ProOrder: error on long only strategy with ATR and RSI

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #258429 quote
    jereco273
    Participant
    New

    Hello , Please I made this code but pro Order do not accept it and I really need help ,

    It’s a code only buying position no short.




    // ===============================

    //       PARAMETRES

    // ===============================

    DEFPARAM CumulateOrders = False

    DEFPARAM PreLoadBars = 1000


    capitalPerTrade = 1000

    tradeCount = 0

    positionSize = 0


    // ===============================

    //       VARIABLES

    // ===============================

    atrValue = 0

    emaShort = 0

    rsiValue = 0

    volumeAvg = 0

    vwapValue = 0

    atrMultiplier = 0

    trailATRMultiplier = 1

    currentHour = 0

    hourStart1 = 9.5

    hourEnd1 = 11.5

    hourStart2 = 14

    hourEnd2 = 16

    maxTradesPerDay = 0

    inTradingHours = 0

    longCondition = 0

    liquidCondition = 0


    // ===============================

    //       INDICATEURS

    // ===============================

    atrValue = ATR[14](high, low, close)

    emaShort = EMA[9](close)

    rsiValue = RSI[14](close)

    volumeAvg = SMA[20](volume)

    vwapValue = VWAP[0]


    // ===============================

    //       FILTRE LIQUIDITE

    // ===============================

    liquidCondition = IFF(volumeAvg >= 500000, 1, 0)


    // ===============================

    //       HORAIRES US

    // ===============================

    currentHour = HOUR + MINUTE / 60

    inTradingHours = IFF(((currentHour >= hourStart1) AND (currentHour <= hourEnd1)) OR ((currentHour >= hourStart2) AND (currentHour <= hourEnd2)), 1, 0)


    // ===============================

    //    LIMITE DYNAMIQUE TRADES

    // ===============================

    IF atrValue < 1 THEN

      maxTradesPerDay = 2

    ELSIF atrValue < 2 THEN

      maxTradesPerDay = 3

    ELSE

      maxTradesPerDay = 5

    ENDIF


    // ===============================

    //     TAILLE POSITION

    // ===============================

    positionSize = FLOOR(capitalPerTrade / close)

    IF positionSize < 1 THEN

      positionSize = 1

    ENDIF


    // ===============================

    //     CONDITION LONG

    // ===============================

    longCondition = IFF(close > vwapValue AND low <= vwapValue AND close > open AND close > emaShort AND volume > volumeAvg AND rsiValue < 70 AND liquidCondition AND inTradingHours, 1, 0)


    IF longCondition = 1 AND tradeCount < maxTradesPerDay AND NOT ONMARKET THEN

      BUY positionSize SHARES AT MARKET

      tradeCount = tradeCount + 1

    ENDIF


    // ===============================

    //     STOP & TARGET ATR

    // ===============================

    IF atrValue < 1 THEN

      atrMultiplier = 2

    ELSIF atrValue < 2 THEN

      atrMultiplier = 2.5

    ELSE

      atrMultiplier = 3

    ENDIF


    SET STOP atrValue

    SET TARGET atrValue * atrMultiplier


    // ===============================

    //     BREAK EVEN

    // ===============================

    IF ONMARKET AND (close – ENTRYPRICE) >= (atrValue / 2) THEN

      MODIFY STOP ENTRYPRICE

    ENDIF


    // ===============================

    //     TRAILING STOP

    // ===============================

    IF ONMARKET AND (close – ENTRYPRICE) >= atrValue THEN

      MODIFY STOP (close – atrValue * trailATRMultiplier)

    ENDIF

    #258433 quote
    Nicolas
    Keymaster
    Master

    Please next time open a new topic rather than replying to an existing one not linked to your query.


    This code is made by AI and needs a lot of recoding. We’ll look at fix it as soon as possible.

    #258434 quote
    jereco273
    Participant
    New

    Yes , I had written one previously and I ask AI to make it correct but it’s seems with AI it’s still wrong

    #258435 quote
    jereco273
    Participant
    New

    I waiting for your reply thanks for your help

    #258436 quote
    Snålänningen
    Participant
    Junior

    Try this:


    // ===============================
    //        PARAMETERS
    // ===============================
    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars = 1000
    
    
    //PRC Rolling VWAP
    //version = 0
    //06.03.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    ///inputs
    src = customclose
    minBarsInput = 10
    stdevMult1 = 1
    stdevMult2 = 1.5
    stdevMult3 = 2.5
    showbands = 1
    
    
    //////BARS TO CALCULATE VWAP/////////
    if gettimeframe < 86400 then
    bars = minbarsinput
    elsif gettimeframe >= 86400 and gettimeframe < 604800 then
    bars = MAX(22,minbarsinput)
    elsif gettimeframe = 604800 then
    bars = MAX(round(90/5),minbarsinput)
    else
    bars = MAX(round(252/22),minbarsinput)
    endif
    //////////////////////////////////////
    
    
    sumSrcVol = summation[bars](src*volume)
    sumVol = summation[bars](volume)
    sumSrcSrcVol = summation[bars](pow(src,2)*volume)
    
    
    rollingvwap = sumSrcVol / SumVol
    
    
    
    
    //TRADING LOGIC
    
    
    // RESET tradeCount 
    IF Day <> Day[1] THEN
    tradeCount = 0
    ENDIF
    
    
    capitalPerTrade = 1000
    
    
    // ===============================
    //        INDICATOR
    // ===============================
    atrValue = AverageTrueRange[14](close)
    emaShort = ExponentialAverage[9](close)
    rsiValue = RSI[14](close)
    volumeAvg = Average[20](volume)
    vwapValue = rollingvwap 
    
    
    // ===============================
    //        FILTER & LOGIC
    // ===============================
    liquidCondition = volumeAvg >= 500000
    
    
    
    inTradingHours = (Time >= 093000 AND Time <= 113000) OR (Time >= 140000 AND Time <= 160000)
    
    
    // Dynamic values
    IF atrValue < 1 THEN
    maxTradesPerDay = 2
    atrMultiplier = 2
    ELSIF atrValue < 2 THEN
    maxTradesPerDay = 3
    atrMultiplier = 2.5
    ELSE
    maxTradesPerDay = 5
    atrMultiplier = 3
    ENDIF
    
    
    // ===============================
    //        POSITIONSIZE 
    // ===============================
    posSize = MAX(1, FLOOR(capitalPerTrade / close))
    
    
    longCondition = close > vwapValue AND low <= vwapValue and  close > open AND close > emaShort AND volume > volumeAvg AND rsiValue < 70 AND liquidCondition AND inTradingHours
    
    
    IF longCondition AND tradeCount < maxTradesPerDay AND NOT ONMARKET THEN
    BUY posSize SHARES AT MARKET
    tradeCount = tradeCount + 1
    ENDIF
    
    
    // ===============================
    //        EXIT LOGIC
    // ===============================
    
    
    
    
    SET STOP LOSS atrValue
    SET TARGET PROFIT (atrValue * atrMultiplier)
    
    
    // Break Even & Trailing 
    IF ONMARKET THEN
    // Break Even
    IF (close - PositionPrice) >= (atrValue / 2) THEN
    SELL AT PositionPrice STOP
    ENDIF
        
    //  Trailing
    IF (close - PositionPrice) >= atrValue THEN
    SELL AT (close - atrValue) STOP
    ENDIF
    ENDIF
    
    Nicolas and Iván González thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

ProOrder: error on long only strategy with ATR and RSI


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jereco273 @jereco273 Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Snålänningen
1 month, 3 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/23/2026
Status: Active
Attachments: No files
Logo Logo
Loading...