From indicator to screener – screener misses stocks
Forums › ProRealTime English forum › ProScreener support › From indicator to screener – screener misses stocks
- This topic has 11 replies, 2 voices, and was last updated 3 years ago by robertogozzi.
-
-
07/30/2021 at 9:26 AM #174370
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110//Pivot calculation methodOnce mode = 1Once dailyPivot = 1Once lastWeekBarIndex = 1Once weeklyHigh = undefinedOnce weeklyLow = undefinedOnce weeklyPivot = undefinedOnce lastMonthBarIndex = 1Once monthlyHigh = undefinedOnce monthlyLow = undefinedOnce monthlyPivot = undefinedIf Day>Day[1] thenIf mode = 1 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3Elsif mode = 1 thendailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4Elsif mode = 2 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4ElsedailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4EndifEndifIf DayOfWeek<DayOfWeek[1] thenweeklyHigh = Highest[max(1,BarIndex - lastWeekBarIndex)](High)[1]weeklyLow = Lowest[max(1,BarIndex - lastWeekBarIndex)](Low)[1]lastWeekBarIndex = BarIndexIf mode = 1 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3Elsif mode = 1 thenweeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4Elsif mode = 2 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4ElseweeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4EndifEndifIf Month<>Month[1] thenmonthlyHigh = Highest[max(1,BarIndex - lastMonthBarIndex)](High)[1]monthlyLow = Lowest[max(1,BarIndex - lastMonthBarIndex)](Low)[1]lastMonthBarIndex = BarIndexIf mode = 1 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3Elsif mode = 1 thenmonthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4Elsif mode = 2 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4ElsemonthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4EndifEndifc1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11C2= close - C1IF c2 > 2 * Averagetruerange ThenRESULT = 10ELSIF LOW<C1 THENRESULT = 0ENDIFIF RESULT[0] > RESULT[1] THENFINALRESULT = CLOSE [0]ENDIFIF FINALRESULT OR RESULT >0 THENSIGNAL = 1ELSIF (LOW<C1) THENSIGNAL = 0ENDIFIF SIGNAL > 0 AND HIGH - FINALRESULT > Averagetruerange * 3 THENFINALSIGNAL = 1ELSIF (LOW<C1) THENFINALSIGNAL = 0ENDIFIf FINALSIGNAL > 0 and c2 > 3 * Averagetruerange thenfinalentrysignal = 1ELSIF (LOW<C1) THENfinalENTRYSIGNAL = 0EndifIf finalentrysignal<finalentrysignal[1] thenlevel=(highest[33](HIGH[1]))elsif finalentrysignal>finalentrysignal[1] or close>level thenlevel=0endifSCREENER[level] ((close/DClose(1)-1)*100 AS "%Chg yest.")107/30/2021 at 10:39 AM #174379Screeners 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:
1Highest[min(254,max(1,BarIndex - lastMonthBarIndex))]Furthermore, ONCE may lead to issues in ProScreener, it’s advisable not to use it. Instead of using
1Once mode = 1use
123IF BarIndex = 0 THENmode = 1ENDIF1 user thanked author for this post.
07/30/2021 at 10:45 AM #17438107/30/2021 at 2:10 PM #174389I 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138//Pivot calculation methodIF BarIndex = 0 THENmode = 1ENDIFIF BarIndex = 0 THENdailypivot = 1ENDIFIF BarIndex = 0 THENlastWeekbarIndex = 1ENDIFIF BarIndex = 0 THENweeklyhigh = undefinedENDIFIF BarIndex = 0 THENweeklylow = undefinedENDIFIF BarIndex = 0 THENweeklypivot = undefinedENDIFIF BarIndex = 0 THENlastmonthbarindex = 1ENDIFIF BarIndex = 0 THENmonthlyhigh = undefinedENDIFIF BarIndex = 0 THENmonthlylow = undefinedENDIFIF BarIndex = 0 THENmonthlypivot = undefinedENDIFIf Day>Day[1] thenIf mode = 1 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3Elsif mode = 1 thendailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4Elsif mode = 2 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4ElsedailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4EndifEndifIf DayOfWeek<DayOfWeek[1] thenweeklyHigh = Highest[min(254,max(1,BarIndex - lastweekBarIndex))]weeklyLow = Lowest[min(254,max(1,BarIndex - lastweekBarIndex))]lastWeekBarIndex = BarIndexIf mode = 1 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3Elsif mode = 1 thenweeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4Elsif mode = 2 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4ElseweeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4EndifEndifIf Month<>Month[1] thenmonthlyHigh = Highest[min(254,max(1,BarIndex - lastMonthBarIndex))]monthlyLow = Lowest[min(254,max(1,BarIndex - lastMonthBarIndex))]lastMonthBarIndex = BarIndexIf mode = 1 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3Elsif mode = 1 thenmonthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4Elsif mode = 2 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4ElsemonthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4EndifEndifc1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11C2= close - C1IF c2 > 2 * Averagetruerange ThenRESULT = 10ELSIF LOW<C1 THENRESULT = 0ENDIFIF RESULT[0] > RESULT[1] THENFINALRESULT = CLOSE [0]ENDIFIF FINALRESULT OR RESULT >0 THENSIGNAL = 1ELSIF (LOW<C1) THENSIGNAL = 0ENDIFIF SIGNAL > 0 AND HIGH - FINALRESULT > Averagetruerange * 3 THENFINALSIGNAL = 1ELSIF (LOW<C1) THENFINALSIGNAL = 0ENDIFIf FINALSIGNAL > 0 and c2 > 3 * Averagetruerange thenfinalentrysignal = 1ELSIF (LOW<C1) THENfinalENTRYSIGNAL = 0EndifIf finalentrysignal<finalentrysignal[1] thenlevel=(highest[33](HIGH[1]))elsif finalentrysignal>finalentrysignal[1] or close>level thenlevel=0endifSCREENER[level] ((close/DClose(1)-1)*100 AS "%Chg yest.")08/03/2021 at 8:11 AM #17459408/03/2021 at 2:25 PM #174606You wrote “The screener is still just finding less than half of the stocks it should“, how many results were returned?
1 user thanked author for this post.
08/03/2021 at 3:43 PM #17461808/03/2021 at 4:57 PM #174623I 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:
123456789101112IF BarIndex = 0 THENmode = 1dailypivot = 1lastWeekbarIndex = 1weeklyhigh = undefinedweeklylow = undefinedweeklypivot = undefinedlastmonthbarindex = 1monthlyhigh = undefinedmonthlylow = undefinedmonthlypivot = undefinedENDIFbut this won’t affect results.
1 user thanked author for this post.
08/03/2021 at 5:13 PM #174624I might have found a glitch.
As you can see from the attached pic, the first IF is1If mode = 0 thennot
1If mode = 1 then1 user thanked author for this post.
08/03/2021 at 10:08 PM #174639Thank 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.
1108/03/2021 at 10:10 PM #174640123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103//Pivot calculation methodIF BarIndex = 0 THENmode = 1dailypivot = 1lastWeekbarIndex = 1weeklyhigh = undefinedweeklylow = undefinedweeklypivot = undefinedlastmonthbarindex = 1monthlyhigh = undefinedmonthlylow = undefinedmonthlypivot = undefinedENDIFIf Day>Day[1] thenIf mode = 0 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3Elsif mode = 1 thendailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4Elsif mode = 2 thendailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4ElsedailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4EndifEndifIf DayOfWeek<DayOfWeek[1] thenweeklyHigh = Highest[min(254,max(1,BarIndex - lastweekBarIndex))]weeklyLow = Lowest[min(254,max(1,BarIndex - lastweekBarIndex))]lastWeekBarIndex = BarIndexIf mode = 0 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3Elsif mode = 1 thenweeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4Elsif mode = 2 thenweeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4ElseweeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4EndifEndifIf Month<>Month[1] thenmonthlyHigh = Highest[min(254,max(1,BarIndex - lastMonthBarIndex))]monthlyLow = Lowest[min(254,max(1,BarIndex - lastMonthBarIndex))]lastMonthBarIndex = BarIndexIf mode = 0 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3Elsif mode = 1 thenmonthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4Elsif mode = 2 thenmonthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4ElsemonthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4EndifEndifc1= (DailyPivot *2 + weeklyPivot *2 + monthlyPivot *2 + average [5] + average [20] + average [50] + average [100] + average [200]) / 11C2= close - C1IF c2 > 2 * Averagetruerange ThenRESULT = 10ELSIF LOW<C1 THENRESULT = 0ENDIFIF RESULT[0] > RESULT[1] THENFINALRESULT = CLOSE [0]ENDIFIF FINALRESULT OR RESULT >0 THENSIGNAL = 1ELSIF (LOW<C1) THENSIGNAL = 0ENDIFIF SIGNAL > 0 AND HIGH - FINALRESULT > Averagetruerange * 3 THENFINALSIGNAL = 1ELSIF (LOW<C1) THENFINALSIGNAL = 0ENDIFIf FINALSIGNAL > 0 and c2 > 3 * Averagetruerange thenfinalentrysignal = 1ELSIF (LOW<C1) THENfinalENTRYSIGNAL = 0EndifIf finalentrysignal<finalentrysignal[1] thenlevel=(highest[33](HIGH[1]))elsif finalentrysignal>finalentrysignal[1] or close>level thenlevel=0endifSCREENER[level] ((close/DClose(1)-1)*100 AS "%Chg yest.")08/04/2021 at 2:26 AM #174645Ok, I see.
We would appreciate it if you would like to share any answers you can get.
Thank you 🙂
-
AuthorPosts
Find exclusive trading pro-tools on