Why did my strategy open a position?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #154380 quote
    sulimastersulimaster
    Participant
    Average

    Hi

    My code below seemed to work previously so I cannot understand why it doesn’t work anymore. Has something changed in PRT or is there a coding error?

    Backtesting based on Daily DJI. I have also attached screenshots of the trade day, trigger day and trigger day -1 values of the indicators to assist you. Why did backtesting open a new long position on 16th Dec 2020?

    The issue seems to be specifically in relation to the code in lines 33 to 45. In this particular example (see screenshots), x[1] > y[1] AND x[1] > 70 AND x > y are all true so a = 1. If a = 1, then as per line 49, it should not enter into a long position on 16th Dec 2020.

    x = AroonUp[10]

    y = AroonDown[10]

    Please advise. Let me know if you need any further information.

    Thanks

    Sachin

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    x = AroonUp[10]
    y = AroonDown[10]
    
    short = 12
    long = 26
    signal = 9
    
    EMAshort1 = exponentialaverage[short](close)
    EMAshort2 = exponentialaverage[short](EMAshort1)
    DifferenceShort = EMAshort1 - EMAshort2
    ZeroLagShort = EMAshort1 + DifferenceShort
     
    EMAlong1 = exponentialaverage[long](close)
    EMAlong2 = exponentialaverage[long](EMAlong1)
    DifferenceLong = EMAlong1 - EMAlong2
    ZeroLagLong = EMAlong1 + DifferenceLong
     
    ZeroLagMACD = ZeroLagShort - ZeroLagLong
     
    signal1 = ExponentialAverage[signal](ZEROLAGMACD)
    signal2 = ExponentialAverage[signal](signal1)
    DIFFERENCE2 = signal1 - signal2
     
    SignalMACD = signal1 + DIFFERENCE2
     
    z = Williams[8](close)
    
    ATR = AverageTrueRange[14](close)
    
    //POSITIONPERF(1) < 0 AND TRADEPRICE(2) > TRADEPRICE(1) AND
    IF ZeroLagMACD[1] > SignalMACD[1] AND ZeroLagMACD > SignalMACD AND x[1] > y[1] AND x[1] > 70 AND x > y THEN
    a = 1
    ELSE
    a = 0
    ENDIF
    
    //POSITIONPERF(1) < 0 AND TRADEPRICE(2) < TRADEPRICE(1) AND
    IF ZeroLagMACD[1] < SignalMACD[1] AND ZeroLagMACD < SignalMACD AND x[1] < y[1] AND y[1] > 70 AND x < y THEN
    b = 1
    ELSE
    b = 0
    ENDIF
    
    // Conditions to enter long positions
    
    IF a = 0 AND ATR < 500 AND ZeroLagMACD > SignalMACD AND z > -80 AND x > y AND x > 70 THEN
    BUY 0.2 PERPOINT AT MARKET
    SET STOP LOSS 1.5 * ATR
    ENDIF
    
    // Conditions to exit long positions
    
    IF (ZeroLagMACD CROSSES UNDER SignalMACD AND z < -20) OR y > x THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    
    IF b = 0 AND ATR < 500 AND ZeroLagMACD < SignalMACD AND z < -20 AND y > x AND y > 70 THEN
    SELLSHORT 0.2 PERPOINT AT MARKET
    SET STOP LOSS 1.5 * ATR
    ENDIF
    
    // Conditions to exit short positions
    
    IF (ZeroLagMACD CROSSES OVER SignalMACD AND z > -80) OR x > y THEN
    EXITSHORT AT MARKET
    ENDIF
    
    //c = BARINDEX - TRADEINDEX
    
    //IF LONGONMARKET AND (highest[c](high) - TRADEPRICE) > 500 THEN
    //SET STOP TRAILING 100
    //ELSIF SHORTONMARKET AND (TRADEPRICE - lowest[c](low)) > 500 THEN
    //SET STOP TRAILING 100
    //ENDIF
    
    Trade-Day.jpg Trade-Day.jpg Trigger-Day-1.jpg Trigger-Day-1.jpg Trigger-Day.jpg Trigger-Day.jpg
    #154815 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    If you append this code to your strategy:

    graph a
    graph ATR
    graph ZeroLagMACD
    graph SignalMACD
    graph z
    graph x
    graph y
    graph (a = 0 AND ATR < 500 AND ZeroLagMACD > SignalMACD AND z > -80 AND x > y AND x > 70)

    you will be able to see that on Dec. 15th 2020 conditions at line 49 were met when the daily candle closed, so it immediately entered a trade (signaled with an arrow on Dec. 16th).

    sulimaster thanked this post
    x-7.jpg x-7.jpg
    #154854 quote
    VonasiVonasi
    Moderator
    Master

    sulimaster – Please follow the forum rules and give any future topics a meaningful title otherwise we will end up with a forum full of ‘Code error’ topics. I have changed your topic title.

    #154899 quote
    sulimastersulimaster
    Participant
    Average

    Thanks Roberto

    Another thing I’m struggling with – in the live market (trading with IG), using the same strategy, why was a long trade opened on 18th Dec 2020 instead of 16th December 2020 as per the tick by tick back test (see attached)?

    Live-Trading-Chart.jpg Live-Trading-Chart.jpg Live-Trading.jpg Live-Trading.jpg
    #154937 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Mine was opened on Dec. 16th.

    x-9.jpg x-9.jpg
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Why did my strategy open a position?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
sulimaster @sulimaster Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by robertogozzirobertogozzi
5 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/19/2020
Status: Active
Attachments: 7 files
ProRealCode ProRealCode
Loading...