Code Review If possible please??

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #263156 quote
    Michael RobertsonMichael Robertson
    Participant
    New

    Hi,


    Anyone available to review my code?


    DEFPARAM CumulateOrders = False

    DEFPARAM PreLoadBars = 300


    Price = Close <—- I keep getting the following error ” Characters missing. Suggestions : end of code (How Fix?)

    High3m = Highest[63](Price)

    MA20 = Average[20](Price)

    MA50 = Average[50](Price)

    MA200 = Average[200](Price)


    TR1 = High – Low

    TR2 = Abs(High – Price[1])

    TR3 = Abs(Low – Price[1])

    TR = Max(TR1, Max(TR2, TR3))

    ATR14 = Average[14](TR)


    delta = Price – Price[1]

    gain = Max(delta, 0)

    loss = Max(-delta, 0)

    avgGain = Average[2](gain)

    avgLoss = Average[2](loss)


    IF avgLoss <> 0 THEN

    rs = avgGain / avgLoss

    RSI2 = 100 – (100 / (1 + rs))

    ELSE

    RSI2 = 50

    ENDIF


    TrendOK = MA50 > MA200


    ONCE inTrade = 0

    ONCE partialTaken = 0

    ONCE entryPrice = 0

    ONCE stopLevel = 0

    ONCE partialTarget = 0

    ONCE positionSize = 0


    IF BarIndex > 200 THEN


    ATR_STOP_MULT = 3

    PARTIAL_MULT = 2

    DD_LOW = 0.82

    DD_HIGH = 0.88

    VOL_MULT = 1.5

    RSI_THRESH = 3

    K = 1500


    IF ATR14 > 0 THEN

    positionSize = Round(K / ATR14)

    ELSE

    positionSize = 0

    ENDIF


    IF inTrade = 0 THEN


    IF High3m <> 0 AND MA20 <> 0 AND ATR14 <> 0 AND positionSize > 0 THEN

    rel = Price / High3m

    cond_dd = (rel <= DD_HIGH) AND (rel >= DD_LOW)

    cond_vol = Price < (MA20 – VOL_MULT * ATR14)

    cond_rsi = RSI2 < RSI_THRESH

    cond_trend = TrendOK


    IF cond_dd AND cond_vol AND cond_rsi AND cond_trend THEN

    BUY positionSize CONTRACTS AT MARKET

    inTrade = 1

    partialTaken = 0

    entryPrice = Price

    stopLevel = entryPrice – ATR_STOP_MULT * ATR14

    partialTarget = entryPrice + PARTIAL_MULT * ATR14

    ENDIF

    ENDIF


    ELSE


    exitReason = 0


    IF Low <= stopLevel THEN

    exitReason = 1

    ENDIF


    IF exitReason = 0 AND partialTaken = 0 AND High >= partialTarget THEN

    halfSize = Round(positionSize / 2)

    IF halfSize > 0 THEN

    SELL halfSize CONTRACTS AT partialTarget

    partialTaken = 1

    ENDIF

    ENDIF


    IF exitReason = 0 AND partialTaken = 1 AND Price < MA20 THEN

    exitReason = 2

    ENDIF


    IF exitReason > 0 THEN

    SELL AT MARKET

    inTrade = 0

    partialTaken = 0

    ENDIF


    ENDIF


    ENDIF

    #263169 quote
    JSJS
    Participant
    Master

    Hi,

    The error messages were caused by the use of reserved keywords (such as price, tr, loss, etc.)…

    In addition, the use of underscores (_) in variable names is not allowed…

    The code no longer generates any error messages…

    I have not reviewed the strategy logic itself…

    DEFPARAM CumulateOrders = False
    
    
    DEFPARAM PreLoadBars = 300
    
    
    ONCE inTrade = 0
    
    
    ONCE partialTaken = 0
    
    
    ONCE entryPrice = 0
    
    
    ONCE stopLevel = 0
    
    
    ONCE partialTarget = 0
    
    
    ONCE positionSize = 0
    
    
    xPrice = Close //<—- I keep getting the following error " Characters missing. Suggestions : end of code (How Fix?)
    
    
    High3m = Highest[63](xPrice)
    
    
    MA20 = Average[20](xPrice)
    
    
    MA50 = Average[50](xPrice)
    
    
    MA200 = Average[200](xPrice)
    
    
    
    
    TR1 = High - Low
    
    
    TR2 = Abs(High - xPrice[1])
    
    
    TR3 = Abs(Low - xPrice[1])
    
    
    xTR = Max(TR1, Max(TR2, TR3))
    
    
    ATR14 = Average[14](xTR)
    
    
    
    
    delta = xPrice - xPrice[1]
    
    
    gain = Max(delta, 0)
    
    
    xloss = Max(-delta, 0)
    
    
    avgGain = Average[2](gain)
    
    
    avgLoss = Average[2](xloss)
    
    
    
    
    IF avgLoss <> 0 THEN
    
    
    rs = avgGain / avgLoss
    
    
    RSI2 = 100 - (100 / (1 + rs))
    
    
    ELSE
    
    
    RSI2 = 50
    
    
    ENDIF
    
    
    
    
    TrendOK = MA50 > MA200
    
    
    
    
    IF BarIndex > 200 THEN
    
    
    ATRSTOPMULT = 3
    
    
    PARTIALMULT = 2
    
    
    DDLOW = 0.82
    
    
    DDHIGH = 0.88
    
    
    VOLMULT = 1.5
    
    
    RSITHRESH = 3
    
    
    K = 1500
    
    
    IF ATR14 > 0 THEN
    
    
    positionSize = Round(K / ATR14)
    
    
    ELSE
    
    
    positionSize = 0
    
    
    ENDIF
    
    
    
    
    
    
    IF inTrade = 0 THEN
    
    
    
    
    IF High3m <> 0 AND MA20 <> 0 AND ATR14 <> 0 AND positionSize > 0 THEN
    
    
    rel = xPrice / High3m
    
    
    conddd = (rel <= DDHIGH) AND (rel >= DDLOW)
    
    
    condvol = xPrice < (MA20 - VOLMULT * ATR14)
    
    
    condrsi = RSI2 < RSITHRESH
    
    
    condtrend = TrendOK
    
    
    
    
    
    
    IF conddd AND condvol AND condrsi AND condtrend THEN
    
    
    BUY positionSize CONTRACTS AT MARKET
    
    
    inTrade = 1
    
    
    partialTaken = 0
    
    
    entryPrice = xPrice
    
    
    stopLevel = entryPrice - ATRSTOPMULT * ATR14
    
    
    partialTarget = entryPrice + PARTIALMULT * ATR14
    
    
    ENDIF
    
    
    ENDIF
    
    
    ELSE
    
    
    
    
    exitReason = 0
    
    
    
    
    IF Low <= stopLevel THEN
    
    
    exitReason = 1
    
    
    ENDIF
    
    
    
    
    IF exitReason = 0 AND partialTaken = 0 AND High >= partialTarget THEN
    
    
    halfSize = Round(positionSize / 2)
    
    
    IF halfSize > 0 THEN
    
    
    SELL halfSize CONTRACTS AT market//partialTarget
    
    
    partialTaken = 1
    
    
    ENDIF
    
    
    ENDIF
    
    
    
    
    
    
    IF exitReason = 0 AND partialTaken = 1 AND xPrice < MA20 THEN
    
    
    exitReason = 2
    
    
    ENDIF
    
    
    IF exitReason > 0 THEN
    
    
    SELL AT MARKET
    
    
    inTrade = 0
    
    
    partialTaken = 0
    
    
    ENDIF
    
    
    ENDIF
    
    
    ENDIF
    
    Iván González thanked this post
    #264365 quote
    NicolasNicolas
    Keymaster
    Legend

    AI-generated code often has this type of error, and that’s what our upcoming tool ProRealAI will solve.

    More information:

    ProRealAI: From Idea to ProBuilder Code in Seconds

    robertogozzi thanked this post
    ULc8dpkFPU.png ULc8dpkFPU.png
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

Code Review If possible please??


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by NicolasNicolas
1 month, 2 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/04/2026
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...