/*[[ Name := Торговля на прорыве Author := Driver Notes:= refactored by Nick Bilak Lots := 1.00 Stop Loss := 300 Take Profit := 25 Trailing Stop := 0 ]]*/ Defines: Test(0),TestYear(2004),TestMonth(1); Defines: risk(0),HL(85),N(9),Zapas(10); // risk -(20)-было,процент используемого капитала. Если = 0 то не используется // HL - разница между экстремальными ценами, // N - период // Zapas - запас в выставлении отложенного ордера var: initialize(1),iTmp(0),s(0),b(0),ho(0),lo(0),i(0),fl(0),lotsi(0),isBuy(false),isSell(false),orders(0),ttime(0); if year*100+month < TestYear*100+TestMonth then exit; if !IsTradeAllowed then exit; //Торговать советнику запрещено - выходим If FreeMargin < 1000 Then Exit; if ((CurTime-ttime)<10) then Exit; // 10 сек таймаут между операциями if risk=0 then lotsi=lots else lotsi=Ceil(Balance*risk/10000)/10; orders=0; For i=1 to TotalTrades { If Ord(i,Val_Symbol)=Symbol then { orders++; }; }; //Обнуляем кол-во ожидающих приказов b=0; s=0; if orders<>0 then for i=1 to TotalTrades { if ord(i,VAL_SYMBOL)=Symbol and OrderValue(i,VAL_TYPE)=OP_BUYSTOP then isBuy=true; //Считаем кол-во приказов на покупку if ord(i,VAL_SYMBOL)=Symbol and OrderValue(i,VAL_TYPE)=OP_SELLSTOP then isSell=true; // Считаем кол-во приказов на продажу if ord(i,VAL_SYMBOL)=Symbol and OrderValue(i,VAL_TYPE)=OP_BUY then b++; //Считаем кол-во приказов на покупку if ord(i,VAL_SYMBOL)=Symbol and OrderValue(i,VAL_TYPE)=OP_SELL then s++; // Считаем кол-во приказов на продажу }; // Если выставлен приказ на покупку, то тут же выставлять приказ на продажу if fl=1 then { fl=0; if isBuy then { isSell=true; ttime=CurTime; SetOrder(OP_SELLSTOP,lotsi,lo-Zapas*Point,3,lo-Zapas*Point+StopLoss*Point,lo-Zapas*Point-TakeProfit*Point,red); exit; }; if isSell then { isBuy=true; ttime=CurTime; SetOrder(OP_BUYSTOP,lotsi,ho+Zapas*Point,3,ho+Zapas*Point-StopLoss*Point,ho+Zapas*Point+TakeProfit*Point,blue); exit; }; }; // Если остался один ожидающий приказ на покупку/продажу - удаляем его. if orders<>0 and (b+s)=1 and (isBuy or isSell)then for i=1 to TotalTrades { if (OrderValue(i,VAL_TYPE)=OP_SELLSTOP) or (OrderValue(i,VAL_TYPE)=OP_BUYSTOP) then { isBuy=false; isSell=false; ttime=CurTime; DeleteOrder (OrderValue(i,VAL_TICKET),blue); exit; }; }; // Если нет ни готовых, ни ожидающих приказов, то находим минимум и максимум за последние n баров if orders=0 and (b+s)=0 and !isBuy and !isSell then { ho=h[0]; lo=l[0]; for i=n DownTo 0 { if h[i]>ho then ho=h[i]; if l[i]