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:
cbar=Dhigh(0)
ybar=Dhigh(1)
t1bar=Dhigh(2)
t2bar= Dhigh(3)
t3bar=Dhigh(4)
rig=ybar>cbar
lef1=ybar>t1bar
lef2=ybar>t2bar
lef3=ybar>t3bar
if rig AND lef1 AND lef2 AND lef3 then
i= 1
else
i= 0
endif
cbor=Dlow(0)
ybor=Dlow(1)
t1bor=Dlow(2)
t2bor= Dlow(3)
t3bor=Dlow(4)
rog=ybor<cbor
lof1=ybor<t1bor
lof2=ybor<t2bor
lof3=ybor<t3bor
if rog AND lof1 AND lof2 AND lof3 then
j= -1
else
j= 0
endif
if i=1 then
previousswinghigh=lastswinghigh
lastswinghigh=ybar
endif
if j=-1 then
previousswinglow=lastswinglow
lastswinglow=ybor
endif
//Uptrend
condition1=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
//Downtrend
condition2=lastswinghigh < previousswinghigh and lastswinglow < previousswinglow
if condition2 then
if high[0] > lastswinghigh then
condition2 = condition4
endif
endif
//Pennant
condition3=lastswinghigh <= previousswinghigh and lastswinglow >= previousswinglow and low[0]>=lastswinglow and high[0]<=lastswinghigh
//Megaphone
condition4=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 trend
condition5=(lastswinghigh > previousswinghigh and lastswinglow > previousswinglow) and (low[0]<lastswinglow)
//Megaphone_broken down trend
condition6=(lastswinghigh < previousswinghigh and lastswinglow <= previousswinglow) and (high[0]>lastswinghigh)
//Downtrend_broken pennant
condition7=(lastswinghigh < previousswinghigh and lastswinglow >= previousswinglow) and (low[0]<lastswinglow) and high[0]<=lastswinghigh
//Uptrend_broken pennant
condition8=(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:
indicator1, ignored, ignored, ignored, ignored, ignored, ignored, ignored = CALL TA
c1 = (indicator1 = 1)
ignored, ignored, ignored, indicator2, ignored, ignored, ignored, ignored = CALL TA
c2 = (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,
Sascha