Pivots Points – Buy and sell short strategy

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #220441 quote
    Inertia
    Participant
    Master

    Hello,

    Just looking for an automated strategy that involves Pivots Points (Free or with a small fee).

    Conditions:

    Buy if PP is support

    Sell if PP is resistance

    TF to be determined manually.

    TP to be determined manually.

     

    Thank you

     

     

    Thank you

    Damien

    Screenshot-2023-09-06-171420.jpg Screenshot-2023-09-06-171420.jpg
    #220547 quote
    robertogozzi
    Moderator
    Master

    Any help and code posted on this forum is ALWAYS for free.

    There you go:

    DEFPARAM CumulateOrders = False
    SL    = 200 * PipSize
    TP    = SL * 3
    N     = 5
    PP    = (DHigh(1) + DLow(1) + DClose(1))/3    //PP calculation
    //
    Res1  = summation[N](close <= PP) = N
    Res2  = summation[N](high >= PP)
    Res   = Res1 AND Res2
    //
    Sup1  = summation[N](close >= PP) = N
    Sup2  = summation[N](low <= PP)
    Sup   = Sup1 AND Sup2
    //
    IF Sup AND Not LongOnMarket THEN
       BUY 1 CONTRACT AT MARKET
    ELSIF Res AND Not ShortOnMarket THEN
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //
    SET TARGET pPROFIT TP
    SET STOP   pLOSS   SL
    //
    GraphOnPrice PP         AS "Pivot"      coloured("Fuchsia",255)
    GraphOnPrice TradePrice AS "TradePrice" coloured("Cyan",255)
    Midlanddave, Inertia, Nicolas and KumoNoJuzza thanked this post
    #220563 quote
    Inertia
    Participant
    Master

    Hi Roberto, Big thanks to you and very long life to this forum!

    #220567 quote
    Nicolas
    Keymaster
    Master

    Nice approach by Roberto!

    Other code related to avoid take positions near pivot points: https://www.prorealcode.com/topic/prevent-entry-near-pivot-points/#post-202658

    could be easily reverted to take positions on them.

    robertogozzi and Inertia thanked this post
    #222589 quote
    Inertia
    Participant
    Master
    DEFPARAM CumulateOrders = False
    
    SL    = 40
    TP    = 10
    N     = 5
    Ht = DHigh(1)
    Bs = DLow(1)
    C = DClose(1)
    Pivot = (Ht + Bs + C) / 3
    //
    Res1  = summation[N](close <= Pivot) = N
    Res2  = (high[1] >= Pivot)
    Res   = Res1 AND Res2
    //
    Sup1  = summation[N](close >= Pivot) = N
    Sup2  = (low[1] <= Pivot)
    Sup   = Sup1 AND Sup2
    //
    IF Sup AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF Res AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //
    SET TARGET pPROFIT TP
    SET STOP   pLOSS   SL

    Good morning Roberto,

    Thank you for this strategy.

    I am scratching my head wondering why this strategy did not take a short position at 1030am this morning (NASDAQ – 1 mn UT) ?

    Point pivot was a “Res” for the close, 5 previous close were below Point Pivot and high was over point pivot.

    Thank you.

    Damien

    Screenshot-2023-10-18-104827.png Screenshot-2023-10-18-104827.png
    #222591 quote
    robertogozzi
    Moderator
    Master

    Because it was already ShortOnMarket AND condition Sup1 was false.

    Using GRAPH extensively to monitor your conditions and other data will help you.

    Inertia thanked this post
    #222600 quote
    Inertia
    Participant
    Master

    Thank you Roberto for your swift answer. Appreciated.

    If I am not mistaken, the strategy was flat. I added the Graph as you said. I have ignored the Sup1 // …

    According to the chart, the strategy should have taken postions at 9:44am & 9:54am and 10:31am? What do you think?

    These types of entries are the one I am looking for. I am a dummy in coding 😉

    Screenshot-2023-10-18-114618.png Screenshot-2023-10-18-114618.png
    #222606 quote
    robertogozzi
    Moderator
    Master

    Append these lines to your code:

    graphonprice Pivot coloured("Fuchsia")
    graph Res          coloured("Red")
    graph Sup          coloured("Green")

    you will see that NO condition was true and that the price was quite far from the pivot line.

    x-4.jpg x-4.jpg
    #222615 quote
    Inertia
    Participant
    Master

    Find it why, thank you Roberto.

    1 – The code uses the previous PP (1) so of course there were no trade taken in the mentioned levels today (0). Sorry 😉

    2 – But when i change the PP with (0) instead of (1) it gives a funny PP… How can i have it straight like the PRT one please?

    Thank you.

    Damien

    Screenshot-2023-10-18-143328.png Screenshot-2023-10-18-143328.png Screenshot-2023-10-18-143226.png Screenshot-2023-10-18-143226.png
    #222618 quote
    Inertia
    Participant
    Master
    Ht = DHigh(1)
    Bs = DLow(1)
    C = DClose(1)
    Pivot = (Ht + Bs + C) / 3
    Res3 = Res1 + (Ht - Bs)
    Res2 = Pivot + Ht - Bs
    Res1 = (2 * Pivot) - Bs
    Sup1 = (2 * Pivot) - Ht
    Sup2 = Pivot - (Ht - Bs)
    Sup3 = Sup1 - (Ht - Bs)
    
    Return Res1        AS "Res1"      coloured("green"), Res2        AS "Res2"      coloured("green"), Res3        AS "Res3"      coloured("green"), Pivot        AS "Pivot"      coloured("black"), Sup1        AS "Sup1"      coloured("red"), Sup2        AS "Sup2"      coloured("red"), Sup3        AS "Sup3"      coloured("red")

    Strangely, the indicator PP Daily gives a straight line for the PP Pivot like the PRT PP even with the (1)… Please help. Thank you Roberto.

    #222620 quote
    robertogozzi
    Moderator
    Master

    Sorry, but I can’t understand what you want to do, why are you comparing yestarday’s (1)  data with today’s (0)?

    Please post exactly the code you want to use and tell me when it doesn’t work according to you (on Nasdaq, 1-minute TF) ?

    Inertia thanked this post
    #222687 quote
    Inertia
    Participant
    Master

    Bonjour Nicolas,

    J’ai envoyé une demande mercredi via la messagerie “Trading Programming Service” afin de faire construire la Ferrari des points Pivots 😉 dans votre garage. C’est possible, n’est-ce pas ?

    Excellente journée.

    Damien

    Hello Nicolas, I sent a request on Wednesday via the “Trading Programming Service” messaging service to have the Pivot Points Ferrari built 😉 in your garage. It’s possible, isn’t it? Excellent day.

    Damien

    #222695 quote
    robertogozzi
    Moderator
    Master

    @Inertia

    Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Thanks 🙂

    Inertia thanked this post
    #222696 quote
    Inertia
    Participant
    Master

    Sorry Roberto. Thank you. Cheers. Thank you for your help.

    #222803 quote
    Inertia
    Participant
    Master
    //-------------------------------------------------------------------------
    // Main code : DAX OCTOBRE
    //-------------------------------------------------------------------------
    DEFPARAM CumulateOrders     = TRUE  // Cumulating positions deactivated
    //monthly values
    // MONTHLY
    mR1M = 15828
    R1M = 16016
    mR2M = 16283
    R2M = 16550
    mR3M = 16738
    R3M = 16926
    mR4M = 17381
    R4M = 17836
    PivotM = 15640
    mS1M = 15373
    S1M = 15106
    mS2M = 14918
    S2M = 14730
    mS3M = 14663
    S3M = 14196
    mS4M = 13741
    S4M = 13286
    //WEEKLY VALUES
    R4W = 16331
    R3W = 15791
    R2W = 15598
    R1W = 15251
    PivotW = 15058
    S1W =  14711
    S2W = 14518
    S3W = 14171
    S4W = 13631
    //TITAN
    HigWPrev = 15683
    HigMPrev = 16175
    LowWPrev = 15188
    LowMPrev = 15265
    
    //ROUNDNUMBER VALUES
    c1 = 15000
    c2 = 14500
    c3  = 14000
    c4 = 15500
    c5 = 16000
    
    //N periodes to look back
    N = 5
    //Position taker
    //mR1M
    r1mR1M = summation[N](close <= mR1M) = N
    r2mR1M = summation[1](high >= mR1M)
    tlmR1M = r1mR1M AND r2mR1M
    //
    s1mR1M = summation[N](close >= mR1M) = N
    s2mR1M = summation[1](low <= mR1M)
    tsmR1M = s1mR1M AND s2mR1M
    //
    IF tsmR1M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlmR1M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //R1M
    r1R1M = summation[N](close <= R1M) = N
    r2R1M = summation[1](high >= R1M)
    tlR1M = r1R1M AND r2R1M
    //
    s1R1M = summation[N](close >= R1M) = N
    s2R1M = summation[1](low <= R1M)
    tsR1M = s1R1M AND s2R1M
    //
    IF tsR1M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR1M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //mR2M
    r1mR2M = summation[N](close <= mR2M) = N
    r2mR2M = summation[1](high >= mR2M)
    tlmR2M = r1mR2M AND r2mR2M
    //
    s1mR2M = summation[N](close >= mR2M) = N
    s2mR2M = summation[1](low <= mR2M)
    tsmR2M = s1mR2M AND s2mR2M
    //
    IF tsmR2M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlmR2M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //M2M
    r1R2M = summation[N](close <= R2M) = N
    r2R2M = summation[1](high >= R2M)
    tlR2M = r1R2M AND r2R2M
    //
    s1R2M = summation[N](close >= R2M) = N
    s2R2M = summation[1](low <= R2M)
    tsR2M = s1R2M AND s2R2M
    //
    IF tsR2M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR2M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //m3RM
    r1mR3M = summation[N](close <= mR3M) = N
    r2mR3M = summation[1](high >= mR3M)
    tlmR3M = r1mR3M AND r2mR3M
    //
    s1mR3M = summation[N](close >= mR3M) = N
    s2mR3M = summation[1](low <= mR3M)
    tsmR3M = s1mR3M AND s2mR3M
    //
    IF tsmR3M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlmR3M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //3RM
    r1R3M = summation[N](close <= R3M) = N
    r2R3M = summation[1](high >= R3M)
    tlR3M = r1R3M AND r2R3M
    //
    s1R3M = summation[N](close >= R3M) = N
    s2R3M = summation[1](low <= R3M)
    tsR3M = s1R3M AND s2R3M
    //
    IF tsR3M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR3M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //
    //m4RM
    r1mR4M = summation[N](close <= mR4M) = N
    r2mR4M = summation[1](high >= mR4M)
    tlmR4M = r1mR4M AND r2mR4M
    //
    s1mR4M = summation[N](close >= mR4M) = N
    s2mR4M = summation[1](low <= mR4M)
    tsmR4M = s1mR4M AND s2mR4M
    //
    IF tsmR4M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlmR4M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //4RM
    r1R4M = summation[N](close <= R4M) = N
    r2R4M = summation[1](high >= R4M)
    tlR4M = r1R4M AND r2R4M
    //
    s1R4M = summation[N](close >= R4M) = N
    s2R4M = summation[1](low <= R4M)
    tsR4M = s1R4M AND s2R4M
    //
    IF tsR4M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR4M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //
    //PIVOT M
    r1PivotM = summation[N](close <= PivotM) = N
    r2PivotM = summation[1](high >= PivotM)
    tlPivotM = r1PivotM AND r2PivotM
    //
    s1PivotM = summation[N](close >= PivotM) = N
    s2PivotM = summation[1](low <= PivotM)
    tsPivotM = s1PivotM AND s2PivotM
    //
    IF tsPivotM AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlPivotM AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //mS1MV
    r1mS1M = summation[N](close <= mS1M) = N
    r2mS1M = summation[1](high >= mS1M)
    tlmS1M = r1mS1M AND r2mS1M
    //
    s1mS1M = summation[N](close >= mS1M) = N
    s2mS1M = summation[1](low <= mS1M)
    ssmS1M = s1mS1M AND s2mS1M
    //
    IF ssmS1M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlmS1M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S1MV
    r1S1M = summation[N](close <= S1M) = N
    r2S1M = summation[1](high >= S1M)
    tlS1M = r1S1M AND r2S1M
    //
    s1S1M = summation[N](close >= S1M) = N
    s2S1M = summation[1](low <= S1M)
    tsS1M = s2S1M AND s1S1M
    //
    IF tsS1M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS1M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //mS2M
    r1mS2M = summation[N](close <= mS2M) = N
    r2mS2M = summation[1](high >= mS2M)
    tlmS2M = r1mS2M AND r2mS2M
    //
    s1mS2M = summation[N](close >= mS2M) = N
    s2mS2M = summation[1](low <= mS2M)
    tsmS2M = s1mS2M AND s2mS2M
    //
    IF tsmS2M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlmS2M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S2M
    r1S2M = summation[N](close <= S2M) = N
    r2S2M = summation[1](high >= S2M)
    tlS2M = r1S2M AND r2S2M
    //
    s1S2M = summation[N](close >= S2M) = N
    s2S2M = summation[1](low <= S2M)
    tsS2M = s1S2M AND s2S2M
    //
    IF tsS2M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS2M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //mS3M
    r1SmS3M = summation[N](close <= mS3M) = N
    r2SmS3M = summation[1](high >= mS3M)
    tlSmS3M = r1SmS3M AND r2SmS3M
    //
    s1SmS3M = summation[N](close >= mS3M) = N
    s2SmS3M = summation[1](low <= mS3M)
    tsSmS3M = s1SmS3M AND s2SmS3M
    //
    IF tsSmS3M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlSmS3M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S3M
    r1S3M  = summation[N](close <= S3M) = N
    r2S3M = summation[1](high >= S3M)
    tlS3M = r1S3M AND r2S3M
    //
    s1S3M = summation[N](close >= S3M) = N
    s2S3M = summation[1](low <= S3M)
    tsS3M = s1S3M AND s2S3M
    //
    IF tsS3M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS3M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //mS4MV
    r1SmS4M = summation[N](close <= mS4M) = N
    r2SmS4M = summation[1](high >= mS4M)
    tlSmS4M = r1SmS4M AND r2SmS4M
    //
    s1SmS4M = summation[N](close >= mS4M) = N
    s2SmS4M = summation[1](low <= mS4M)
    tsSmS4M = s1SmS4M AND s2SmS4M
    //
    IF tsSmS4M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlSmS4M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S4MV
    r1S4M = summation[N](close <= S4M) = N
    r2S4M = summation[1](high >= S4M)
    tlS4M = r1S4M AND r2S4M
    //
    s1S4M = summation[N](close >= S4M) = N
    s2S4M = summation[1](low <= S4M)
    tsS4M = s1S4M AND s2S4M
    //
    IF tsS4M AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS4M AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //R1W
    r1R1W = summation[N](close <= R1W) = N
    r2R1W = summation[1](high >= R1W)
    tlR1W = r1R1W AND r2R1W
    //
    s1R1W = summation[N](close >= R1W) = N
    s2R1W= summation[1](low <= R1W)
    tsR1W = s1R1W AND s2R1W
    //
    IF tsR1W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR1W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //R2W
    r1R2W = summation[N](close <= R2W) = N
    r2R2W = summation[1](high >= R2W)
    tlR21W = r1R2W AND r2R2W
    //
    s1R2W = summation[N](close >= R2W) = N
    s2R2W= summation[1](low <= R2W)
    tsR21W = s1R2W AND s2R2W
    //
    IF tsR21W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR21W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //R3W
    r1R3W = summation[N](close <= R3W) = N
    r2R3W = summation[1](high >= R3W)
    tlR3W = r1R3W AND r2R3W
    //
    s1R3W = summation[N](close >= R3W) = N
    s2R3W= summation[1](low <= R3W)
    tsR31W = s1R3W AND s2R3W
    //
    IF tsR31W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR3W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //R4W
    r1R4W = summation[N](close <= R4W) = N
    r2R4W = summation[1](high >= R4W)
    tlR4W = r1R4W AND r2R4W
    //
    s1R4W = summation[N](close >= R4W) = N
    s2R4W= summation[1](low <= R4W)
    tsR41W = s1R4W AND s2R4W
    //
    IF tsR41W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlR4W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //PivotW
    r1PivotW = summation[N](close <= PivotW) = N
    r2PivotW = summation[1](high >= PivotW)
    tlPivotW = r1PivotW AND r2PivotW
    //
    s1PivotW = summation[N](close >= PivotW) = N
    s2PivotW= summation[1](low <= PivotW)
    tsPivotW = s1PivotW AND s2PivotW
    //
    IF tsPivotW AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlPivotW AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S1W
    r1S1W = summation[N](close <= S1W) = N
    r2S1W = summation[1](high >= S1W)
    tlS1W = r1S1W AND r2S1W
    //
    s1S1W = summation[N](close >= S1W) = N
    s2S1W = summation[1](low <= S1W)
    tsS1W = s1S1W AND s2S1W
    //
    IF tsS1W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS1W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S2W
    r1S2W = summation[N](close <= S2W) = N
    r2S2W = summation[1](high >= S2W)
    tlS2W = r1S2W AND r2S2W
    //
    s1S2W = summation[N](close >= S2W) = N
    s2S2W = summation[1](low <= S2W)
    tsS2W = s1S2W AND s2S2W
    //
    IF tsS2W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS2W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S3W
    r1S3W = summation[N](close <= S3W) = N
    r2S3W = summation[1](high >= S3W)
    tlS3W = r1S3W AND r2S3W
    //
    s1S3W = summation[N](close >= S3W) = N
    s2S3W = summation[1](low <= S3W )
    tsS3W = s1S3W AND s2S3W
    //
    IF tsS3W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS3W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S3W
    r1S4W = summation[N](close <= S4W) = N
    r2S4W = summation[1](high >= S4W)
    tlS4W = r1S4W AND r2S4W
    //
    s1S4W = summation[N](close >= S4W) = N
    s2S4W = summation[1](low <= S4W )
    tsS4W = s1S4W AND s2S4W
    //
    IF tsS4W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS4W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //S4W
    r1S4W = summation[N](close <= S4W) = N
    r2S4W = summation[1](high >= S4W)
    tlS4W = r1S4W AND r2S4W
    //
    s1S4W = summation[N](close >= S4W) = N
    s2S4W = summation[1](low <= S4W )
    tsS4W = s1S4W AND s2S4W
    //
    IF tsS4W AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlS4W AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //HigWPrev
    r1HigWPrev = summation[N](close <= HigWPrev) = N
    r2HigWPrev = summation[1](high >= HigWPrev)
    tlHigWPrev = r1HigWPrev AND r2HigWPrev
    //
    s1HigWPrev = summation[N](close >= HigWPrev) = N
    s2HigWPrev = summation[1](low <= HigWPrev )
    tsHigWPrev = s1HigWPrev AND s2HigWPrev
    //
    IF tsHigWPrev AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlHigWPrev AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //HigMPrev
    r1HigMPrev = summation[N](close <= HigMPrev) = N
    r2HigMPrev = summation[1](high >= HigMPrev)
    tlHigMPrev = r1HigMPrev AND r2HigMPrev
    //
    s1HigMPrev = summation[N](close >= HigMPrev) = N
    s2HigMPrev = summation[1](low <= HigMPrev )
    tsHigMPrev = s1HigMPrev AND s2HigMPrev
    //
    IF tsHigMPrev AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlHigMPrev AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //LowWPrev
    r1LowWPrev = summation[N](close <= LowWPrev) = N
    r2LowWPrev = summation[1](high >= LowWPrev)
    tlLowWPrev = r1LowWPrev AND r2LowWPrev
    //
    s1LowWPrev = summation[N](close >= LowWPrev) = N
    s2LowWPrev = summation[1](low <= LowWPrev )
    tsLowWPrev = s1LowWPrev AND s2LowWPrev
    //
    IF tsLowWPrev AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlLowWPrev AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //LowMPrev
    r1LowMPrev = summation[N](close <= LowMPrev) = N
    r2LowMPrev = summation[1](high >= LowMPrev)
    tlLowMPrev = r1LowWPrev AND r2LowMPrev
    //
    s1LowMPrev = summation[N](close >= LowMPrev) = N
    s2LowMPrev = summation[1](low <= LowMPrev )
    tsLowMPrev = s1LowMPrev AND s2LowMPrev
    //
    IF tsLowMPrev AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlLowMPrev AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //c1
    r1c1 = summation[N](close <= c1) = N
    r2c1 = summation[1](high >= c1)
    tlc1 = r1c1 AND r2c1
    //
    s1c1= summation[N](close >= c1) = N
    s2Lc1 = summation[1](low <= c1)
    tsc1 = s1c1 AND s2Lc1
    //
    IF tsc1 AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlc1 AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //c2
    r1c2 = summation[N](close <= c2) = N
    r2c2 = summation[1](high >= c2)
    tlc2 = r1c2 AND r2c2
    //
    s12c2 = summation[N](close >= c2) = N
    s2Lc2 = summation[1](low <= c2)
    tsc2 = s12c2 AND s2Lc2
    //
    IF tsc2 AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlc2 AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //c3
    r1c3 = summation[N](close <= c3) = N
    r2c3 = summation[1](high >= c3)
    tlc3 = r1c3 AND r2c3
    //
    s12c3 = summation[N](close >= c3) = N
    s2Lc3 = summation[1](low <= c3)
    tsc3 = s12c3 AND s2Lc3
    //
    IF tsc3 AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlc3 AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //c4
    r1c4 = summation[N](close <= c4) = N
    r2c4 = summation[1](high >= c4)
    tlc4 = r1c4 AND r2c4
    //
    s12c4 = summation[N](close >= c4) = N
    s2Lc4 = summation[1](low <= c4)
    tsc4 = s12c4 AND s2Lc4
    //
    IF tsc4 AND Not LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
    ELSIF tlc4 AND Not ShortOnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    //
    TS        =   7  //   30
    trailingstop = TS//Best 30
    if not onmarket then
    MAXPRICE = 0
    priceexit = 0
    endif
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    SELL AT priceexit STOP
    endif
    
    TS        =   7  //   30
    trailingstop = TS//Best 30
    if not onmarket then
    MINPRICE = close
    priceexit = 0
    endif
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    
    SET STOP %LOSS 0.15
    SET TARGET %PROFIT 0.07
    

    Hello Roberto,

    Here is the code.

    Highlighted in yellow the level to Buy OR Sellshort.

    No trade were taken despite: “DEFPARAM CumulateOrders = TRUE “.

    Thank you for your help.

    Screenshot-2023-10-23-094658.png Screenshot-2023-10-23-094658.png mS2M-14918.png mS2M-14918.png Screenshot-2023-10-23-093623.png Screenshot-2023-10-23-093623.png
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Pivots Points – Buy and sell short strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Inertia @inertia Participant
Summary

This topic contains 16 replies,
has 4 voices, and was last updated by LaMaille
2 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/06/2023
Status: Active
Attachments: 11 files
Logo Logo
Loading...