Problem with simple Pivot code

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #90721 quote
    PastaPesto
    Participant
    Veteran

    Hi again 🙂

    Just starting to look at a strategy including Pivots and got stuck directly on the first rule. My first rule is price to reach Res3 pivot, and I just made a simple code for that frst rule but it doesnt work. Please see picture attached and code. Picture will show two order that seems to be ok and one is executed in the wrong place (and there are lots of them). What do I do wrong here? Price has not reached the RES3 but gets triggered anyway.

    DEFPARAM CumulateOrders = False 
    
    // Conditions to enter short positions
    Res3 = DHigh(1)+2*((DHigh(1) + DLow(1) + DClose(1))/3-DLow(1))
    c1 = (close >= Res3)
    
    if not onmarket and c1 then
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    Pivot = (DHigh(1) + DLow(1) + DClose(1))/3
    c2 = (close <= Pivot)
    
    IF c2 THEN
    EXITSHORT AT MARKET
    ENDIF
    Pivot.jpg Pivot.jpg
    #90725 quote
    Vonasi
    Moderator
    Master

    Try using GRAPH to graph Res3, close and Pivot to confirm that they are calculated to match your indicator.

    graph res3
    graph close
    graph pivot
    #90731 quote
    PastaPesto
    Participant
    Veteran

    Thank you Vonasi, it is clearly monday that is the problem. It seems that RES3 is looking at sunday, and that messes up the pivots and draw them really close to eachother. It was very clear using the “graph”. Thank you for that tips.

    Is there someway to make RES3 not include sunday and look at friday instdead when calculating pivot for monday?

    #90736 quote
    Vonasi
    Moderator
    Master

    I have some code somewhere that I wrote to avoid the Sunday candles issue. I’ll try to find it for you.

    PastaPesto thanked this post
    #90739 quote
    Vonasi
    Moderator
    Master

    I’m not sure if this is something that I wrote or I stole! – but here is the code as an indicator for pivot, s1 and r1 which you should be able to adapt easily to levels 2 and 3 and into a strategy code too.

    a1 = OpenDayOfWeek
    b1 = DHigh(1)
    b2 = DHigh(2)
    c1 = DLow(1)
    c2 = DLow(2)
    d1 = DClose(1)
    d2 = DClose(2)
    
    IF a1 = 1 THEN
    b1 = b2
    c1 = c2
    d1 = d2
    ELSE
    b1 = b1
    c1 = c1
    d1 = d1
    ENDIF
    
    H1 = b1//High
    L1 = c1//Low
    C = d1//Close
    
    Pivot = (H1 + L1 + C) / 3
    R1 = 2*((H1 + L1 + C) / 3) - L1
    S1 = 2*((H1 + L1 + C) / 3) - H1
    
    return Pivot as "Point Pivot", R1 as "R1", S1 as "S1"
    
    #90828 quote
    PastaPesto
    Participant
    Veteran

    That works perfectly!

    Thanks!

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

Problem with simple Pivot code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
PastaPesto @pastapesto Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by PastaPesto
7 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/07/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...