GabyParticipant
Average
Hello,
in order to avoid to open any position on Sunday I have coded the following (Sunday = 0):
DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
TimeCond = OpenTime <= 204500 AND OpenTime >= 014500
IF TimeCond and DayCond THEN
However the algo managed to open a position on Sunday. DO you know why the DayCond was disregarded by Prorealcode?
Many thanks for your help, Gaby
Maybe you are placing a pending order on the very last candle on Friday, so it will be executed when the next bar opens, which might be on Sunday.
This code works correctly:
DEFPARAM CumulateOrders = true
sell at market
DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
TimeCond = OpenTime <= 204500 AND OpenTime >= 014500
IF DayCond AND TimeCond THEN
buy at market
ENDIF
graph DayCond
GabyParticipant
Average
Thanks Roberto, you spot on!
It was a daily signal started on Fri @ 00.00.00 and given at the closure of the bar (on Friday day’s close). And the program correctly took the trade as soon as possible (Sunday @ 21.00 GMT).
Actually, I made a mistake on my first message, as in my first post analysis I did not see it was a daily signal. The daily program includes only the check on the DayCond (and not the TimeCond).
I have now modified my code as follow – and it works (it now prevent trading on Sunday evening at the opening to execute signals generated on Friday’s close):
// Avoid to open new trades on Sunday at 21.00.00 (for signals generated on Friday’s close), to avoid wide spreads on Sunday night
// Avoid to open new trades on Monday at 00.00.00 (for signals generated on Sunday’s close), to avoid to consider Sunday as a relevant day to generate the signal.
DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
Sunday = DayOfWeek[0]
IF DayCond AND NOT Sunday THEN
Thank you for your support. Gaby
GabyParticipant
Average
========= ERRATA CORRIGE ========
This is the code that works (preventing trades to be opened on Sunday):
// Avoid to open new trades on Sunday at 21.00.00 (for signals generated on Friday’s close), to avoid wide spreads on Sunday night
// Avoid to open new trades on Monday at 00.00.00 (for signals generated on Sunday’s close), to avoid to consider Sunday as a relevant day to generate the signal.
DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
NoSunday = currentdayofweek=1 or currentdayofweek=2 or currentdayofweek=3 or currentdayofweek=4 or currentdayofweek=5
IF DayCond and NoSunday THEN