Ignore sunday bar

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #42833 quote
    Pjotterd
    Participant
    Average

    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

    #42854 quote
    robertogozzi
    Moderator
    Master

    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!

    #42866 quote
    Pjotterd
    Participant
    Average

    Thanks Roberto, maybe somebody can help us out?

    #42868 quote
    robertogozzi
    Moderator
    Master

    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.

    #42913 quote
    Nicolas
    Keymaster
    Master

    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.

    #42955 quote
    robertogozzi
    Moderator
    Master

    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?

    Pic1.jpg Pic1.jpg Pic2.jpg Pic2.jpg
    #42968 quote
    Derek
    Participant
    Veteran

    So, what does it graph using your initial code?

    #43157 quote
    robertogozzi
    Moderator
    Master

    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.

    Old1.jpg Old1.jpg Old2.jpg Old2.jpg
    #43174 quote
    Derek
    Participant
    Veteran

    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.

    #43176 quote
    robertogozzi
    Moderator
    Master

    No 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!

    #43179 quote
    Derek
    Participant
    Veteran

    Did you try it?

    The company I work at produces quite a few manuals with errors.

    #43180 quote
    Derek
    Participant
    Veteran

    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.

    #43181 quote
    robertogozzi
    Moderator
    Master

    How would you write “BUY on Tuesday if the daily bar on Monday is bullish”?

    #43216 quote
    Derek
    Participant
    Veteran

    How about

    If currentdayofweek = 2 and close>open then
    Buy at market
    Endif
    #43221 quote
    robertogozzi
    Moderator
    Master

    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)!

    Old1-1.jpg Old1-1.jpg
Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.

Ignore sunday bar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Pjotterd @pjotterd Participant
Summary

This topic contains 22 replies,
has 5 voices, and was last updated by Derek
8 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/09/2017
Status: Active
Attachments: 9 files
Logo Logo
Loading...