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]
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]
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!
JSParticipant
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…?
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
JSParticipant
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…
I’ll check what I can loosen.
Thanks a lot for the help!
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]
JSParticipant
Senior
Hi,
I made a few adjustments to the code:
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]
Works! Appreciate the help a lot!