positioning trading system

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #248473 quote
    Patrick K TemplarPatrick K Templar
    Participant
    Average
    // Prevent multiple orders in the same direction
    defparam cumulateorders = false
    
    // Initialize
    ONCE N = 1
    PointsToKeep = 5 // Breakeven buffer in points
    
    // Reset management variables when flat
    IF NOT ONMARKET THEN
    breakevenLevel = 0
    newSL = 0
    ENDIF
    
    // --- Indicator ---
    indicator1 = MACD[20,30,9](typicalPrice)
    c1 = (indicator1 CROSSES OVER 0)
    
    B1 = (indicator1 CROSSES UNDER 0)
    
    // --- Long Trade Entry ---
    IF c1 AND NOT ONMARKET THEN
    Tp  = AverageTrueRange[14](CLOSE) * 2
    Tp2 = AverageTrueRange[14](CLOSE) * 2
    Tp3 = AverageTrueRange[14](CLOSE) * 3
    St  = AverageTrueRange[14](CLOSE) * 2.5
    Ts  = AverageTrueRange[14](CLOSE) * 1
    
    startBreakeven = Tp
    trailingstart = Ts
    trailingstep = St * pipsize
    
    BUY 4 PERPOINT AT MARKET
    SET STOP PLOSS St * pipsize
    N = 1
    ENDIF
    
    // --- Long Trade Management ---
    IF LONGONMARKET AND abs(CountOfPosition) = 3 AND close - TRADEPRICE(1) >= startBreakeven * pipsize THEN
    breakevenLevel = TRADEPRICE(1) + PointsToKeep * pipsize
    ENDIF
    
    IF LONGONMARKET AND CLOSE >= (TRADEPRICE(1) + Tp) AND abs(CountOfPosition) = 4 THEN
    SELL 1 PERPOINT AT MARKET
    ENDIF
    
    IF LONGONMARKET AND CLOSE >= (TRADEPRICE(1) + Tp2) AND abs(CountOfPosition) = 3 THEN
    SELL 1 PERPOINT AT MARKET
    ENDIF
    
    IF LONGONMARKET AND CLOSE >= (TRADEPRICE(1) + Tp3) AND abs(CountOfPosition) = 2 THEN
    SELL 1 PERPOINT AT MARKET
    ENDIF
    
    IF LONGONMARKET THEN
    IF newSL = 0 AND close - TRADEPRICE(1) >= trailingstart * pipsize THEN
    newSL = high - trailingstep * pipsize
    ENDIF
    IF newSL > 0 AND close - newSL >= trailingstep * pipsize THEN
    newSL = high - trailingstep * pipsize
    ENDIF
    ENDIF
    
    IF breakevenLevel > 0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    
    IF newSL > 0 THEN
    SELL AT newSL STOP
    ENDIF
    
    // --- Short Trade Entry ---
    IF B1 AND NOT ONMARKET THEN
    Tp  = AverageTrueRange[14](CLOSE) * 2
    Tp2 = AverageTrueRange[14](CLOSE) * 2
    Tp3 = AverageTrueRange[14](CLOSE) * 3
    St  = AverageTrueRange[14](CLOSE) * 2.5
    Ts  = AverageTrueRange[14](CLOSE) * 1
    
    startBreakeven = Tp
    trailingstart = Ts
    trailingstep = St * pipsize
    
    SELLSHORT 4 PERPOINT AT MARKET
    SET STOP PLOSS St * pipsize
    N = 1
    ENDIF
    
    // --- Short Trade Management ---
    IF SHORTONMARKET AND abs(CountOfPosition) = 3 AND TRADEPRICE(1) - close >= startBreakeven * pipsize THEN
    breakevenLevel = TRADEPRICE(1) - PointsToKeep * pipsize
    ENDIF
    
    IF SHORTONMARKET AND CLOSE <= (TRADEPRICE(1) - Tp) AND abs(CountOfPosition) = 4 THEN
    EXITSHORT 1 PERPOINT AT MARKET
    ENDIF
    
    IF SHORTONMARKET AND CLOSE <= (TRADEPRICE(1) - Tp2) AND abs(CountOfPosition) = 3 THEN
    EXITSHORT 1 PERPOINT AT MARKET
    ENDIF
    
    IF SHORTONMARKET AND CLOSE <= (TRADEPRICE(1) - Tp3) AND abs(CountOfPosition) = 2 THEN
    EXITSHORT 1 PERPOINT AT MARKET
    ENDIF
    
    IF SHORTONMARKET THEN
    IF newSL = 0 AND TRADEPRICE(1) - close >= trailingstart * pipsize THEN
    newSL = low - trailingstep * pipsize
    ENDIF
    IF newSL > 0 AND TRADEPRICE(1) - newSL >= trailingstep * pipsize THEN
    newSL = low - trailingstep * pipsize
    ENDIF
    ENDIF
    
    IF breakevenLevel > 0 THEN
    EXITSHORT AT breakevenLevel STOP
    ENDIF
    
    IF newSL > 0 THEN
    EXITSHORT AT newSL STOP
    ENDIF
    
    // --- Visualization ---
    GraphOnPrice newSL coloured("purple") AS "Trailing Stop"
    GraphOnPrice breakevenLevel coloured("orange") AS "Breakeven Level"
    
    // Long trade visuals
    IF LONGONMARKET THEN
    GraphOnPrice (TRADEPRICE(1) + Tp) coloured("lightgreen") AS "Long Exit 1"
    GraphOnPrice (TRADEPRICE(1) + Tp2) coloured("green") AS "Long Exit 2"
    GraphOnPrice (TRADEPRICE(1) + Tp3) coloured("darkgreen") AS "Long Exit 3"
    GraphOnPrice (TRADEPRICE(1) - St) coloured("red") AS "Stop"
    ENDIF
    
    // Short trade visuals
    IF SHORTONMARKET THEN
    GraphOnPrice (TRADEPRICE(1) - Tp) coloured("lightblue") AS "Short Exit 1"
    GraphOnPrice (TRADEPRICE(1) - Tp2) coloured("blue") AS "Short Exit 2"
    GraphOnPrice (TRADEPRICE(1) - Tp3) coloured("darkblue") AS "Short Exit 3"
    GraphOnPrice (TRADEPRICE(1) + St) coloured("red") AS "Stop"
    ENDIF

    #248474 quote
    Patrick K TemplarPatrick K Templar
    Participant
    Average

    positioning trading system seems to have a fault with the shorts not scaling out I believe it’s due to a coding error

    #248477 quote
    Patrick K TemplarPatrick K Templar
    Participant
    Average

    dont worry iv fixed it

    robertogozzi thanked this post
Viewing 3 posts - 1 through 3 (of 3 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

positioning trading system


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 2 replies,
has 1 voice, and was last updated by Patrick K TemplarPatrick K Templar
1 year, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/21/2025
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...