/*[[ Name := High_Low v2 (ZigZag) 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(300),Length(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); 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]); 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("Total profit in points=", summ/Point, " for the last ", barn, " bars, starting from ", TimeToStr(Time[300]), "\n", "min/max for the bars ¹1-7=",LL,"/",HH, " swing/swing_n=", 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) { summ=summ+Close[Uzel[i+1,3]]-Close[Uzel[i,3]]; FileWrite(file_handle," buy at", TimeToStr(Time[Uzel[i,3]]), "on the price of", Close[Uzel[i,3]]); FileWrite(file_handle,"close at", TimeToStr(Time[Uzel[i+1,3]]), "on the price of", Close[Uzel[i+1,3]]); FileWrite(file_handle,"profit on this position=", (Close[Uzel[i+1,3]]-Close[Uzel[i,3]])/Point, "Totally in points=", summ/Point); }; if Uzel[i+1,2]-Uzel[i,2]<0 then //seems necessary to buy now (write in log using previous sell) { summ=summ-(Close[Uzel[i+1,3]]-Close[Uzel[i,3]]); FileWrite(file_handle," sell at", TimeToStr(Time[Uzel[i,3]]), "on the price of", Close[Uzel[i,3]]); FileWrite(file_handle,"close at", TimeToStr(Time[Uzel[i+1,3]]), "on the price o", Close[Uzel[i+1,3]]); 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);