Just set a flag when the condition is met and then only open the trade when the time = your desired time and the flag is set. Reset the flag to zero when the trade is opened.
Hi Vonasi
Thanks a lot for your guidance. It is working. I have another issue now.
- I have selected custom trading hours as 143000 to 210000.
- Condition satisfied at 210000, sets the flag=1. When flag =1 and time = 1430000, I am not getting any trade at 1430000. For that I have to select custom trading hours as 140000 to 210000. But I do not want to select that trading hours since other calculations of strategy (moving averaage, RSI) etc consider Intraday bar of 140000 to 143000 for calculation.which I do not want to consider for calculation and still I want trade to open at 143000 only.
So please advice solutions for this issue.
Thanks.
Hi Vonasi/Nicolas
Could you please guide me on my above query.
Thanks.
Please add the new complete code with the “flag” you have coded.
Hi Nicolas
Thanks for your reply. I did not understand your reply. Appreciate if you could clarify in detail or add corrections to my earlier post dated 10/04/2018 at 6:44 PM to make me easy to understand.
Thanks.
Nicolas is requesting that you post your modified code as it is far easier to find a coding problem with the code rather than just a description of what you expect it to do!
Use the ‘Insert PRT Code’ button and cut and paste your code into the box and I’m sure someone will quickly spot why your strategy is not behaving as you expect it to.
Hi Vonasi/Nicolas
Thanks for the clarifications. Please review below code and guide me.
The trade open at 143000 only when custom trading hours are 140000 to 210000. I want trade to open at 143000 when custom trading hours are 143000 to 210000 based on condition satisfied a day before at 210000.
Thanks.
// Conditions to enter long positions
DEFPARAM CUMULATEORDERS = FALSE
starthour = 150000
endhour = 210000
if time = starthour then
hh4 = hh3
hh3 = hh2
hh2 = hh1
hh1 = hh
hh = close
ll4 = ll3
ll3 = ll2
ll2 = ll1
ll1 = ll
ll = close*1000
endif
if time >= starthour and time <= endhour then
hh = max (hh, high)
ll = min (ll, low)
endif
starthour2 = 170000
endhour2 = 210000
if time = starthour2 then
ahh5 = ahh4
ahh4 = ahh3
ahh3 = ahh2
ahh2 = ahh1
ahh1 = ahh
ahh = close
all5 = all4
all4 = all3
all3 = all2
all2 = all1
all1 = all
all = close*1000
endif
if time >= starthour2 and time <= endhour2 then
ahh = max (ahh, high)
all = min (all, low)
endif
REM Computes the highest and lowest prices on p bars
hi1 = Max(hh,Max(hh1,Max(hh2,Max(hh3,Max(hh4,ahh5)))))
lo1 = Min(ll,Min(ll1,Min(ll2,Min(ll3,Min(ll4,all5)))))
oscillator1 = ((close - lo1) / (hi1 - lo1)) * 100
r=5
r1=2
lineK = average[r](oscillator1)
lineD = average[r1](lineK)
e1 = LineK > LineD AND time = 210000
if e1 then
flag1 = 1
endif
If flag1 and time = 143000 then
Buy 5 Contracts at market
endif
SET STOP %LOSS 0.32
If Longonmarket and (BarIndex - TradeIndex) >= 10 then
Sell at market
endif
if time = 160000 then
flag1 = 0
endif
Hi Nicolas/Vonasi
Could you please review my request and guide me.
Thanks
The trade open at 143000 only when custom trading hours are 140000 to 210000. I want trade to open at 143000 when custom trading hours are 143000 to 210000 based on condition satisfied a day before at 210000.
I’m not sure I understand what the problem is exactly from your description. I would suggest using GRAPH to show TIME so that you can see what the TIME of the candle when you want a trade to open actually is. I often prefer OPENTIME when writing a code as my brain seems to understand this better!
Hi Vonasi
Please refer to below simple code to know the issue. This code is executed on Proreal time demo platform but nt on real Proreal time platform. All settings are same on both plaatforms.
Could you please advice on solution to be able to execute simililar code in Real time Proreal time platform.
Thanks
if time = 210000 then
flag = 1
endif
IF NOT LongOnMarket AND flag and time = 143000 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
If LongOnMarket AND time = 203000 THEN
SELL AT MARKET
ENDIF
if time = 203000 then
flag = 0
endif
I can’t explain to you why it works on demo but not on real. I am not willing to test that strategy on my own real account as it could be very expensive! It works fine on my demo account.
I would suggest sending a technical help request from your live account with a link to this topic within your description.
Hi Vonasi
Thanks for your reply. I back tested above strategy both in Demo & real plat forms. It work in demo but not in real. It was not real auto trading testing. I back tested it to see the result.
Can you back test real plat form. I am sure you will get some clue/solution.
Meanwhile I will online check with technical team as you advised.
Thanks.
GraHal he doesn’t check the two time values together, he just SETS a flag at that time, which will not be cleared till 203000 the next day, so at 143000 the next day FLAG will still be set.
He wants to stay off trading just 30 minutes, from 203000 to 210000.
Ah gotcha Roberto, thank you!
I looked for guidance on using Flags (after posting my query above) but it looks straightforward?
I was mixing Flags up with … when a condition is true and would, for example, show as = 1 using GRAPH under an equity curve?
Or do I still need to find / read up on Flags!? 🙂