I am looking to build a scanner that populates which stocks are trading below or above their weekly expected moves.

dfabian007

New member
I am looking to build a scanner that populates which stocks are trading below or above their weekly expected moves. I have a study that plots this for me however when I try to make a custom scanner with that study I get the error message that it is too complex.
 

MerryDay

Administrative
Staff member
Staff
VIP
'Generally' too complex scanner messages means that the study is not scannable. However, 'sometimes', the problem is just too many extraneous statements which are not related to the logic needed for the scan. Removal of the extraneous puts less strain on resources and will then sometimes run successfully.

Another work-around that posters have sometimes had success with is to limit the data pool that you are scanning against. Scanning the Universe of Stocks is never recommended. Scanning a watch list of your preferred equities, scanning the DJIA or NASDAQ 100, or limit on volume, market cap, etc.. Anything that will require considerable less of TD's resources will occasionally get around the too complex error.

However, a majority of the time, the problem is built into the complex logic of the study and then there is no work-around.
 

zamanib

New member
I am looking to build a scanner that populates which stocks are trading below or above their weekly expected moves. I have a study that plots this for me however when I try to make a custom scanner with that study I get the error message that it is too complex.
can you share the code please - and did you fix the error
 

dfabian007

New member
can you share the code please - and did you fix the error
def agg = GetAggregationPeriod();

def err_label = if agg == AggregationPeriod.DAY then
no
else
yes;

input em_skew_percent = 70;
input em_bandwidth = 100;
input touches_percent = 90;

input show_high_bubble = yes;
input show_low_bubble = yes;
input show_high_dots = yes;
input show_low_dots = yes;
input show_touches_high_dots=yes;
input show_touches_low_dots=yes;
input show_touches_daily=yes;

input show_em_calc = yes;
input show_highlow_detail = yes;
input show_highlow_daily = yes;
input show_highlow_daily_inside= yes;

#------------------------------------------------------


def barcount = BarNumber();
def lastbar = HighestAll(if IsNaN(high) then 0 else barcount);

def ivGapHi;
def expmove;
def high_bar;
def low_bar;
def em_close;
def weekcnt;
def touch_high_bar;
def touch_low_bar;

#---------------------------------------------------

if GetDayOfWeek(GetYYYYMMDD()) == 1 or (getdayofweek(getYYYYMMDD()[1]) == 5 and getdayofweek(getyyyymmdd()) == 2)
then {

ivGapHi = imp_volatility()[1];

expmove = close[1] * ivGapHi * Sqrt(6) / Sqrt(365) * em_skew_percent / 100 * em_bandwidth / 100;

high_bar = close[1] + expmove;
touch_high_bar = close[1] + (expmove * touches_percent/100);
low_bar = close[1] - expmove;
touch_low_bar = close[1] - (expmove * touches_percent/100);
em_close = close[1];
weekcnt=weekcnt[1] + 1;

}
else {
ivGapHi = ivGapHi[1];
expmove = expmove[1];
high_bar = high_bar[1];
touch_high_bar = touch_high_bar[1];
low_bar = low_bar[1];
touch_low_bar= touch_low_bar[1];
em_close = em_close[1];
weekcnt = weekcnt[1];

}

#
# calculations for over EM
#

def peak = if high_bar > 1 and close > high_bar then 1 else 0;

def peakcnt = if peak then peakcnt[1] + 1 else peakcnt[1];
def peakamt = if peak then peakamt[1] + close - high_bar else peakamt[1];

#################### daily bar logic -- over EM
#
# Continue to monitor Friday's for count.

def fripeak = if high_bar > 1 and close > high_bar and GetDayOfWeek(GetYYYYMMDD()) == 5 then 1 else 0;
def fripeakcnt = if fripeak then fripeakcnt[1] + 1 else fripeakcnt[1];
def fripeakamt = if fripeak then fripeakamt[1] + close - high_bar else fripeakamt[1];

def thupeak = if high_bar > 1 and close > high_bar and GetDayOfWeek(GetYYYYMMDD()) == 4 then 1 else 0;
def thupeakcnt = if thupeak then thupeakcnt[1] + 1 else thupeakcnt[1];
def thupeakamt = if thupeak then thupeakamt[1] + close - high_bar else thupeakamt[1];

def wenpeak = if high_bar > 1 and close > high_bar and GetDayOfWeek(GetYYYYMMDD()) == 3 then 1 else 0;
def wenpeakcnt = if wenpeak then wenpeakcnt[1] + 1 else wenpeakcnt[1];
def wenpeakamt = if wenpeak then wenpeakamt[1] + close - high_bar else wenpeakamt[1];

def tuepeak = if high_bar > 1 and close > high_bar and GetDayOfWeek(GetYYYYMMDD()) == 2 then 1 else 0;
def tuepeakcnt = if tuepeak then tuepeakcnt[1] + 1 else tuepeakcnt[1];
def tuepeakamt = if tuepeak then tuepeakamt[1] + close - high_bar else tuepeakamt[1];

def monpeak = if high_bar > 1 and close > high_bar and GetDayOfWeek(GetYYYYMMDD()) == 1 then 1 else 0;
def monpeakcnt = if monpeak then monpeakcnt[1] + 1 else monpeakcnt[1];
def monpeakamt = if monpeak then monpeakamt[1] + close - high_bar else monpeakamt[1];

#
# calculations for under EM
#

def valley = if low_bar > 1 and close < low_bar then 1 else 0;

def valleycnt = if valley then valleycnt[1] + 1 else valleycnt[1];
def valleyamt = if valley then valleyamt[1] + low_bar - close else valleyamt[1];

#################### daily bar logic -- uner EM
#
# Continue to monitor Friday's for count.

def frivalley = if low_bar > 1 and close < low_bar and GetDayOfWeek(GetYYYYMMDD()) == 5 then 1 else 0;
def frivalleycnt = if frivalley then frivalleycnt[1] + 1 else frivalleycnt[1];
def frivalleyamt = if frivalley then frivalleyamt[1] + low_bar - close else frivalleyamt[1];

def thuvalley = if low_bar > 1 and close < low_bar and GetDayOfWeek(GetYYYYMMDD()) == 4 then 1 else 0;
def thuvalleycnt = if thuvalley then thuvalleycnt[1] + 1 else thuvalleycnt[1];
def thuvalleyamt = if thuvalley then thuvalleyamt[1] + low_bar - close else thuvalleyamt[1];

def wenvalley = if low_bar > 1 and close < low_bar and GetDayOfWeek(GetYYYYMMDD()) == 3 then 1 else 0;
def wenvalleycnt = if wenvalley then wenvalleycnt[1] + 1 else wenvalleycnt[1];
def wenvalleyamt = if wenvalley then wenvalleyamt[1] + low_bar - close else wenvalleyamt[1];

def tuevalley = if low_bar > 1 and close < low_bar and GetDayOfWeek(GetYYYYMMDD()) == 2 then 1 else 0;
def tuevalleycnt = if tuevalley then tuevalleycnt[1] + 1 else tuevalleycnt[1];
def tuevalleyamt = if tuevalley then tuevalleyamt[1] + low_bar - close else tuevalleyamt[1];

def monvalley = if low_bar > 1 and close < low_bar and GetDayOfWeek(GetYYYYMMDD()) == 1 then 1 else 0;
def monvalleycnt = if monvalley then monvalleycnt[1] + 1 else monvalleycnt[1];
def monvalleyamt = if monvalley then monvalleyamt[1] + low_bar - close else monvalleyamt[1];



def touchpeak = if high_bar > 1 and ((high < high_bar and high >= touch_high_bar) or (close < high_bar and close >= touch_high_bar)) then 1 else 0;
def touchpeakcnt = if touchpeak then touchpeakcnt[1] + 1 else touchpeakcnt[1];

def touchvalley = if low_bar > 1 and ((low > low_bar and low <= touch_low_bar) or (close > low_bar and close <= touch_low_bar)) then 1 else 0;
def touchvalleycnt = if touchvalley then touchvalleycnt[1] + 1 else touchvalleycnt[1];



plot spxhigh = if high_bar < 1 then Double.NaN else high_bar;

spxhigh.SetDefaultColor(Color.GREEN);
spxhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
spxhigh.SetLineWeight(2);

plot spxlow = if low_bar < 1 then Double.NaN else low_bar;

spxlow.SetDefaultColor(Color.RED);
spxlow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
spxlow.SetLineWeight(2);

plot spxzero = if em_close < 1 then Double.Nan else em_close;

spxzero.setdefaultcolor(color.black);
spxzero.setpaintingstrategy(paintingstrategy.horizontal);
spxzero.setlineweight(2);
 

Similar threads

Top