/*[[ Name := RealZigZagBreakOut Author := Istoniz Link := http://www.kg/ Separate Window := No First Color := Blue First Draw Type := Line First Symbol := 217 Use Second Data := Yes Second Color := White Second Draw Type := Line Second Symbol := 218 ]]*/ Inputs : barn(250),LengthInput(6),delaymin(60); Variable : shift(0),LL(0),HH(0),Swing(0),Swing_n(0),BH(0),BL(0),i(0),zu(0),zd(0),NH(0),NL(0),uzl(0), summ(0), current(0); Variable : lasttime(0), file_handle(0); Variable:Length(6),bs(0),ss(0),buyprice(0),sellprice(0); Define: nSymbolHi(242), nSymbolLow(241); Array: Uzel[10000,3](0); SetLoopCount(0); // loop from first bar to current bar (with shift=0) Swing_n=0;Swing=0;uzl=0; BH =High[barn];BL=Low[barn];zu=barn;zd=barn; For shift= barn downto 0 Begin LL=10000000;HH=-100000000; for i=shift+Length downto shift+1 Begin if Low[i]< LL then {LL=Low[i];}; if High[i]>HH then {HH=High[i];}; end; if Low[shift]HH then { Swing=2; if Swing_n=1 then {zu=shift+1;}; if Swing_n=-1 then {zd=shift+1;}; } else { if Low[shift]HH then {Swing=1;}; }; if Swing <> Swing_n and Swing_n<>0 then { if Swing=2 then {swing=-Swing_n;BH = High[shift];BL = Low[shift]; }; uzl=uzl+1; if swing = 1 then {Uzel[uzl,1]=zd;Uzel[uzl,2]=BL;Uzel[uzl,3]=shift;}; if swing =- 1 then {Uzel[uzl,1]=zu;Uzel[uzl,2]=BH;Uzel[uzl,3]=shift;}; BH = High[shift];BL = Low[shift]; }; if swing = 1 then { if High[shift] >= BH then {BH=High[shift];zu=shift;};}; if swing = -1 then { if Low[shift]<=BL then {BL=Low[shift]; zd=shift;};}; Swing_n=Swing; end; for i =1 to uzl Begin SetIndexValue(Uzel[i,1],Uzel[i,2]); SetIndexValue2(Uzel[i,3],Uzel[i,2]); if Uzel[i,2]-Uzel[i-1,2]<0 then SetArrow(Time[Uzel[i,3]], min(Uzel[i,2], Low[Uzel[i,3]])-10*Point,nSymbolLow, limegreen); if Uzel[i,2]-Uzel[i-1,2]>0 then SetArrow(Time[Uzel[i,3]], max(Uzel[i,2], High[Uzel[i,3]])+20*Point, nSymbolHi, Red); end ; // eugene5 added something here summ=0; for i = 1 to uzl-1 Begin if Uzel[i+1,2]-Uzel[i,2]>0 then //it means that we must sell now (calculating profit using the previous buy summ=summ+Close[Uzel[i+1,3]]-Close[Uzel[i,3]]; if Uzel[i+1,2]-Uzel[i,2]<0 then //it means that we must buy now (calculating profit using the previous sell) summ=summ-(Close[Uzel[i+1,3]]-Close[Uzel[i,3]]); end; Comment(TimeToStr(Time[0]), "\n"," Swing UP/Swing DWN=", swing, "/", swing_n, "\n","BL/BH=",BL,"/",BH); //if more than delaymin-mimutes - exit //If CurTime < lasttime + delaymin*60 Then exit; //lasttime = CurTime; //FileDelete("report"+Symbol); //file_handle = FileOpen("report"+Symbol," "); summ=0; for i = 1 to uzl-1 Begin if Uzel[i+1,2]-Uzel[i,2]>0 then //seems necessary to sell now (write in log using previous buy) { ss=(h[Uzel[i+1,3]]-l[Uzel[i,3]])/point; sellprice=l[Uzel[i+1,3]]-ss*point; summ=summ+o[Uzel[i+1,3]]-o[Uzel[i,3]]; // comment("Buy at ", TimeToStr(Time[Uzel[i,3]]), "on the price of ", o[Uzel[i,3]],"Close at ", TimeToStr(Time[Uzel[i+1,3]]), "on the price of ", o[Uzel[i+1,3]],"\nProfit on this position= ", (o[Uzel[i+1,3]]-o[Uzel[i,3]])/Point," pips"); // comment("Close at ", TimeToStr(Time[Uzel[i+1,3]]), "on the price of ", Close[Uzel[i+1,3]]); comment("Place SELLSTOP @ ", sellprice ,"\n",TimeToStr(Time[Uzel[i+1,3]])); MoveObject("sellprice",OBJ_HLINE,time,sellprice,time,sellprice,RED,1,STYLE_SOLID); SetObjectText("sellprice_txt","SELL Here ","Arial",7,White); MoveObject("sellprice_txt",OBJ_TEXT,time,sellprice,time,sellprice,White); }; if Uzel[i+1,2]-Uzel[i,2]<0 then //seems necessary to buy now (write in log using previous sell) { bs=-(l[Uzel[i+1,3]]-h[Uzel[i,3]])/point; buyprice=h[Uzel[i+1,3]]+bs*point; summ=summ-(o[Uzel[i+1,3]]-o[Uzel[i,3]]); // comment("Sell at ", TimeToStr(Time[Uzel[i,3]]), "on the price of ", o[Uzel[i,3]],"Close at ", TimeToStr(Time[Uzel[i+1,3]]), "on the price of ", o[Uzel[i+1,3]],"\nProfit on this position= ", -(o[Uzel[i+1,3]]-o[Uzel[i,3]])/Point," pips"); // comment("Close at ", TimeToStr(Time[Uzel[i+1,3]]), "on the price of ", Close[Uzel[i+1,3]]); comment("Place BUYSTOP @ ", buyprice ,"\n",TimeToStr(Time[Uzel[i+1,3]])); MoveObject("buyprice",OBJ_HLINE,time,buyprice,time,buyprice,limegreen,1,STYLE_SOLID); SetObjectText("buyprice_txt","BUY Here ","Arial",7,White); MoveObject("buyprice_txt",OBJ_TEXT,time,buyprice,time,buyprice,White); //FileWrite(file_handle,"profit on this position=", -(Close[Uzel[i+1,3]]-Close[Uzel[i,3]])/Point, "Totally in points=", summ/Point); }; end; //FileClose(file_handle); //print(TimeToStr(Time[Uzel[i,3]]),l[Uzel[i,3]]);