Here's the code:
Code: Select all
Inputs: nBarClose(2), T1(759), T2(1559), T3(2358), pip(0.001);
vars: Flag(false), size(0), ISL(0), R(100), Trig(0), Intrabarpersist RLevel(0),
intrabarpersist Rstop(0), intrabarpersist MaxRLevel(0), EODRstop(0), iStop(0), NoGap(false), MP(0);
[IntrabarOrderGeneration = True]
MP = Marketposition;
If MP = 0 then begin
RLevel = 0;
MaxRLevel = 0;
iStop = 0;
EODRstop = 0;
RStop = 0;
end;
If BarStatus(1) = 2 and MP <=0 then begin
Flag = IP;
Trig = High + pip;
R = (High - Low) + (pip * 2);
ISL = Low - pip;
end;
If BarStatus(1) <=1 then NoGap = c <= Trig + pip;
if MP <=0 and Flag and NoGap then begin
Buy("IP-L") 100{size} shares next bar at Trig Stop;
end;
If MP = 1 then flag = false;
If MP = 1 then RLevel = (c - Trig)/R;
If MP = 1 then MaxRLevel = Iff(RLevel > MaxRlevel, RLevel, MaxRLevel);
If MP = 1 and MaxRLevel < 1 then iStop = ISL;
If MP = 1 and MaxRLevel >= 1 then iStop = (IntPortion(MaxRLevel) * R) + ISL; //stop to Max R - 1
IF MP = 1 and (Time = T1 or Time = T2 or Time = T3) and MaxRLevel > 1 then EODRstop = (IntPortion(MaxRLevel) * R) + Trig;
If MP = 1 then RStop = Iff(EODRstop > iStop, EODRstop, iStop);//initialize EODRstop to 0 for long entry signals
if MP = 1 then sell("RStop") from entry("IP-L") next bar at RStop Stop;
If MP = 1 and BarsSinceEntry = nBarClose and MaxRLevel < 1 then Sell("LowR") from entry ("IP-L") this bar at Close;
If AtCommentaryBar Then begin
commentary("istop",istop:1:5);
end;