It’s currentdayofweek not dayofweek.
Or am I off track?
AVTParticipant
Senior
CurrentDayOfWeek is for the current candle, wheras DayOfWeek can be any candle you specify (like finding out whether the 10th candle before was on a Monday=1 or not)
This seems to be the good one (on Eur/Usd, DAILY, on Dax it still opens trades on Sunday, occasionally):
Defparam cumulateorders = false
// Long
IF CurrentDayOfWeek = 4 AND close < open THEN //On Friday we test Thursday's close
Buy 1 contract at market //and a new trade should be opened immediately (on
ENDIF //Friday).
// Short
IF CurrentDayOfWeek = 0 AND close[1] > open[1] THEN //On Monday we need to test the Fridays'closure, since
sellshort 1 contract at market //there is Sunday in the middle.
ENDIF
//GRAPH CurrentDayOfWeek AS "cDoW"
// Stop e target in pips
SET TARGET pPROFIT 75
SET STOP pLOSS 35
The strategy tests Thursday to open a new trade on Friday and Friday (on Sunday BAR) to open a new trade on Monday, if conditions are met.
When testing daily bar, you should use OpenDayOfWeek
Still Nicolas, I need to know some (unknown to me) details: “when are DayOfWeek, CurrentDayOfWeek and OpenDayOfWeek best used?”.
Because, as you can see from the screenshot (EurUsd daily), on Thursday DoW is 5 while the other two are both 4, on Friday all the three retain value 5 and on Monday DoW is 2 while the other two are both 1. It appears that DoW is always one day ahead, but on Friday! What’s the logic behind this?
Hello robertogozzi,
take a look a the attached screenshot for this code:
dow = DayOfWeek
CDow = CurrentDayOfWeek
ODow = OpenDayOfWeek
return dow as "dow", CDow as "CDow", ODow as "ODow"
“CDow” is always referring to the same day which is Friday and not the actual Sunday of the day when I took the screenshots. Trying CDow on a IG Market that actually trades on Sundays did not change the observation.
Dow” is counting from 1 on Sundays to 5 on Thursday and remains 5 on Friday.
ODow is working properly.
I guess this helps to decide which function to use.
The good news is: All three are working fine on the intraday timerframes. The screenshot shows an hourly t-bond futures chart.
Here currentdayofweek switches to the new day faster. The rest of the day currentdayofweek and opendayofweek are identical,
And I have to correct myself:
On intraday timeframes currentdayofweek works just the same as on longer timeframes.
It’s dayofweek that switches to the new day on the first intraday bar. Openday of week waits for the first bar to close, before returning the next day’s value.
Sorry for the confusion.