Trying to code a screener but has error

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #252514 quote
    steff_bcn
    Participant
    New

    Hello!
    I’m just learning about everything trading and trying out strategies. I tried to build a screener with help of Chat Gpt but it seems not to know the right syntax.
    There is a problem with this line:
    macdLine=emaF-emaS

    Is it something easy to fix?
    Would appreciate your help.

    Thank you!

    ** Entire proposed code **

    minConsWeeks=6
    maP=20
    natrP=14
    natrThresh=8
    minGain=5
    maxGain=20
    volRatio=1.3
    macdFast=12
    macdSlow=26
    macdSig=9
    maxWidthPct=40
    
    ma20=Average[maP](close)
    atr=Average[natrP](TrueRange)
    natr=(atr/close)*100
    
    emaF=ExponentialAverage[macdFast](close)
    emaS=ExponentialAverage[macdSlow](close)
    macdLine=emaF-emaS
    macdSignal=ExponentialAverage[macdSig](macdLine)
    
    highCons=Highest[minConsWeeks](close)
    lowCons=Lowest[minConsWeeks](close)
    IF lowCons<>0 THEN
    consWidth=((highCons-lowCons)/lowCons)*100
    ELSE
    consWidth=0
    ENDIF
    isCons=consWidth<=maxWidthPct AND natr<natrThresh
    
    high10=Highest[10](close)
    is10high=close>=high10
    
    IF close[1]<>0 THEN
    pctMove=((close-close[1])/close[1])*100
    ELSE
    pctMove=0
    ENDIF
    pctOk=pctMove>=minGain AND pctMove<=maxGain
    
    volSpike=volume>volume[1]*volRatio
    priceAboveMA=close>ma20
    macdBull=macdLine>macdSignal
    
    cHeight=high-low
    IF cHeight>0 THEN
    IF close>=open THEN
    uWick=high-close
    ELSE
    uWick=high-open
    ENDIF
    uWickPct=(uWick/cHeight)*100
    ELSE
    uWickPct=100
    ENDIF
    uWickOk=uWickPct<=50
    
    resistance=highCons
    closedAboveRes=close>resistance
    
    scanBuy=priceAboveMA AND isCons AND macdBull AND is10high AND pctOk AND volSpike AND uWickOk AND closedAboveRes
    
    SCREENER[scanBuy]
    #252524 quote
    Iván González
    Moderator
    Master

    In ProBuilder, some words such as truerange or macdline are reserved identifiers or simply don’t exist with that exact name.
    That’s why you get syntax errors.
    There’s also a small conceptual mistake: the closing price (close) can never be strictly greater than the highest closing price of the last N periods — it can only be greater or equal.

    minConsWeeks=6
    maP=20
    natrP=14
    natrThresh=8
    minGain=5
    maxGain=20
    volRatio=1.3
    macdFast=12
    macdSlow=26
    macdSig=9
    maxWidthPct=40
    
    ma20=Average[maP](close)
    atr=Average[natrP](tr)//(TrueRange)
    natr=(atr/close)*100
    
    emaF=ExponentialAverage[macdFast](close)
    emaS=ExponentialAverage[macdSlow](close)
    mymacdLine=emaF-emaS
    
    mymacdSignal=ExponentialAverage[macdSig](mymacdLine)
    
    highCons=Highest[minConsWeeks](close)
    lowCons=Lowest[minConsWeeks](close)
    
    IF lowCons<>0 THEN
       consWidth=((highCons-lowCons)/lowCons)*100
    ELSE
       consWidth=0
    ENDIF
    
    isCons=consWidth<=maxWidthPct AND natr<natrThresh
    
    high10=Highest[10](close)
    is10high=close>=high10
    
    IF close[1]<>0 THEN
       pctMove=((close-close[1])/close[1])*100
    ELSE
       pctMove=0
    ENDIF
    
    pctOk=pctMove>=minGain AND pctMove<=maxGain
    
    volSpike=volume>volume[1]*volRatio
    priceAboveMA=close>ma20
    macdBull=mymacdLine>mymacdSignal
    
    cHeight=high-low
    IF cHeight>0 THEN
       IF close>=open THEN
          uWick=high-close
       ELSE
          uWick=high-open
       ENDIF
       uWickPct=(uWick/cHeight)*100
    ELSE
       uWickPct=100
    ENDIF
    uWickOk=uWickPct<=50
    
    resistance=highCons
    closedAboveRes=close>=resistance
    
    scanBuy=priceAboveMA AND isCons AND macdBull AND is10high AND pctOk AND volSpike AND uWickOk AND closedAboveRes
    
    SCREENER[scanBuy]
    steff_bcn and robertogozzi thanked this post
    #252528 quote
    steff_bcn
    Participant
    New

    Iván, thank you for your time, it works now!
    Unfortunately it shows no results. I wonder if I have to wait or there is some requirement too strict and I should change. I’ll have to play around with the criteria.
    If you have any thought on it, would be welcome.

    Again, thanks for the help!

    #252543 quote
    JS
    Participant
    Senior

    Hi,

    It looks like you’re trying to use MultiTimeFrames (MTF), since I see terms like “minConsWeeks”…

    Should certain parts of your screener operate on a different timeframe…?

    steff_bcn thanked this post
    #252547 quote
    steff_bcn
    Participant
    New
    Thanks JS. I don’t think I’m looking for MTF. The minConsWeeks would refer to looking for a 6 week consolidation period. This is be the criteria I’d like to screen for, but if it doesn’t work something can be taken out.
    • Price above 20-week moving average

    • 6+ weeks of consolidation before breakout

    • MACD bullish alignment: MACD line above the signal line

    • Breakout candle:

      Must close above resistance Body > 50% of the candle 10-week high or higher Candle gain between +5% and +20% vs previous week’s close. Volume spike ≥ +30% vs previous week NATR < 8
    #252550 quote
    JS
    Participant
    Senior
    Hi, I’ve checked all the conditions, and in principle, the issue isn’t with the conditions themselves… The problem is the number of conditions that have to be true at the same time — that combination almost never occurs… In the 100 weeks I checked, it didn’t happen even once…
    #252560 quote
    steff_bcn
    Participant
    New
    I’ll check what I can loosen. Thanks a lot for the help!
    JS thanked this post
    #252561 quote
    steff_bcn
    Participant
    New
    I tried to simplify and use the code Iván suggested, but get another Syntax error (mymacdsignal not used). Would you kindly have another look at it?
    minConsWeeks=6
    maP=20
    maxWidthPct=40
    volRatio=1.25
    macdFast=12
    macdSlow=26
    macdSig=9
    
    ma20=Average[maP](close)
    
    emaF=ExponentialAverage[macdFast](close)
    emaS=ExponentialAverage[macdSlow](close)
    mymacdLine=emaF-emaS
    
    mymacdSignal=ExponentialAverage[macdSig](mymacdLine)
    
    highCons=Highest[minConsWeeks](close)
    lowCons=Lowest[minConsWeeks](close)
    IF lowCons<>0 THEN
    consWidth=((highCons-lowCons)/lowCons)*100
    ELSE
    consWidth=0
    ENDIF
    isCons=consWidth<=maxWidthPct
    
    priceAboveMA=close>ma20
    macdBull=macdLine>macdSignal
    
    resistance=highCons
    wasBelowOrAtRes = close[1] <= resistance
    closedAboveRes = close > resistance
    breakoutCandle = wasBelowOrAtRes AND closedAboveRes
    
    volSpike = volume >= volume[1] * volRatio
    
    scanBuy = priceAboveMA AND isCons AND macdBull AND breakoutCandle AND volSpike
    
    SCREENER[scanBuy]
    
    #252562 quote
    JS
    Participant
    Senior

    Hi,

    I made a few adjustments to the code:

    highCons = Highest[minConsWeeks](close[1]) // using Close[1] instead of Close, so the current bar is excluded
    lowCons = Lowest[minConsWeeks](close[1]) // using Close[1] instead of Close, for consistency with highCons
    macdBull = mymacdLine > mymacdSignal // using mymacdLine instead of macdLine (reserved keyword) and mymacdSignal instead of macdSignal (reserved keyword)

    These changes ensure that the calculations don’t include the current bar in the range evaluation and that the MACD comparison uses your custom variables consistently…

    minConsWeeks=6
    maP=20
    maxWidthPct=40
    volRatio=1.25
    macdFast=12
    macdSlow=26
    macdSig=9
    
    ma20=Average[maP](close)
    
    emaF=ExponentialAverage[macdFast](close)
    emaS=ExponentialAverage[macdSlow](close)
    mymacdLine=emaF-emaS
    
    mymacdSignal=ExponentialAverage[macdSig](mymacdLine)
    
    highCons=Highest[minConsWeeks](close[1])
    lowCons=Lowest[minConsWeeks](close[1])
    IF lowCons<>0 THEN
    consWidth=((highCons-lowCons)/lowCons)*100
    ELSE
    consWidth=0
    ENDIF
    isCons=consWidth<=maxWidthPct
    
    priceAboveMA=close>ma20
    macdBull=mymacdLine>mymacdSignal
    
    resistance=highCons
    wasBelowOrAtRes = close[1] <= resistance
    closedAboveRes = close > resistance
    breakoutCandle = wasBelowOrAtRes AND closedAboveRes
    
    volSpike = volume >= volume[1] * volRatio
    
    scanBuy = priceAboveMA AND isCons AND macdBull AND breakoutCandle AND volSpike
    
    Screener[scanBuy]
    steff_bcn and robertogozzi thanked this post
    Scherm­afbeelding-2025-10-13-om-22.04.19.jpg Scherm­afbeelding-2025-10-13-om-22.04.19.jpg
    #252564 quote
    steff_bcn
    Participant
    New
    Works! Appreciate the help a lot!
    JS thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Trying to code a screener but has error


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
steff_bcn @steff_bcn Participant
Summary

This topic contains 9 replies,
has 3 voices, and was last updated by steff_bcn
4 months, 1 week ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 10/12/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...