I had an idea for an indicator and somehow with the help of reading on this forum and using copy paste I was able to create an indicator that does what I want. I have no previous knowledge of coding.
The indicator identifies a stock that has had a run up without any major pullbacks. When the stock pulls back to an average price the indicator plots a line of the highest high over the the last 33 days. When price takes out that high or when the indicator identifies the start of a new run up the line goes to zero.
Anyway, I guess something is off with how I coded this indicator because I am not able to get pro screener to find all the stocks where this line is plotted. It finds a few of them – but it misses the majority. I would be very grateful if someone could take a look and see what could be wrong that causes the screener to miss so many stocks…
Thank you, Gustav
//Pivot calculation method
Once mode = 1
Once dailyPivot = 1
Once lastWeekBarIndex = 1
Once weeklyHigh = undefined
Once weeklyLow = undefined
Once weeklyPivot = undefined
Once lastMonthBarIndex = 1
Once monthlyHigh = undefined
Once monthlyLow = undefined
Once monthlyPivot = undefined
If Day>Day[1] then
If mode = 1 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
Elsif mode = 1 then
dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
Elsif mode = 2 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
Else
dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
Endif
Endif
If DayOfWeek<DayOfWeek[1] then
weeklyHigh = Highest[max(1,BarIndex - lastWeekBarIndex)](High)[1]
weeklyLow = Lowest[max(1,BarIndex - lastWeekBarIndex)](Low)[1]
lastWeekBarIndex = BarIndex
If mode = 1 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
Elsif mode = 1 then
weeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4
Elsif mode = 2 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4
Else
weeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4
Endif
Endif
If Month<>Month[1] then
monthlyHigh = Highest[max(1,BarIndex - lastMonthBarIndex)](High)[1]
monthlyLow = Lowest[max(1,BarIndex - lastMonthBarIndex)](Low)[1]
lastMonthBarIndex = BarIndex
If mode = 1 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
Elsif mode = 1 then
monthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4
Elsif mode = 2 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4
Else
monthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4
Endif
Endif
c1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11
C2= close - C1
IF c2 > 2 * Averagetruerange Then
RESULT = 10
ELSIF LOW<C1 THEN
RESULT = 0
ENDIF
IF RESULT[0] > RESULT[1] THEN
FINALRESULT = CLOSE [0]
ENDIF
IF FINALRESULT OR RESULT >0 THEN
SIGNAL = 1
ELSIF (LOW<C1) THEN
SIGNAL = 0
ENDIF
IF SIGNAL > 0 AND HIGH - FINALRESULT > Averagetruerange * 3 THEN
FINALSIGNAL = 1
ELSIF (LOW<C1) THEN
FINALSIGNAL = 0
ENDIF
If FINALSIGNAL > 0 and c2 > 3 * Averagetruerange then
finalentrysignal = 1
ELSIF (LOW<C1) THEN
finalENTRYSIGNAL = 0
Endif
If finalentrysignal<finalentrysignal[1] then
level=(highest[33](HIGH[1]))
elsif finalentrysignal>finalentrysignal[1] or close>level then
level=0
endif
SCREENER[level] ((close/DClose(1)-1)*100 AS "%Chg yest.")
Screeners have only 254 bars of data history, so you should check this isn’t the case; when it calculates the HIGHEST and LOWEST I suggest that you use:
Highest[min(254,max(1,BarIndex - lastMonthBarIndex))]
Furthermore, ONCE may lead to issues in ProScreener, it’s advisable not to use it. Instead of using
Once mode = 1
use
IF BarIndex = 0 THEN
mode = 1
ENDIF
Thank you Roberto for the quick response. I will try this!
I tried to change it but I must be doing something wrong because the problem persists. The screener is still just finding less than half of the stocks it should. This is what the code looks like now: Im using prt 11.1
//Pivot calculation method
IF BarIndex = 0 THEN
mode = 1
ENDIF
IF BarIndex = 0 THEN
dailypivot = 1
ENDIF
IF BarIndex = 0 THEN
lastWeekbarIndex = 1
ENDIF
IF BarIndex = 0 THEN
weeklyhigh = undefined
ENDIF
IF BarIndex = 0 THEN
weeklylow = undefined
ENDIF
IF BarIndex = 0 THEN
weeklypivot = undefined
ENDIF
IF BarIndex = 0 THEN
lastmonthbarindex = 1
ENDIF
IF BarIndex = 0 THEN
monthlyhigh = undefined
ENDIF
IF BarIndex = 0 THEN
monthlylow = undefined
ENDIF
IF BarIndex = 0 THEN
monthlypivot = undefined
ENDIF
If Day>Day[1] then
If mode = 1 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
Elsif mode = 1 then
dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
Elsif mode = 2 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
Else
dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
Endif
Endif
If DayOfWeek<DayOfWeek[1] then
weeklyHigh = Highest[min(254,max(1,BarIndex - lastweekBarIndex))]
weeklyLow = Lowest[min(254,max(1,BarIndex - lastweekBarIndex))]
lastWeekBarIndex = BarIndex
If mode = 1 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
Elsif mode = 1 then
weeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4
Elsif mode = 2 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4
Else
weeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4
Endif
Endif
If Month<>Month[1] then
monthlyHigh = Highest[min(254,max(1,BarIndex - lastMonthBarIndex))]
monthlyLow = Lowest[min(254,max(1,BarIndex - lastMonthBarIndex))]
lastMonthBarIndex = BarIndex
If mode = 1 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
Elsif mode = 1 then
monthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4
Elsif mode = 2 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4
Else
monthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4
Endif
Endif
c1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11
C2= close - C1
IF c2 > 2 * Averagetruerange Then
RESULT = 10
ELSIF LOW<C1 THEN
RESULT = 0
ENDIF
IF RESULT[0] > RESULT[1] THEN
FINALRESULT = CLOSE [0]
ENDIF
IF FINALRESULT OR RESULT >0 THEN
SIGNAL = 1
ELSIF (LOW<C1) THEN
SIGNAL = 0
ENDIF
IF SIGNAL > 0 AND HIGH - FINALRESULT > Averagetruerange * 3 THEN
FINALSIGNAL = 1
ELSIF (LOW<C1) THEN
FINALSIGNAL = 0
ENDIF
If FINALSIGNAL > 0 and c2 > 3 * Averagetruerange then
finalentrysignal = 1
ELSIF (LOW<C1) THEN
finalENTRYSIGNAL = 0
Endif
If finalentrysignal<finalentrysignal[1] then
level=(highest[33](HIGH[1]))
elsif finalentrysignal>finalentrysignal[1] or close>level then
level=0
endif
SCREENER[level] ((close/DClose(1)-1)*100 AS "%Chg yest.")
I am still looking for help with this. Is there anyone that can see what I am doing wrong?
You wrote “The screener is still just finding less than half of the stocks it should“, how many results were returned?
If we take DAX30 for example then the screener finds 7 stocks. If I instead search the DAX30 manually with the indicator I find 20 stocks.
Thank you Roberto for taking the time to look at this once more.
I can’t detect any issue. I am returned several signals, but I can’t know how many they should have been.
I suggest that you hit Ctrl+M to ask PRT for assistance.
You may shorten you code by replacing lines 3 to 43 with:
IF BarIndex = 0 THEN
mode = 1
dailypivot = 1
lastWeekbarIndex = 1
weeklyhigh = undefined
weeklylow = undefined
weeklypivot = undefined
lastmonthbarindex = 1
monthlyhigh = undefined
monthlylow = undefined
monthlypivot = undefined
ENDIF
but this won’t affect results.
I might have found a glitch.
As you can see from the attached pic, the first IF is
If mode = 0 then
not
If mode = 1 then
Thank you again Roberto for your improvements to the code. The problem with missing stocks when screening is unfortunately still present. I have contacted PRT-support to see if they can help.
This is what the screener code looks like now.
//Pivot calculation method
IF BarIndex = 0 THEN
mode = 1
dailypivot = 1
lastWeekbarIndex = 1
weeklyhigh = undefined
weeklylow = undefined
weeklypivot = undefined
lastmonthbarindex = 1
monthlyhigh = undefined
monthlylow = undefined
monthlypivot = undefined
ENDIF
If Day>Day[1] then
If mode = 0 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
Elsif mode = 1 then
dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
Elsif mode = 2 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
Else
dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
Endif
Endif
If DayOfWeek<DayOfWeek[1] then
weeklyHigh = Highest[min(254,max(1,BarIndex - lastweekBarIndex))]
weeklyLow = Lowest[min(254,max(1,BarIndex - lastweekBarIndex))]
lastWeekBarIndex = BarIndex
If mode = 0 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
Elsif mode = 1 then
weeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4
Elsif mode = 2 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4
Else
weeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4
Endif
Endif
If Month<>Month[1] then
monthlyHigh = Highest[min(254,max(1,BarIndex - lastMonthBarIndex))]
monthlyLow = Lowest[min(254,max(1,BarIndex - lastMonthBarIndex))]
lastMonthBarIndex = BarIndex
If mode = 0 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
Elsif mode = 1 then
monthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4
Elsif mode = 2 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4
Else
monthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4
Endif
Endif
c1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11
C2= close - C1
IF c2 > 2 * Averagetruerange Then
RESULT = 10
ELSIF LOW<C1 THEN
RESULT = 0
ENDIF
IF RESULT[0] > RESULT[1] THEN
FINALRESULT = CLOSE [0]
ENDIF
IF FINALRESULT OR RESULT >0 THEN
SIGNAL = 1
ELSIF (LOW<C1) THEN
SIGNAL = 0
ENDIF
IF SIGNAL > 0 AND HIGH - FINALRESULT > Averagetruerange * 3 THEN
FINALSIGNAL = 1
ELSIF (LOW<C1) THEN
FINALSIGNAL = 0
ENDIF
If FINALSIGNAL > 0 and c2 > 3 * Averagetruerange then
finalentrysignal = 1
ELSIF (LOW<C1) THEN
finalENTRYSIGNAL = 0
Endif
If finalentrysignal<finalentrysignal[1] then
level=(highest[33](HIGH[1]))
elsif finalentrysignal>finalentrysignal[1] or close>level then
level=0
endif
SCREENER[level] ((close/DClose(1)-1)*100 AS "%Chg yest.")
Ok, I see.
We would appreciate it if you would like to share any answers you can get.
Thank you 🙂