Trying to code a screener but has error
Forums › ProRealTime English forum › ProScreener support › Trying to code a screener but has error
- This topic has 9 replies, 3 voices, and was last updated 11 hours ago by
steff_bcn.
-
-
10/12/2025 at 9:25 PM #252514
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-emaSIs it something easy to fix?
Would appreciate your help.Thank you!
** Entire proposed code **
Strategy123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263minConsWeeks=6maP=20natrP=14natrThresh=8minGain=5maxGain=20volRatio=1.3macdFast=12macdSlow=26macdSig=9maxWidthPct=40ma20=Average[maP](close)atr=Average[natrP](TrueRange)natr=(atr/close)*100emaF=ExponentialAverage[macdFast](close)emaS=ExponentialAverage[macdSlow](close)macdLine=emaF-emaSmacdSignal=ExponentialAverage[macdSig](macdLine)highCons=Highest[minConsWeeks](close)lowCons=Lowest[minConsWeeks](close)IF lowCons<>0 THENconsWidth=((highCons-lowCons)/lowCons)*100ELSEconsWidth=0ENDIFisCons=consWidth<=maxWidthPct AND natr<natrThreshhigh10=Highest[10](close)is10high=close>=high10IF close[1]<>0 THENpctMove=((close-close[1])/close[1])*100ELSEpctMove=0ENDIFpctOk=pctMove>=minGain AND pctMove<=maxGainvolSpike=volume>volume[1]*volRatiopriceAboveMA=close>ma20macdBull=macdLine>macdSignalcHeight=high-lowIF cHeight>0 THENIF close>=open THENuWick=high-closeELSEuWick=high-openENDIFuWickPct=(uWick/cHeight)*100ELSEuWickPct=100ENDIFuWickOk=uWickPct<=50resistance=highConsclosedAboveRes=close>resistancescanBuy=priceAboveMA AND isCons AND macdBull AND is10high AND pctOk AND volSpike AND uWickOk AND closedAboveResSCREENER[scanBuy]10/13/2025 at 9:01 AM #252524In 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.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667minConsWeeks=6maP=20natrP=14natrThresh=8minGain=5maxGain=20volRatio=1.3macdFast=12macdSlow=26macdSig=9maxWidthPct=40ma20=Average[maP](close)atr=Average[natrP](tr)//(TrueRange)natr=(atr/close)*100emaF=ExponentialAverage[macdFast](close)emaS=ExponentialAverage[macdSlow](close)mymacdLine=emaF-emaSmymacdSignal=ExponentialAverage[macdSig](mymacdLine)highCons=Highest[minConsWeeks](close)lowCons=Lowest[minConsWeeks](close)IF lowCons<>0 THENconsWidth=((highCons-lowCons)/lowCons)*100ELSEconsWidth=0ENDIFisCons=consWidth<=maxWidthPct AND natr<natrThreshhigh10=Highest[10](close)is10high=close>=high10IF close[1]<>0 THENpctMove=((close-close[1])/close[1])*100ELSEpctMove=0ENDIFpctOk=pctMove>=minGain AND pctMove<=maxGainvolSpike=volume>volume[1]*volRatiopriceAboveMA=close>ma20macdBull=mymacdLine>mymacdSignalcHeight=high-lowIF cHeight>0 THENIF close>=open THENuWick=high-closeELSEuWick=high-openENDIFuWickPct=(uWick/cHeight)*100ELSEuWickPct=100ENDIFuWickOk=uWickPct<=50resistance=highConsclosedAboveRes=close>=resistancescanBuy=priceAboveMA AND isCons AND macdBull AND is10high AND pctOk AND volSpike AND uWickOk AND closedAboveResSCREENER[scanBuy]1 user thanked author for this post.
10/13/2025 at 10:38 AM #252528Ivá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!
10/13/2025 at 1:49 PM #25254310/13/2025 at 2:13 PM #252547Thanks 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
10/13/2025 at 3:28 PM #252550Hi,
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…
10/13/2025 at 8:02 PM #25256010/13/2025 at 8:25 PM #252561I 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?2nd try1234567891011121314151617181920212223242526272829303132333435363738minConsWeeks=6maP=20maxWidthPct=40volRatio=1.25macdFast=12macdSlow=26macdSig=9ma20=Average[maP](close)emaF=ExponentialAverage[macdFast](close)emaS=ExponentialAverage[macdSlow](close)mymacdLine=emaF-emaSmymacdSignal=ExponentialAverage[macdSig](mymacdLine)highCons=Highest[minConsWeeks](close)lowCons=Lowest[minConsWeeks](close)IF lowCons<>0 THENconsWidth=((highCons-lowCons)/lowCons)*100ELSEconsWidth=0ENDIFisCons=consWidth<=maxWidthPctpriceAboveMA=close>ma20macdBull=macdLine>macdSignalresistance=highConswasBelowOrAtRes = close[1] <= resistanceclosedAboveRes = close > resistancebreakoutCandle = wasBelowOrAtRes AND closedAboveResvolSpike = volume >= volume[1] * volRatioscanBuy = priceAboveMA AND isCons AND macdBull AND breakoutCandle AND volSpikeSCREENER[scanBuy]10/13/2025 at 9:04 PM #252562Hi,
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…
Second Try1234567891011121314151617181920212223242526272829303132333435363738minConsWeeks=6maP=20maxWidthPct=40volRatio=1.25macdFast=12macdSlow=26macdSig=9ma20=Average[maP](close)emaF=ExponentialAverage[macdFast](close)emaS=ExponentialAverage[macdSlow](close)mymacdLine=emaF-emaSmymacdSignal=ExponentialAverage[macdSig](mymacdLine)highCons=Highest[minConsWeeks](close[1])lowCons=Lowest[minConsWeeks](close[1])IF lowCons<>0 THENconsWidth=((highCons-lowCons)/lowCons)*100ELSEconsWidth=0ENDIFisCons=consWidth<=maxWidthPctpriceAboveMA=close>ma20macdBull=mymacdLine>mymacdSignalresistance=highConswasBelowOrAtRes = close[1] <= resistanceclosedAboveRes = close > resistancebreakoutCandle = wasBelowOrAtRes AND closedAboveResvolSpike = volume >= volume[1] * volRatioscanBuy = priceAboveMA AND isCons AND macdBull AND breakoutCandle AND volSpikeScreener[scanBuy]1 user thanked author for this post.
10/13/2025 at 9:17 PM #252564 -
-
AuthorPosts
Find exclusive trading pro-tools on