Trend analysis screener help for code
Forums › ProRealTime English forum › ProScreener support › Trend analysis screener help for code
- This topic has 9 replies, 3 voices, and was last updated 7 years ago by Sascha.
-
-
12/07/2016 at 3:57 PM #17942
Hi Nicolas,
I have a different problem which may not be a big thing, but somehow a screener that I created (based on an indicator that I also created which was based partly on your feedback) doesn’t always provide correct results. I just can’t find the reason because the code is actually very simple. Maybe you can take a look at it.First, I can give you the code for the indicator. It’s called “TA” which stands for Trend Analysis and the indicator shows the different types of trends (bull, bear, megaphone, pennant).
Second, I provide the code for the screener. The results should only show those stocks that change from a megaphone to a bull market.
The screener code actually consist of more elements, but I’ll only send one element which already creates false search results. So it should be easier for you to find the mistake. Maybe there is a systematic error the way I created the scanner.When I ran the scan for example on the predefined list “US NASDAQ stocks” today, I get the stock CVLY which should not show up as a result because it’s been in an uptrend for some time.
Code for the TA indicator:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869cbar=Dhigh(0)ybar=Dhigh(1)t1bar=Dhigh(2)t2bar= Dhigh(3)t3bar=Dhigh(4)rig=ybar>cbarlef1=ybar>t1barlef2=ybar>t2barlef3=ybar>t3barif rig AND lef1 AND lef2 AND lef3 theni= 1elsei= 0endifcbor=Dlow(0)ybor=Dlow(1)t1bor=Dlow(2)t2bor= Dlow(3)t3bor=Dlow(4)rog=ybor<cborlof1=ybor<t1borlof2=ybor<t2borlof3=ybor<t3borif rog AND lof1 AND lof2 AND lof3 thenj= -1elsej= 0endifif i=1 thenpreviousswinghigh=lastswinghighlastswinghigh=ybarendifif j=-1 thenpreviousswinglow=lastswinglowlastswinglow=yborendif//Uptrendcondition1=lastswinghigh > previousswinghigh and lastswinglow >= previousswinglow and low[0]>=lastswinglow or lastswinghigh = previousswinghigh and lastswinglow >= previousswinglow and high[0]>lastswinghigh or lastswinghigh < previousswinghigh and lastswinglow > previousswinglow and high[1]>lastswinghigh//Downtrendcondition2=lastswinghigh < previousswinghigh and lastswinglow < previousswinglowif condition2 thenif high[0] > lastswinghigh thencondition2 = condition4endifendif//Pennantcondition3=lastswinghigh <= previousswinghigh and lastswinglow >= previousswinglow and low[0]>=lastswinglow and high[0]<=lastswinghigh//Megaphonecondition4=lastswinghigh > previousswinghigh and lastswinglow < previousswinglow or (lastswinghigh >= previousswinghigh and lastswinglow > previousswinglow and low[0]<lastswinglow) or (lastswinghigh >= previousswinghigh and lastswinglow < previousswinglow) or (lastswinghigh >= previousswinghigh and lastswinglow = previousswinglow and low[0]<lastswinglow) or lastswinghigh < previousswinghigh and lastswinglow > previousswinglow and high[0]>lastswinghigh and low[0]<lastswinglow//Megaphone_broken up trendcondition5=(lastswinghigh > previousswinghigh and lastswinglow > previousswinglow) and (low[0]<lastswinglow)//Megaphone_broken down trendcondition6=(lastswinghigh < previousswinghigh and lastswinglow <= previousswinglow) and (high[0]>lastswinghigh)//Downtrend_broken pennantcondition7=(lastswinghigh < previousswinghigh and lastswinglow >= previousswinglow) and (low[0]<lastswinglow) and high[0]<=lastswinghigh//Uptrend_broken pennantcondition8=(lastswinghigh < previousswinghigh and lastswinglow > previousswinglow) and (high[0]>lastswinghigh) and low[0]>=lastswinglow and (high[1]<lastswinghigh)return condition1 as "bull", condition2 as "bear", condition3 as "pennant", condition4 as "megaphone", condition5 as "megaphone_broken up trend", condition6 as "megaphone_broken down trend", condition7 as "downtrend_broken pennant", condition8 as "uptrend_broken pennant"Code for the Screener:
12345678910indicator1, ignored, ignored, ignored, ignored, ignored, ignored, ignored = CALL TAc1 = (indicator1 = 1)ignored, ignored, ignored, indicator2, ignored, ignored, ignored, ignored = CALL TAc2 = (indicator2[1] = 1)indicator3 = Average[50](close)c3 = (close > indicator3)SCREENER[c1 AND c2 AND c3] ((close/DClose(1)-1)*100 AS "%Chg yest.")I attach a screenshot just to show you how I colour the TA indicator.
Thanks very much for your help.Kind regards,
Sascha12/08/2016 at 10:36 AM #17990I think condition1 (bull) and condition4 (megaphone) may overlap each other, that’s why these 2 conditions are tested true at the same time.
Also, in your screener code, the c1 condition only test if we are in a bull market accordingly to your indicator, not if it were not the case the candlestick before.
This is a quick conclusion while reading the code, not tested I must admit 🙂
12/08/2016 at 5:49 PM #18081This looks interesting, but I met with a few ‘challenges’! 🙂
First off I couldnt copy and paste it directly, even copied 10 rows only bit still wouldn’t paste??
I dumped the Indicator into Outlook (just happened to be open) then copied into PRT and all pasted okay … weird??
Anyway attached is what I get … a horizontal black line only with ‘Indicator on Price’ and vertical lines when ‘Indicator separate from Price’.
Its probably me doing something wrong or not doing something right??
12/08/2016 at 6:21 PM #18085Hi Nicolas,
I made a quick 4 minute video to explain my view but when wanted to upload the file it said that it’s not allowed.
Do you have an email address I can sent it to?
If not, please let me know, then I would describe it in another message.
Thanks.
Sascha
12/08/2016 at 8:24 PM #1809312/08/2016 at 9:13 PM #1809812/09/2016 at 10:13 AM #1813312/09/2016 at 12:02 PM #18153Hi Nicolas,
I don’t know why I didn’t think of that myself. Here is a link to a Google Drive folder where I uploaded the short video.
https://drive.google.com/open?id=0B9k7VdzutxCCdnR1NmJNYTQzOW8
Thanks.
Sascha
12/12/2016 at 5:35 PM #1836901/05/2017 at 7:21 PM #19959 -
AuthorPosts
Find exclusive trading pro-tools on