Forums › ProRealTime English forum › ProOrder support › How to create a breakout box between 2 hours, Code please? › Reply To: How to create a breakout box between 2 hours, Code please?
07/23/2018 at 11:34 AM
#76502
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
defparam flatafter = 210000 daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 if longonmarket then alreadybuy=1 endif if shortonmarket then alreadysell=1 endif if intradaybarindex=0 then alreadybuy=0 alreadysell=0 endif if time = 061000 then yh = highest[86](high) yL=lowest[86](low) os = 2*pipsize endif tcondition = time>080000 and time<200000 if tcondition then if close<yh+os and not alreadybuy then buy 1 contract at yh+os PositionSize 3 stop endif if close>yl+os and not alreadysell then sellshort 1 contract at yl-os PositionSize 3 stop endif endif set stop ploss 30 ONCE TrailStart = 30 //30 Start trailing profits from this point ONCE ProfitPerCent = 0.666 //66.6% Profit to keep IF Not OnMarket THEN y1 = 0 y2 = 0 ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG x1 = (close – tradeprice) / pipsize //convert price to pips IF x1 >= TrailStart THEN //go ahead only if 30+ pips y1 = max(x1 * ProfitPerCent, y1) //y = % of max profit ENDIF IF y1 THEN //Place pending STOP order when y>0 SELL AT Tradeprice + (y1 * pipsize) STOP //convert pips to price ENDIF ELSIF ShortOnMarket AND close < (TradePrice – (y2 * pipsize)) THEN //SHORT x2 = (tradeprice – close) / pipsize //convert price to pips IF x2 >= TrailStart THEN //go ahead only if 30+ pips y2 = max(x2 * ProfitPerCent, y2) //y = % of max profit ENDIF IF y2 THEN //Place pending STOP order when y>0 EXITSHORT AT Tradeprice – (y2 * pipsize) STOP //convert pips to price ENDIF ENDIF |
Lastly, I have a slight issue with the breakout box settings, if the time condition is 8-8, as below:
tcondition = time>080000 and time<200000.
Eg: Sell example: If the price has moved out of the breakout box at say 7:30, it seems to buy at 8 regardless, I would like the sell trade to be cancelled if the box has been broken before 8. The buy remains active, but the same conditions as the above.
Hopefully this makes sense.