/*--------------------------------------------------------------------
скрипт определяет цену, куда мы его бросили и от нее строит сеть отложенных ордеров
если ниже цены, то SellStop, если выше, то BuyStop
//--------------------------------------------------------------------*/
extern int Step = 40; //расстояние (в пунктах) между ордерами
extern int Orders = 5; //кол-во ордеров сетки
extern int Magic = 0; //уникальный номер ордера
extern double Lot = 0.1; //объем первого Stop ордера
extern double K_Lot = 0.5; //умножение лота Stop ордеров
extern double PlusLot = 0; //прибавлять это значение к лоту последующих ордеров
extern int DigitsLot = 2; //округление значения лота
extern int stoploss = 0; //уровень выставления SL, если 0, то SL не выставляется
extern int takeprofit = 0; //уровень выставления TP, если 0, то TP не выставляется
extern int Expiration = 0; //Срок истечения отложенного ордера в минутах, если 0, то срок не ограничен (1440 - сутки)
extern int attempts = 20; //кол-во попыток открытия ордера
//--------------------------------------------------------------------
string txt;
int n,slippage=3,STOPLEVEL;
datetime expiration;
//--------------------------------------------------------------------
int start()
{
if (Expiration>0) expiration=TimeCurrent()+Expiration*60; else expiration=0;
Comment("Запуск скрипта cm_EA_GreadStopOrders ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS),"\nCopyright © 2011
[email protected]");
STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
if (Digits==3 || Digits==5) slippage=30;
double Price;
double LOT=Lot;
Price = NormalizeDouble(WindowPriceOnDropped(),Digits);
for (int i=1; i<=Orders; i++)
{
if (Price>Ask)
{
OPENORDER (OP_BUYSTOP,Price,LOT,i);
Price = NormalizeDouble(Price+Step*Point,Digits);
}
if (Price<Bid)
{
OPENORDER (OP_SELLSTOP,Price,LOT,i);
Price = NormalizeDouble(Price-Step*Point,Digits);
}
LOT=NormalizeDouble(LOT*K_Lot+PlusLot,DigitsLot);
}
Comment("Скрипт закончил свою работу, выставлено ",n," ордеров ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS),"\nCopyright © 2011
[email protected]");
return(0);
}
//--------------------------------------------------------------------
void OPENORDER(int ord,double Price,double L,int i)
{
int error,err;
double SL,TP;
while (true)
{ error=0;
if (ord==OP_BUYSTOP)
{
if (takeprofit!=0) TP = NormalizeDouble(Price + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Price - stoploss*Point,Digits); else SL=0;
error=OrderSend(Symbol(),ord, L,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Blue);
}
if (ord==OP_SELLSTOP)
{
if (takeprofit!=0) TP = NormalizeDouble(Price - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Price + stoploss*Point,Digits); else SL=0;
error=OrderSend(Symbol(),ord,L,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Red);
}
if (ord==OP_SELLLIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(Price - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Price + stoploss*Point,Digits); else SL=0;
error=OrderSend(Symbol(),ord, L,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Blue);
}
if (ord==OP_BUYLIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(Price + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Price - stoploss*Point,Digits); else SL=0;
error=OrderSend(Symbol(),ord,L,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Red);
}
if (error==-1)
{
txt=StringConcatenate(txt,"\nError ",GetLastError());
if (ord==OP_BUYSTOP) txt = StringConcatenate(txt," OPENORDER BUYSTOP ", i," Ask =",DoubleToStr(Ask,Digits)," Lot =",DoubleToStr(L,DigitsLot)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Price-Ask)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((Price-SL)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((TP-Price)/Point,0),") STOPLEVEL=",STOPLEVEL);
if (ord==OP_SELLSTOP) txt = StringConcatenate(txt," OPENORDER SELLSTOP ", i," Bid =",DoubleToStr(Bid,Digits)," Lot =",DoubleToStr(L,DigitsLot)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Bid-Price)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((SL-Price)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((Price-TP)/Point,0),") STOPLEVEL=",STOPLEVEL);
if (ord==OP_SELLLIMIT) txt = StringConcatenate(txt," OPENORDER SELLLIMIT ",i," Ask =",DoubleToStr(Ask,Digits)," Lot =",DoubleToStr(L,DigitsLot)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Price-Ask)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((Price-SL)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((TP-Price)/Point,0),") STOPLEVEL=",STOPLEVEL);
if (ord==OP_BUYLIMIT) txt = StringConcatenate(txt," OPENORDER BUYLIMIT ", i," Bid =",DoubleToStr(Bid,Digits)," Lot =",DoubleToStr(L,DigitsLot)," Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Bid-Price)/Point,0),") SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((SL-Price)/Point,0),") TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((Price-TP)/Point,0),") STOPLEVEL=",STOPLEVEL);
Print(txt);
Comment(txt," ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
err++;Sleep(1000);RefreshRates();
}
else
{
Comment("Ордер ",error," успешно выставлен ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
n++;
return;
}
if (err>attempts) return;
}
return;
}
//--------------------------------------------------------------------