Ignore sunday bar
Forums › ProRealTime English forum › ProOrder support › Ignore sunday bar
- This topic has 22 replies, 5 voices, and was last updated 7 years ago by
Derek.
-
-
08/09/2017 at 8:59 PM #42833
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
08/10/2017 at 9:47 AM #42854I 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):
12345678910111213Defparam cumulateorders = false// LongIF DayOfWeek = 5 AND close < open THEN //On Friday we test Thursday's closeBuy 1 contract at market //and a new trade should be opened immediately, not on Sunday!ENDIF// ShortIF DayOfWeek = 1 AND close[1] > open[1] THEN //On Monday we need to test the Fridays'closure,since there'ssellshort 1 contract at market //Sunday in the middle.ENDIF//GRAPH DayOfWeek AS "DoW"// Stop e target in pipsSET TARGET pPROFIT 50SET STOP pLOSS 50I am eager to know why!
08/10/2017 at 11:03 AM #4286608/10/2017 at 11:12 AM #42868I do hope so, Nicolas (admin) could be of help, but he’s on a temp leave now and he reads posts and threads occasionally.
08/10/2017 at 1:12 PM #42913Thanks Roberto, you are precious member, you desserve your black badge for precious helping member!
I think the code should set as follow:
12345678910111213Defparam cumulateorders = false// LongIF DayOfWeek = 4 AND close < open THEN //On Thursday we test Thursday's closeBuy 1 contract at market //a new trade will be opened at Friday openENDIF// ShortIF DayOfWeek = 1 AND close[1] > open[1] THEN //On Monday we need to test the Fridays'closure,since there'ssellshort 1 contract at market //Sunday in the middle.ENDIF//GRAPH DayOfWeek AS "DoW"// Stop e target in pipsSET TARGET pPROFIT 50SET STOP pLOSS 50If 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.
08/10/2017 at 6:58 PM #42955Sorry 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?
08/10/2017 at 8:55 PM #4296808/14/2017 at 3:14 PM #43157Hi 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.
08/14/2017 at 8:28 PM #4317408/14/2017 at 9:42 PM #43176No Derek, it is documented that days are 1 (monday) thru 5 (friday), as you can see:
https://www.prorealcode.com/reply/7246/
https://www.prorealcode.com/reply/42819/
https://www.prorealcode.com/topic/dayofweek-trading-from-tuesday-to-friday/
That’s why I do not understand that behaviour!
08/14/2017 at 11:18 PM #4317908/14/2017 at 11:25 PM #43180Scratch my last comment.
It’s the IF statement with the AND in a single line.
All your sample links are like
123If dayofweek=1 thendo stuffEndifYour code includes another condition so that the if statement can only be true one bar later.
08/14/2017 at 11:36 PM #43181How would you write “BUY on Tuesday if the daily bar on Monday is bullish”?
08/15/2017 at 5:18 PM #4321608/15/2017 at 7:43 PM #43221I 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)!
-
AuthorPosts
Find exclusive trading pro-tools on