Hi,
On a daily timeframe I would like to start a trade in the direction of the previous day. So if close>open on the previous day then I want to start a long trade. If close<open on the previous day then I want to start a short trade. I think I know how to do this, but now I want to exclude the sunday bar. So, on Monday I want to check the friday bar for the direction.
Can you guys help me out here? Thanks again!
Gr. Pieter
I tried to arrange this code on EurUsd DAILY, but, while it seems running nicely on Monday (short positions) , the same is not true for Friday (long positions) because it opens a trade on Sunday morning while it should open it on Friday!
As far as I know each strategy is executed at each new bar open, so the DayOfWeek for Friday should be 5, while referencing close (or close[0]) should return Thursday’s closing price (the bar just closed):
Defparam cumulateorders = false
// Long
IF DayOfWeek = 5 AND close < open THEN //On Friday we test Thursday's close
Buy 1 contract at market //and a new trade should be opened immediately, not on Sunday!
ENDIF
// Short
IF DayOfWeek = 1 AND close[1] > open[1] THEN //On Monday we need to test the Fridays'closure,since there's
sellshort 1 contract at market //Sunday in the middle.
ENDIF
//GRAPH DayOfWeek AS "DoW"
// Stop e target in pips
SET TARGET pPROFIT 50
SET STOP pLOSS 50
I am eager to know why!
Thanks Roberto, maybe somebody can help us out?
I do hope so, Nicolas (admin) could be of help, but he’s on a temp leave now and he reads posts and threads occasionally.
Thanks Roberto, you are precious member, you desserve your black badge for precious helping member!
I think the code should set as follow:
Defparam cumulateorders = false
// Long
IF DayOfWeek = 4 AND close < open THEN //On Thursday we test Thursday's close
Buy 1 contract at market //a new trade will be opened at Friday open
ENDIF
// Short
IF DayOfWeek = 1 AND close[1] > open[1] THEN //On Monday we need to test the Fridays'closure,since there's
sellshort 1 contract at market //Sunday in the middle.
ENDIF
//GRAPH DayOfWeek AS "DoW"
// Stop e target in pips
SET TARGET pPROFIT 50
SET STOP pLOSS 50
If you want to test the Thursday bar Close, test it when it is Thursday, because the code is read at Close, you’ll get the right values at that time. So logically, the order will be opened at the beginning of the next bar, on Friday morning. Hope I have understood correctly your question.
Sorry Nicolas, but the first part (LONG trades) seems not to work properly, as from the two pics attached.
You cn see:
- a SHORT trade is correctly opened on Monday, but GRAPH display the value 2 as DayOfWeek instead of 1
- a LONG trade is incorrectly opened on Thursday and GRAPH displays the value 5 as DayOfWeek, while it should be 4
Where’s the bug?
So, what does it graph using your initial code?
Hi Derek, sorry for my late answer, but I was on leave.
My initial code displayed Monday as DoW (DayOfWeek) 2, see pic 1. It also started trades on Sunday for which it displayed DoW 1.
Hope you had nice holidays, Roberto.
Ok, Sunday =1, Monday = 2 etc… at least that’s what I see.
Go long on day 6 and short on day 2.
Did you try it?
The company I work at produces quite a few manuals with errors.
Scratch my last comment.
It’s the IF statement with the AND in a single line.
All your sample links are like
If dayofweek=1 then
do stuff
Endif
Your code includes another condition so that the if statement can only be true one bar later.
How would you write “BUY on Tuesday if the daily bar on Monday is bullish”?
How about
If currentdayofweek = 2 and close>open then
Buy at market
Endif
I know Derek, but as you can see from the picture, GRAPH reports DayOfWeek 2 when my cursor is on the MONDAY bar (it was on Aug. 7th, 2017)!