/*[[ Name := ZigZag+fractals Author := исходный индикатор ZigZag от MetaQuotes Software Corp. идеи по доработке и использованию от nemo-X небольшое программирование и отладка от eugene5 Link := Notes := Lots := 0.1 Stop Loss := 100 Take Profit := 100 Trailing Stop := 0 ]]*/ Defines: depth(12),deviation(5),backstep(3),pro(20),myear(2005); Variables : shift(0),lasthigh(-1),lastlow(-1),lasthighpos(0),lastlowpos(0),currentvalue(0),lastvalue(0); Variables : val(0),back(0),res(0),cnt(0),j(0); Variables : curlow(0),curhigh(0),currentshift(0),lastshift(0); Array:MassivSetIndexValue[1000](0),MassivSetIndexValue2[1000](0); Defines: slippage(10); var: Trend(0), lastposition(""); if myear<>year then exit; j=j+1;if j=1000 then j=0; //----------------------------------------------Доливка позиции-------------------------------------- if TotalTrades>1 then begin If ((CurTime-LastTradeTime)<11) then exit; for cnt=1 to TotalTrades Begin if OrderValue(cnt,VAL_TYPE)=OP_BUY and OrderValue(cnt,VAL_SYMBOL)=Symbol) and OrderValue(cnt,VAL_LOTS)=1.0 then begin if OrderValue(cnt,VAL_PROFIT)>=500 then begin CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),ask,slippage,red);exit;end; if OrderValue(cnt,VAL_PROFIT)<=-500 then begin CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),ask,slippage,red);exit;end;end; if OrderValue(cnt,VAL_TYPE)=OP_SELL and OrderValue(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_LOTS)=1.0 then begin if OrderValue(cnt,VAL_PROFIT)>=500 then begin CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),bid,slippage,red);exit;end; if OrderValue(cnt,VAL_PROFIT)<=-500 then begin CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),bid,slippage,red);exit;end;end; end;end; if TotalTrades=1 then begin If ((CurTime-LastTradeTime)<11) then exit; for cnt=1 to TotalTrades Begin if OrderValue(cnt,VAL_TYPE)=OP_BUY and OrderValue(cnt,VAL_SYMBOL)=Symbol) and OrderValue(cnt,VAL_LOTS)=lots then begin if OrderValue(cnt,VAL_PROFIT)>=pro then begin SetArrow(Time[0],L-5*point,241,Violet); SetOrder(op_Buy,1.0,Ask,5,Bid-StopLoss*Point,Ask+TakeProfit*Point,Red);SetArrow(Time[0],L-5*point,241,Red);exit;end;end; if OrderValue(cnt,VAL_TYPE)=OP_SELL and OrderValue(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_LOTS)=lots then begin if OrderValue(cnt,VAL_PROFIT)>=pro then begin SetArrow(Time[0],L-5*point,241,Red); SetOrder(op_Sell,1.0,Bid,5,Ask+StopLoss*Point,Bid-TakeProfit*Point,Gold);SetArrow(Time[0],H+5*point,242,Gold);exit;end;end; end;end; //------------------------------------------Данные для журнала отладки---------------------------------------------- print(" jInd=",j," Positions=",TotalTrades," Profit=",round(TotalProfit)); //------------------------------------------------Трейлинг-Стоп--------------------------------------------- If TrailingStop>0 then begin For cnt=1 to TotalTrades begin if OrderValue(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_PROFIT)>0 then begin If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(Point*TrailingStop) then begin If OrderValue(cnt,VAL_STOPLOSS)<(Bid-Point*TrailingStop) then begin ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);end;end; If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(Point*TrailingStop) then begin If OrderValue(cnt,VAL_STOPLOSS)>(Ask+Point*TrailingStop) then begin ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);end;end;end;end;end; //-----------------------------------------Исходный эксперт без изменений------------------------------------------- SetLoopCount(0); lasthigh=-1; lastlow=-1; for shift = Bars-300 downto 0 { //--- low val=Low[Lowest(MODE_LOW,shift+depth-1,depth)]; if val==lastlow then val=0 else { lastlow=val; if (Low[shift]-val)>(deviation*Point) then val=0 else { for back=1 to backstep { res=MassivSetIndexValue[shift+back]; if res!=0 and res>val then MassivSetIndexValue[shift+back]=0; }; }; }; MassivSetIndexValue[shift]=val; //--- high val=High[Highest(MODE_HIGH,shift+depth-1,depth)]; if val==lasthigh then val=0 else { lasthigh=val; if (val-High[shift])>(deviation*Point) then val=0 else { for back=1 to backstep { res=MassivSetIndexValue2[shift+back]; if res!=0 and res0 then { if lasthigh0 then { if lastlow>curlow then MassivSetIndexValue[lastlowpos]=0 else MassivSetIndexValue[shift]=0; }; //--- if curlow0 then if currentvalue=0 then { currentvalue=MassivSetIndexValue[shift]; currentshift=shift; } else if lastvalue=0 then lastvalue=MassivSetIndexValue[shift] else break; }; If FreeMargin<1000 then Exit; // денег нет - выходим trend=currentvalue-lastvalue; if trend<0 then { if iFractals(MODE_LOWER, currentshift)<>0 then comment("Разница зигзаза=",trend, " хочется купить и фрактал даже есть :)", " lastposition=", lastposition) else { comment("Разница зигзаза=",trend, " хочется купить, а фрактала нет :(", " lastposition=", lastposition); exit; } } else if trend>0 then { if iFractals(MODE_UPPER, currentshift)<>0 then comment("Разница зигзаза=",trend, " хочется продать и фрактал даже есть :)", " lastposition=", lastposition) else { comment("Разница зигзаза=",trend, " хочется продать, а фрактала нет :(", " lastposition=", lastposition); exit; } } else comment("Разница зигзаза=",trend, " стоим на месте :(", " lastposition=", lastposition); If CurTime > LastTradeTime + 10 Then //стандартная проверка по времени { if trend<0 then { if TotalTrades=1 and ord(1,VAL_TYPE)=OP_SELL then { Comment("close order"); CloseOrder(ord(1,VAL_TICKET),ord(1,VAL_LOTS),bid,slippage,red); lastposition="sell"; exit; } else if TotalTrades=0 and (lastposition="sell" or lastposition="") then { SetOrder(OP_BUY,lots,ask,Slippage,ask-StopLoss*point,ask+TakeProfit*Point,RED); exit; }; }; if trend>0 then { if TotalTrades=1 and ord(1,VAL_TYPE)=OP_BUY then { Comment("close order"); CloseOrder(ord(1,VAL_TICKET),ord(1,VAL_LOTS),ask,slippage,red); lastposition="buy"; exit; } else if TotalTrades=0 and (lastposition="buy" or lastposition="") then { SetOrder(OP_SELL,lots,bid,Slippage,bid+StopLoss*point,bid-TakeProfit*Point,RED); exit; }; }; };