how to close at the end of day on a daily candle
Forums › ProRealTime English forum › ProOrder support › how to close at the end of day on a daily candle
- This topic has 6 replies, 3 voices, and was last updated 8 years ago by Nicolas.
-
-
08/31/2016 at 9:15 AM #12513
I would like to figure out how to code entering a trade at the open and exiting at the close on a daily candle.
here is my attempt at the code which opens and closes simultaneously, rather than the end of day (:
any suggestions greatly appreciated
123456789101112131415161718192021222324252627282930313233343536// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedPosition = 10starttime = 090000finishtime = 230000ema = ExponentialAverage[10](close)// Conditions to enter long positionsc1 = (ema > ema[1])c2 = (currenttime = starttime)IF c1 and c2 THENBUY position CONTRACT AT MARKETENDIF// Conditions to exit long positionsc3 = (currenttime = finishtime)IF c3 thensell position contract at marketendif// Conditions to enter short positionsc4 = (ema < ema[1])c5 = (currenttime = starttime)IF c4 and c5 THENSELLSHORT position CONTRACT AT MARKETENDIF// Conditions to exit short positionsc6 = (currenttime = finishtime)if c6 thenexitshort position contract at marketendif// Stops and targetsSET STOP loss 1*(averagetruerange[14](close))08/31/2016 at 11:08 AM #12519Hi Chris,
What instrument are you referring to, and what time zone are is your platform set to ?
Your code refers to “currenttime” – should this be just “time” ?
In any case – This sample code should point you in the right direction, using XJO as it appears your a fellow Aussie 😉
Use c2 for entries and c3 for exits
12345DayOpenTime = 100100 //1min after market openDayCloseTime = 155900 //1min before market closec2 = time <= DayOpenTimec3 = time >= DayCloseTime08/31/2016 at 12:06 PM #12522many thanks Grizzly
I have set the time zone as Sydney GMT+10 (screenshot attached)
I am looking to test on Australia 200 & AUD/USD on daily candles timeframes, which would include after hours trading to pick up any moves during the europe & US sessions. I’ll adjust the times to 000100 to enter and 115900 to exit – I’ll do some testing & see how it goes.
cheers
Chris
09/01/2016 at 8:03 AM #12535When I applied the code to Sydney GMT+10 there were no entries & when I changed that to GMT+1 the entry conditions seemed to work, though not the exit based on time – see attached screenshot. Could it be something around when the time condition is met, it is applied to the next bar and leaves the position open??
Any suggestions?
12345678910111213141516171819202122232425262728293031323334353637// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedDayOpenTime = 000100 //1min after market openDayCloseTime = 235900 //1min before market closePosition = 1ema = ExponentialAverage[10](close)// Conditions to enter long positionsc1 = (ema > ema[1])c2 = time <= DayOpenTimeIF c1 and c2 THENBUY position CONTRACT AT MARKETENDIF// Conditions to exit long positionsc3 = time >= DayCloseTimeIF c3 thensell position contract at marketendif// Conditions to enter short positionsc4 = (ema < ema[1])c5 = time <= DayOpenTimeIF c4 and c5 THENSELLSHORT position CONTRACT AT MARKETENDIF// Conditions to exit short positionsc6 = time >= DayCloseTimeif c6 thenexitshort position contract at marketendif// Stops and targetsSET STOP loss 1*(averagetruerange[14](close))09/01/2016 at 8:56 AM #12540When you are changing timezome in the configuration window, you need to save the platform and restart it, otherwise it will not has any effect on the current session.
About the exit at end of day, maybe you can try to add this line at the beginning of the code and see what happens:
1defparam flatafter = 23590009/01/2016 at 9:58 AM #1254409/01/2016 at 1:09 PM #12548 -
AuthorPosts
Find exclusive trading pro-tools on