A trend, momentum and cycle Trading System v3.0 (CSA)

I like this (or any) indicator that looks at trend from multiple perspectives. With all the labels it becomes a bit busy as I'm only interested in the bottom line. For my personal use I modified it to show only the Hold, Buy or Sell Trend Labels while keeping all parameters in place. Time frames can be modified to reflect the chart being used.

Here is the simplified label code:

Code:
#CSA - trend, a momentum and a cycle based indicator for ThinkorSwim V3.2
#
#VERSION
# 2020.02.01 V3.2 [USER=258]@diazlaz[/USER] - Added SWCA - Schaff Wave CrossOver Average
# 2020.01.29 V3.1 [USER=258]@diazlaz[/USER] - Added ADXPaintBarsMode
#                            Integrated Derivative RSI Oscillator
# 2020.01.29 V3.0 [USER=258]@diazlaz[/USER] - Modules Restructured 3.0 Framework
#                            Improved ADX formula for Trend Detection
#                            Integrated HeikinAshiCandles and HeikinAshiCandles MTF
#                            set aggregationPeriod to MTF aggregation (default 5 mins)
#                            Integrated PaintBars MACD Neutral Condition trigger
#                            set enableNeutralMACDPainter to yes (default is no) and
#                            neutral gray will be evaluated by MACD (Dark Red/Green)
#                            Integrated Super Trend w/CCI and ATR
#                            Integrated CCI + TTM squeeze + TTM trend Combo
#                            Set treshold defaults to 7 (7 out of 10), removed scanmode.
#                            Integrated Slim Ribbon.
#                            Integrated DMI and BOP, restructured INPUTS to each module.
#                            threshold increased to 4 by default.
#                            Integrated ADX Trending States and BAR Line
#                            Integrated TTM Trends, modules selection
#                            and added threshold for signals
#                            Integrated FREMA
#                            Labels, Additional Dashboard, Lower Study
#
#
#LINK
#[URL]https://usethinkscript.com/threads/a-trend-momentum-and-cycle-trading-system-v3-0-csa.1596/[/URL]
#
#INSTRUCTION
#Here is how I envision the paintbar working:
#When the supertrend indicator is long that would equal +1, when its short -1.
#When the TMO is green that would equal +1. when its red its -1.
#When the TOP Cycle Trader is above zero that would equal +1, when its below zero -1.
#When all 3 indicators are equal to +1 making +3 total the price bars would paint #green.
#When all 3 indicators are equal to -1 making -3 total the price bars would paint red.
#If the combination of all 3 indicators equals anything else, the price bars would #paint gray meaning all 3 indicators were not in agreement.
#Code modified by Charles Ricks to only show Hold, Buy and Sell Labels while keeping all parameters in place.


declare upper;

#INPUTS
input showLabels = yes;
input PaintBars = no;
input ADXPaintBarsMode = no;
input enableNeutralMACDPainter = no;
input aggregationPeriod = AggregationPeriod.FIVE_MIN;
input threshold = 7;

input displace = 0;



def h = high;
def l = low;
def o = open;
def c = close;
def hl = hl2;

def h1 = high(period = aggregationPeriod);
def l1 = low(period = aggregationPeriod);
def o1 = open(period = aggregationPeriod);
def c1 = close(period = aggregationPeriod);
def hl2 = hl2(period = aggregationPeriod);

def na = Double.NaN;

AddLabel(showLabels, "TrendMomentum", Color.CYAN);

####################################
##### START OF MODULES SECTION #####
####################################

#START OF HA1 - Heikin Ashi Candles Module V1.0
#
#CHANGELOG
# 2020.01.26 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableHA1 = yes; #Heikin Ashi Candles
def HA1_haopen;
def HA1_hahigh;
def HA1_halow;
def HA1_haclose;
def HA1_sState;
def HA1_sBullish;
def HA1_sBearish;
def HA1_sNeutral;

HA1_haopen = CompoundValue(1, (HA1_haopen[1] + HA1_haclose[1]) / 2, (o[1] + c[1]) / 2);
HA1_hahigh = Max(Max(h, HA1_haopen), HA1_haclose[1]);
HA1_halow = Min(Min(l, HA1_haopen), HA1_haclose[1]);
HA1_haclose = (o + h + l + c) / 4;
HA1_sState = if HA1_haclose > HA1_haopen then 100 else -100;
HA1_sBullish = if(enableHA1 and HA1_sState == 100,1,0);
HA1_sBearish = if(enableHA1 and HA1_sState == -100,1,0);
HA1_sNeutral = 0;


#END OF HA1 - Heikin Ashi Candles Module V1.0

#START OF HAMTF - Heikin Ashi Candles MTF Module V1.0
#
#CHANGELOG
# 2020.01.26 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
def HAMTF_haopen;
def HAMTF_hahigh;
def HAMTF_halow;
def HAMTF_haclose;
def HAMTF_sState;
def HAMTF_sBullish;
def HAMTF_sBearish;
def HAMTF_sNeutral;

input enableHAMTF = yes; #Heikin Ashi Candles MTF

HAMTF_haopen = CompoundValue(1, (HAMTF_haopen[1] + HAMTF_haclose[1]) / 2, (o1[1] + c1[1]) / 2);
HAMTF_hahigh = Max(Max(h1, HAMTF_haopen), HAMTF_haclose[1]);
HAMTF_halow = Min(Min(l1, HAMTF_haopen), HAMTF_haclose[1]);
HAMTF_haclose = (o1 + h1 + l1 + c1) / 4;
HAMTF_sState = if HAMTF_haclose > HAMTF_haopen then 100 else -100;
HAMTF_sBullish = if(enableHAMTF and HAMTF_sState == 100,1,0);
HAMTF_sBearish = if(enableHAMTF and HAMTF_sState == -100,1,0);
HAMTF_sNeutral = 0;

#END OF HAMTF - Heikin Ashi Candles MTF Module V1.0

#START OF TTM - TTM Trend Module V1.0
#
#CHANGELOG
# 2020.01.26 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableTTM = yes; #TTM Trend
def TTM_trendup;
def TTM_trenddown;
def TTM_sState;
def TTM_sBullish;
def TTM_sBearish;
def TTM_sNeutral;

TTM_trendup = if TTM_Trend().TrendUp == 1 then 1 else 0;
TTM_trenddown = if TTM_Trend().TrendDown == 1 then 1 else 0;
TTM_sState = if TTM_trendup then 100 else if TTM_trenddown then -100 else 0;
TTM_sBullish = if(enableTTM and TTM_sState == 100,1,0);
TTM_sBearish = if(enableTTM and TTM_sState == -100,1,0);
TTM_sNeutral = 0;

#END OF TTM - TTM Trend Module V1.0


#START OF ST1 - SuperTrend (Mobius) Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableSuperTrend = yes; #ST1 - SuperTrend (Mobius)
input ST1_atrmult = 1.0; #SuperTrend
input ST1_natr = 4; #SuperTrend
input ST1_avgtype = AverageType.HULL; #SuperTrend

def ST1_atr = MovingAverage(ST1_avgtype, TrueRange(h, c, l), ST1_natr);
def ST1_up = hl + (ST1_atrmult * ST1_atr);
def ST1_dn = hl + (-ST1_atrmult * ST1_atr);
def ST1_st = if c < ST1_st[1] then ST1_up else ST1_dn;
def ST1_ssupertrend = if c < ST1_st then -100 else 100;
def ST1_sbullish = enableSuperTrend and ST1_ssupertrend == 100;
def ST1_sbearish = enableSuperTrend and ST1_ssupertrend == -100;
def ST1_sneutral = 0;


#START OF STHA - SuperTrend HA (Mobius) Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableSuperTrendHA = yes; #ST1 - SuperTrend HA (Mobius)
input STHA_atrmult = 1.0; #SuperTrend
input STHA_natr = 4; #SuperTrend
input STHA_avgtype = AverageType.HULL; #SuperTrend

def STHA_atr = MovingAverage(STHA_avgtype, TrueRange(ha1_hahigh, ha1_HAclose, ha1_HAlow), STHA_natr);
def STHA_up = HL + (STHA_atrmult * STHA_atr);
def STHA_dn = HL + (-STHA_atrmult * STHA_atr);
def STHA_st = if c < STHA_st[1] then STHA_up else STHA_dn;
def STHA_ssupertrend = if c < STHA_st then -100 else 100;
def STHA_sbullish = enableSuperTrendHA and STHA_ssupertrend == 100;
def STHA_sbearish = enableSuperTrendHA and STHA_ssupertrend == -100;
def STHA_sneutral = 0;

#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableFrema = yes; #FREMA
input FRE_aa = .1; #FREMA

def FRE_cc;
def FRE_zeroline = 0;
def FRE_re1;
def FRE_re2;
def FRE_re3;
def FRE_re4;
def FRE_re5;
def FRE_re6;
def FRE_re7;
def FRE_re8;
def FRE_ema;
FRE_cc = if FRE_cc[1] == 0 then .9 else 1 – FRE_aa;
FRE_ema = FRE_aa * c + FRE_cc * FRE_ema[1];
FRE_re1 = FRE_cc * FRE_ema + FRE_ema[1];
FRE_re2 = Power(FRE_cc, 2) * FRE_re1 + FRE_re1[1];
FRE_re3 = Power(FRE_cc, 4) * FRE_re2 + FRE_re2[1];
FRE_re4 = Power(FRE_cc, 8) * FRE_re3 + FRE_re3[1];
FRE_re5 = Power(FRE_cc, 16) * FRE_re4 + FRE_re4[1];
FRE_re6 = Power(FRE_cc, 32) * FRE_re5 + FRE_re5[1];
FRE_re7 = Power(FRE_cc, 64) * FRE_re6 + FRE_re6[1];
FRE_re8 = Power(FRE_cc, 128) * FRE_re7 + FRE_re7[1];
def FRE_ema_signal = FRE_ema – FRE_aa * FRE_re8;
def FRE_sfrema = if (FRE_ema_signal > FRE_zeroline) then 100 else -100;
def FRE_sbullish = enableFrema and FRE_sfrema == 100;
def FRE_sbearish = enableFrema and FRE_sfrema == -100;
def FRE_sneutral = 0;



#START OF TMO - TMO Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableTMO = yes; #TMO
input TMO_length = 14; #TMO
input TMO_calclength = 5; #TMO
input TMO_smoothlength = 3; #TMO

def TMO_data = fold i = 0 to TMO_length
        with s
        do s + (if c > getValue(o, i)
                then 1
                else if c < getValue(o, i)
                     then - 1
                     else 0);
def TMO_ema5 = ExpAverage(TMO_data, TMO_calclength);
def TMO_main = ExpAverage(TMO_ema5, TMO_smoothlength);
def TMO_signal = ExpAverage(TMO_main, TMO_smoothlength);
def TMO_smain = if TMO_main > TMO_signal then 100 else -100;
def TMO_ssignal = if TMO_main > TMO_signal then 100 else - 100;
def TMo_Ob = if isNaN(c) then double.nan else round(TMO_length * .7);
def TMo_Os = if isNaN(c) then double.nan else -round(TMO_length * .7);
def TMO_stmo = if TMO_main > TMO_signal then 100 else -100;
def TMO_sbullish = enableTMO and TMO_stmo == 100;
def TMO_sbearish = enableTMO and TMO_stmo == -100;
def TMO_sneutral = 0;


#END OF TMO - TMO Module V1.0


#START OF SL1 - SLIM Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableSLIM = yes;
input SL1_ssuperfast = 8;
input SL1_sfast = 13;
input SL1_sslow = 21;

def SL1_superfast = ExpAverage(c[-displace], SL1_ssuperfast);
def SL1_fast = ExpAverage(c[-displace], SL1_sfast);
def SL1_slow = ExpAverage(c[-displace], SL1_sslow);
def SL1_buy = SL1_superfast > SL1_fast and SL1_fast > SL1_slow and l > SL1_superfast;
def SL1_stopbuy = SL1_superfast <= SL1_fast;
def SL1_buynow = !SL1_buy[1] and SL1_buy;
def SL1_buysignal = CompoundValue(1, if SL1_buynow and !SL1_stopbuy then 1
else if SL1_buysignal[1] == 1 and SL1_stopbuy then 0 else SL1_buysignal[1], 0);
def SL1_buy_signal = SL1_buysignal[1] == 0 and SL1_buysignal == 1;
def SL1_momentum_down = SL1_buysignal[1] == 1 and SL1_buysignal == 0;
def SL1_sell = SL1_superfast < SL1_fast and SL1_fast < SL1_slow and h < SL1_superfast;
def SL1_stopsell = SL1_superfast >= SL1_fast;
def SL1_sellnow = !SL1_sell[1] and SL1_sell;
def SL1_sellsignal = CompoundValue(1, if SL1_sellnow and !SL1_stopsell then 1
else if SL1_sellsignal[1] == 1 and SL1_stopsell then 0 else SL1_sellsignal[1], 0);
def SL1_sell_signal = SL1_sellsignal[1] == 0 and SL1_sellsignal;
def SL1_momentum_up = SL1_sellsignal[1] == 1 and SL1_sellsignal == 0;
def SL1_sstate = if SL1_buy_signal then 100 else if SL1_momentum_up then 10 else if SL1_sell_signal then -100 else if SL1_momentum_down then -10 else SL1_sstate[1];
def SL1_sbullish = enableSLIM and SL1_sstate == 100;
def SL1_sbearish = enableSLIM and SL1_sstate == -100;
def SL1_sneutral = 0;


#START OF TOP - TOP Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableTOP = yes; #TOP
input TOP_fastcyclelength = 5; #TOP
input TOP_slowcyclelength = 8; #TOP

def TOP_fastvar = ExpAverage((H + L) / 2, TOP_fastcyclelength);
def TOP_slowvar = Average((H + L) / 2, TOP_slowcyclelength);
def TOP_diffvar = TOP_fastvar - TOP_slowvar;
def TOP_pdiffvar = TOP_diffvar;
def TOP_pdiffvar2 = TOP_diffvar;
def TOP_stop = if TOP_diffvar > 0 then 100 else -100;
def TOP_sbullish = enableTOP and TOP_stop == 100;
def TOP_sbearish = enableTOP and TOP_stop == -100;
def TOP_sneutral = 0;



#START OF DMI - DMI Trend Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableDMI = yes; #DMI Trend
input DMI_dmilength = 13;

def DMI_hidiff = h - h[1];
def DMI_lodiff = l[1] - l;
def DMI_plusdm = if DMI_hidiff > DMI_lodiff and DMI_hidiff > 0 then DMI_hidiff else 0;
def DMI_minusdm =  if DMI_lodiff > DMI_hidiff and DMI_lodiff > 0 then DMI_lodiff else 0;
def DMI_atrdmi = WildersAverage(TrueRange(h, c, l), DMI_dmilength);
Def DMI_diplus = 100 * WildersAverage(DMI_plusdm, DMI_dmilength) / DMI_atrdmi;
Def DMI_diminus = 100 * WildersAverage(DMI_minusdm, DMI_dmilength) / DMI_atrdmi;
def DMI_sdmi = if DMI_diplus > DMI_diminus then 100 else if DMI_diminus > DMI_diplus then -100 else 0;
def DMI_sbullish = enableDMI and DMI_sdmi == 100;
def DMI_sbearish = enableDMI and DMI_sdmi == -100;
def DMI_sneutral = 0;


#START OF BOP - BOP Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableBOP = yes; #BOP
input BOP_averagetype = {Simple, Exponential, default Weighted, Wilders, Hull,  Disabled};
input BOP_boplength = 16;

def BOP_rawbmp = if h != l then (c - o) / (h - l) else 1;
def BMP;
switch (BOP_averagetype) {
case Simple:
BMP = Average(BOP_rawbmp, BOP_boplength);
case Exponential:
BMP = ExpAverage(BOP_rawbmp, BOP_boplength);
case Weighted:
BMP = wma(BOP_rawbmp, BOP_boplength);
case Wilders:
BMP = WildersAverage(BOP_rawbmp, BOP_boplength);
case Hull:
BMP = HullMovingAvg(BOP_rawbmp, BOP_boplength);
case Disabled:
BMP = BOP_rawbmp;
}
def BOP_sbop = if BMP > 0 then 100 else -100;
def BOP_sbullish = enableBOP and BOP_sbop == 100;
def BOP_sbearish = enableBOP and BOP_sbop == -100;
def BOP_sneutral = 0;


#START OF STCCI - Super Trend w/CCI Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableSuperTrendCCI = yes; #Super Trend w/CCI
input STCCI_lengthcci = 50;
input STCCI_lengthatr = 21;
input STCCI_atrfactor = 1.0;
def STCCI_pricedata = hl;
def STCCI_atrcci = Average(TrueRange(h, c, l), STCCI_lengthatr) * STCCI_atrfactor;
def STCCI_price = c + l + h;
def STCCI_lindev = lindev(STCCI_price, STCCI_lengthcci);
def STCCI_cci = if STCCI_lindev == 0
       then 0
       else (STCCI_price - Average(STCCI_price, STCCI_lengthcci)) / STCCI_lindev / 0.015;
def STCCI_mt1 = if STCCI_cci > 0
       then Max(STCCI_mt1[1], STCCI_pricedata - STCCI_atrcci)
       else Min(STCCI_mt1[1], STCCI_pricedata + STCCI_atrcci);
def STCCI_ssupertrendcci = if c < STCCI_mt1 and c < ST1_st then -100 else if C > STCCI_mt1 and c > ST1_st then 100 else 0;
def STCCI_sbullish = enableSuperTrendCCI and STCCI_ssupertrendcci == 100;
def STCCI_sbearish = enableSuperTrendCCI and STCCI_ssupertrendcci == -100;
def STCCI_sneutral = 0;


#START OF CTT - CCI + TTM squeeze + TTM trend Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableCCITTM = yes; #CCI + TTM squeeze + TTM trend
def CTT_ccibuy = CCI(length = 14).CCI > 0 and CCI(length = 50).CCI > 0;
def CTT_ccisell = CCI(length = 14).CCI < 0 and CCI(length = 50).CCI < 0;
def CTT_strendup = TTM_Trend().TrendUp;
def CTT_strenddn = TTM_Trend().TrendDown;
def CTT_squeezeup = TTM_Squeeze().Histogram >= 0;
def CTT_squeezedn = TTM_Squeeze().Histogram <= 0;
def CTT_buy = CTT_ccibuy and CTT_strendup and CTT_squeezeup;
def CTT_sell = CTT_ccisell and CTT_strenddn and CTT_squeezedn;
def CTT_sccittm = if CTT_buy then 100 else if CTT_sell then -100 else 0;
def CTT_sbullish = enableCCITTM and CTT_sccittm == 100;
def CTT_sbearish = enableCCITTM and CTT_sccittm == -100;
def CTT_sneutral = 0;


#START OF DRSI - Derivative RSI Oscillator Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
# Derivative RSI Oscillator
# Can be used alone as a smoother RSI or as part of the Carting Wealth strategy when
# combined with the MACD and MAs Charting Wealth study.
# By Horserider 12/25/2019

#USAGE
#
#Derivative RSI Oscillator
input enableDRSI = yes; #Derivative RSI Oscillator
input DRSI_length = 14;
input DRSI_length1 = 5;
input DRSI_length2 = 3;
input DRSI_length3 = 9;
input DRSI_price = close;
input DRSI_averagetype = averagetype.EXPONENTIAL;
input DRSI_averagetype2 = averagetype.SIMPLE;

def DRSI_netchgavg = WildersAverage(DRSI_price - DRSI_price[1], DRSI_length);
def DRSI_totchgavg = WildersAverage(AbsValue(DRSI_price - DRSI_price[1]), DRSI_length);
def DRSI_chgratio = if DRSI_totchgavg != 0 then DRSI_netchgavg / DRSI_totchgavg else 0;

def DRSI_rsi = (50 * (DRSI_chgratio + 1) - 50);

def DRSI_x = MovingAverage(DRSI_averagetype,DRSI_rsi, DRSI_length1);
def DRSI_x2 = MovingAverage(DRSI_averagetype, DRSI_x, DRSI_length2);
def DRSI_xs = MovingAverage(DRSI_averagetype2, DRSI_x2 , DRSI_length3);
def DRSI_rsi__linediff = DRSI_x2 - DRSI_xs;
def DRSI_rsi_line = DRSI_rsi__linediff;
def DRSI_sstate = if DRSI_rsi_line >= 0 then if DRSI_rsi_line > DRSI_rsi_line[1] then 100 else 10 else if DRSI_rsi_line < DRSI_rsi_line[1] then -100 else -10;
def DRSI_sbullish = enableDRSI and DRSI_sstate > 0;
def DRSI_sbearish = enableDRSI and DRSI_sstate < 0;
def DRSI_sneutral = 0;


#START OF SWCA - Schaff Wave CrossOver Average Module V1.0
#
#CHANGELOG
# 2020.02.01 V1.0 [USER=258]@diazlaz[/USER] Initial Module Release
#
#CREDITS
#
#USAGE
#
input enableSWCA = yes;

input SWCA_fastlengthtrend = 48;
input SWCA_slowlengthtrend = 104;
input SWCA_kperiodtrend = 36;
input SWCA_dperiodtrend = 8;
input SWCA_averagetypetrend = AverageType.EXPONENTIAL;
input SWCA_fastlengthwave = 12;
input SWCA_slowlengthwave = 26;
input SWCA_kperiodwave = 9;
input SWCA_dperiodwave = 2;
input SWCA_averagetypewave = AverageType.EXPONENTIAL;

def SWCA_macdtrend = MovingAverage(SWCA_averagetypetrend, c, SWCA_fastlengthtrend) - MovingAverage(SWCA_averagetypetrend, c, SWCA_slowlengthtrend);
def SWCA_macdwave = MovingAverage(SWCA_averagetypewave, c, SWCA_fastlengthwave) - MovingAverage(SWCA_averagetypewave, c, SWCA_slowlengthwave);
def SWCA_fastk1trend = FastKCustom(SWCA_macdtrend, SWCA_kperiodtrend);
def SWCA_fastk1wave = FastKCustom(SWCA_macdwave, SWCA_kperiodwave);
def SWCA_fastd1trend = MovingAverage(SWCA_averagetypetrend, SWCA_fastk1trend, SWCA_dperiodtrend);
def SWCA_fastd1wave = MovingAverage(SWCA_averagetypewave, SWCA_fastk1wave, SWCA_dperiodwave);
def SWCA_fastk2trend = FastKCustom(SWCA_fastd1trend, SWCA_kperiodtrend);
def SWCA_fastk2wave = FastKCustom(SWCA_fastd1wave, SWCA_kperiodwave);
def SWCA_stctrend = MovingAverage(SWCA_averagetypetrend, SWCA_fastk2trend, SWCA_dperiodtrend);
def SWCA_stcwave = MovingAverage(SWCA_averagetypewave, SWCA_fastk2wave, SWCA_dperiodwave);

def SWCA_sstate = if SWCA_stctrend > SWCA_stcwave then 100 else -100;
def SWCA_sbullish = enableSWCA and SWCA_sstate == 100;
def SWCA_sbearish = enableSWCA and SWCA_sstate == -100;
def SWCA_sneutral = 0;


###################################
#####  END OF MODULES SECTION #####
###################################

#ADX TRENDING
input ADXlength = 8; #ADX
input ADXTrending = 25; #ADX
input showADXBar = yes;
input DI_length = 8;

def DX = if (diplus(di_length) + diminus(di_length) > 0) then 100 * AbsValue(diplus(di_length) - diminus(di_length)) / (diplus(di_length) + diminus(di_length)) else 0;
def ADX = WildersAverage(DX, adxlength);

plot ADXCross = LowestAll(low);


#MACD Neutal Eval
input fastLength_1 = 12;
input slowLength_1 = 26;
input MACDLength_1 = 9;
input AverageType_1 = {SMA, default EMA};
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
def MACD_trig = if MACD().value > MACD().avg then 1 else 0;


#STATE
def sResults = HA1_sState + HAMTF_sState + TTM_sState + ST1_ssupertrend + STHA_ssupertrend + FRE_sfrema + TMO_stmo + SL1_sstate + TOP_stop + DMI_sdmi + BOP_sbop
+ STCCI_ssupertrendcci + CTT_sccittm + DRSI_sstate + SWCA_sstate;

def sBullish = HA1_sBullish + HAMTF_sBullish + TTM_sBullish + ST1_sbullish + STHA_sbullish + FRE_sbullish + TMO_sbullish + SL1_sbullish + TOP_sbullish + DMI_sbullish + BOP_sbullish + STCCI_sbullish + CTT_sbullish + DRSI_sbullish + SWCA_sbullish;

def sBearish = HA1_sBearish + HAMTF_sBearish + TTM_sBearish + ST1_sbearish + STHA_sbearish + FRE_sbearish + TMO_sbearish + SL1_sbearish + TOP_sbearish + DMI_sbearish + BOP_sbearish + STCCI_sbearish + CTT_sbearish + DRSI_sbearish + SWCA_sbearish;

def bullish = if(sBullish >= threshold,1,0);
def bearish = if(sBearish >= threshold,1,0);
def sState = if bullish then 100 else if bearish then -100 else 0;
def sState2 = if sState != 0 then sState else sState2[1];


AddLabel(showlabels,
if bullish[-displace] then "LONG" else
if bearish[-displace] then "SHORT"
else "HOLD",
if IsNan(c) then COLOR.Yellow else
if bullish[-displace] then COLOR.GREEN else
if bearish[-displace] then COLOR.RED
else COLOR.Yellow);

#END OF CSA - trend, a momentum and a cycle based indicator for ThinkorSwim V3.2
 
Last edited by a moderator:
Latest Scan Code (based on older V1.7 Release)

Ruby:
# Trend v1.7 Bullish Scan
# tomsk
# 1.4.2020

# tomsk: Here is a bullish scan of the Trend V1.7 study, based on the study that @diazlaz posted
# If you'd like to configure this as a bearish scan, just replace the plot statement with
#
# plot scan = sBearish >= threshold;
#
#
#trend, a momentum and a cycle based indicator for ThinkorSwim V1.7
#@hockeycoachdoug Community Request
#
# https://usethinkscript.com/threads/i-request-combining-3-indicators-into-1-paintbar-study.1390/page-3#post-13087
#
#VERSION
# 2020.01.04 V1.7 @diazlaz - Integrated Slim Ribbon.
# 2020.01.02 V1.6 @diazlaz - Integrated DMI and BOP, restructured INPUTS to each module.
#                            threshold increased to 4 by default.
# 2020.01.01 V1.5 @diazlaz - Integrated ADX Trending States and BAR Line
# 2020.01.01 V1.4 @diazlaz - Integrated TTM Trends, modules selection
#                            and added threshold for signals
# 2019.12.31 V1.2 @diazlaz - Integrated FREMA
# 2019.12.30 V1.1 @diazlaz - Labels, Additional Dashboard, Lower Study
# 2019.12.30 V1.0 @diazlaz - Community Ask/Release

input threshold = 8;

input enableTTM = yes;
input enableSuperTrend = yes;
input enableFrema = yes;
input enableTMO = yes;
input enableSlim = yes;
input enableTOP = yes;
input enableDMI = yes;
input enableBOP = yes;

input displace = 0;

def h = high;
def l = low;
def o = open;
def c = close;

# TTM Trend
def TrendUp = if TTM_Trend().TrendUp == 1 then 1 else 0;
def TrendDown = if TTM_Trend().TrendDown == 1 then 1 else 0;
def sBullish_TTM = enableTTM and TrendUp;
def sBearish_TTM = enableTTM and TrendDown;

# SuperTrend (Mobius)
input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;

def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
def sBullish_SuperTrend = enableSuperTrend and close >= ST;
def sBearish_SuperTrend = enableSuperTrend and close < ST;

# FREMA
input AA = .1;

def CC = if CC[1] == 0 then .9 else 1 – AA;
def EMA = AA * close + CC * EMA[1];
def RE1 = CC * EMA + EMA[1];
def RE2 = Power(CC, 2) * RE1 + RE1[1];
def RE3 = Power(CC, 4) * RE2 + RE2[1];
def RE4 = Power(CC, 8) * RE3 + RE3[1];
def RE5 = Power(CC, 16) * RE4 + RE4[1];
def RE6 = Power(CC, 32) * RE5 + RE5[1];
def RE7 = Power(CC, 64) * RE6 + RE6[1];
def RE8 = Power(CC, 128) * RE7 + RE7[1];
def EMA_Signal = EMA – AA * RE8;
def sBullish_Frema = enableFrema and EMA_Signal > 0;
def sBearish_Frema = enableFrema and EMA_Signal <= 0;

# TMO
input length = 14;
input calcLength = 5;
input smoothLength = 3;

def data = fold i = 0 to length
           with s
           do s + (if c > getValue(o, i)
                   then 1
                   else if c < getValue(o, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
def sBullish_TMO = enableTMO and Main > Signal;
def sBearish_TMO = enableTMO and Main <= Signal;

# SLIM
input sSuperFast = 8;
input sFast = 13;
input sSlow = 21;

def SuperFastM1 = ExpAverage(close[-displace], sSuperFast);
def FastM1 = ExpAverage(close[-displace], sFast);
def SlowM1 = ExpAverage(close[-displace], sSlow);
def buyM1 = SuperFastM1 > FastM1 and FastM1 > SlowM1 and low > SuperFastM1;
def stopbuyM1 = SuperFastM1 <= FastM1;
def buynowM1 = buyM1 and !buyM1[1];
def buysignalM1 = if buynowM1 and !stopbuyM1 then 1
                  else if buysignalM1[1] and stopbuyM1 then 0
                  else buysignalM1[1];
def Buy_SignalM1 = buysignalM1 and !buysignalM1[1];
def sellM1 = SuperFastM1 < FastM1 and FastM1 < SlowM1 and high < SuperFastM1;
def stopsellM1 = SuperFastM1 >= FastM1;
def sellnowM1 = sellM1 and !SellM1[1];
def sellsignalM1 = if sellnowM1 and !stopsellM1 then 1
                   else if sellsignalM1[1] and stopsellM1 then 0
                   else sellsignalM1[1];
def Sell_SignalM1 = sellsignalM1 and !sellsignalM1[1];
def sBullish_SLIM = enableSLIM and Buy_SignalM1;
def sBearish_SLIM = enableSLIM and Sell_SignalM1;

# TOP Cycle Trader
input FastCycleLength = 5;
input SlowCycleLength = 8;

def FastVar = ExpAverage((H + L) / 2, FastCycleLength);
def SlowVar = Average((H + L) / 2, SlowCycleLength);
def DiffVar = FastVar - SlowVar;
def sBullish_TOP = enableTOP and DiffVar > 0;
def sBearish_TOP = enableTOP and DiffVar <= 0;

# DMITrend
input DMIlength = 13;

def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATRDMI = WildersAverage(TrueRange(high, close, low), DMIlength);
Def DIPlus = 100 * WildersAverage(plusDM, DMIlength) / ATRDMI;
Def DIMinus = 100 * WildersAverage(minusDM, DMIlength) / ATRDMI;
def sBullish_DMI = enableDMI and DIPlus > DIMinus;
def sBearish_DMI = enableDMI and DIMinus > DIPlus;

# BOP indicator
input averageType = {Simple, Exponential, default Weighted, Wilders, Hull,  Disabled};
input BoPlength = 16;

def rawBMP = if high != low then (close - open) / (high - low) else 1;
def BMP;
switch (averageType) {
case Simple:
    BMP = Average(rawBMP, BoPlength);
case Exponential:
    BMP = ExpAverage(rawBMP, BoPlength);
case Weighted:
    BMP = wma(rawBMP, BoPlength);
case Wilders:
    BMP = WildersAverage(rawBMP, BoPlength);
case Hull:
    BMP = HullMovingAvg(rawBMP, BoPlength);
case Disabled:
    BMP = rawBMP;
}
def sBullish_BOP = enableBOP and BMP > 0;
def sBearish_BOP = enableBOP and BMP <= 0;

# SCAN

def sBullish = sBullish_TTM + sBullish_SuperTrend + sBullish_Frema + sBullish_TMO + sBullish_TOP + sBullish_DMI + sBullish_BOP + sBullish_SLIM;
def sBearish = sBearish_TTM + sBearish_SuperTrend + sBearish_Frema + sBearish_TMO + sBearish_TOP + sBearish_DMI + sBearish_BOP + sBearish_SLIM;

plot scan = sBullish >= threshold;

# End Trend v1.7 Bullish Scan
I keep getting a script error on this scan
 
I keep getting a script error on this scan
Your post doesn't provide enough information to say where you went astray.

Here is a shared scan link: http://tos.mx/Y9MGrZS Click here for --> Easiest way to load shared links
This has the indicator that you included in your post; already scripted into it.
IFPmX44.png
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
449 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top