Help with setting limit order to be previous days closing candle
Forums › ProRealTime English forum › ProOrder support › Help with setting limit order to be previous days closing candle
- This topic has 3 replies, 2 voices, and was last updated 5 years ago by
robertogozzi.
-
-
06/03/2020 at 10:00 AM #134348
Hello ProRealCode community!
I’m still a bit new to coding and I need a bit of help with something. I have a mean reversion script here that essentially sells/buys the open if we’ve deviated a bit too much from the previous days 9pm candle open.
Going through the backtest results I’ve noticed that my target limit order was set at the wrong price level- instead of the target being yesterdays 9pm opening candle, it was todays 7am opening candle.
What I think might’ve happened is the “open” variables got a bit mixed up – I just don’t know how to fix this.
Any help you can give me with my code will be greatly appreciated. I’ve attached a screenshot with a little example of what went wrong.
1234567891011121314151617181920212223242526272829303132333435363738394041424344defparam cumulateorders=false// ---amount = 3 //amount of lots/shares/contratcs for each orderstoploss = 30 //stoploss in pointspreviousDayTime = 210000 //open of the previous session's UK 21:00 candlecurrentDayTime = 070000 //open of the UK 07:00 candle// ---if time=previousDayTime thenprev = openendiftcondition = time=currentDayTimec1 = prev-openif c1 > 0 thenc2=c1*1endifif c1 < 0 thenc2=c1*-1endifif tcondition and not onmarket and open<prev and c2=>stoploss thenbuy amount contract at marketset target pprofit prevset stop ploss stoplossendifif tcondition and not onmarket and open>prev and c2=>stoploss thensellshort amount contract at marketset target pprofit prevset stop ploss stoplossendifif LongOnMarket And time>210000 thensell at marketendifif ShortonMarket And time>210000 thenbuy at marketendifThanks,
Aleks
06/03/2020 at 10:46 AM #134362Between lines 10 and 11 insert a new one (wich will become the new line 11):
1PreviousPrev = Prevwhenevr you need to use today’s PREV, use PREV, whenever you need to use yesterday’s PREV use PREVIOUSPREV, instead.
06/03/2020 at 12:45 PM #134386Hi Roberto,
Thanks for taking the time to look into this issue. However, the issue persists. Here’s my code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445defparam cumulateorders=false// ---amount = 3 //amount of lots/shares/contratcs for each orderstoploss = 30 //stoploss in pointspreviousDayTime = 210000 //open of the previous session's UK 21:00 candlecurrentDayTime = 070000 //open of the UK 07:00 candle// ---if time=previousDayTime thenPreviousPrev = PrevPrev = openendiftcondition = time=currentDayTimec1 = PreviousPrev-openif c1 > 0 thenc2=c1*1endifif c1 < 0 thenc2=c1*-1endifif tcondition and not onmarket and PreviousPrev<Prev and c2=>stoploss thenbuy amount contract at marketset target pprofit PreviousPrevset stop ploss stoplossendifif tcondition and not onmarket and PreviousPrev>Prev and c2=>stoploss thensellshort amount contract at marketset target pprofit PreviousPrevset stop ploss stoplossendifif LongOnMarket And time>210000 thensell at marketendifif ShortonMarket And time>210000 thenbuy at marketendifCould you advise if I implemented the right changes?
Thanks,
Aleks
06/03/2020 at 11:22 PM #134493Since at line 10 you are using TIME, open will return the OPENing price od the candle that closes at 210000. If you need the opening price of the candle starting at 210000 then you’ll have to use OPENTIME, instead.
In line 5 you should use
130 * pipsize(despite Dax makes no difference), but it’s good programming practice when you need to convert pips into price.
Lines 29 and 35 should read:
1set target profit abs(PreviousPrev - close) //difference in price to use PROFITor
1set target pprofit abs(PreviousPrev - close) / pipsize //difference in pips to use pPROFIT1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on