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

@madeinnyc no its not part of the CSA...here is the script below...you can chose what you want displayed.
Code:
# CustVolumeStudy by 7of9 for BRT

declare lower;

#Inputs

input Show30DayAvg = yes;
input ShowTodayVolume =  yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf30BarAvg = yes;
input ShowSellVolumePercent = yes;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);

# Selling Volume

Plot SellVol = selling;
SellVol.setPaintingStrategy(PaintingStrategy.Histogram);
SellVol.SetDefaultColor(Color.Red);
SellVol.HideTitle();
SellVol.HideBubble();
SellVol.SetLineWeight(5);

# Total Volume

Plot BuyVol =  volume;
BuyVol.setPaintingStrategy(PaintingStrategy.Histogram);
BuyVol.SetDefaultColor(Color.Dark_Green);
BuyVol.HideTitle();
BuyVol.HideBubble();
BuyVol.SetLineWeight(5);

#Volume Data

def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;
def percentOf30Bar = Round((curVolume / avg30Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);

# Labels

AddLabel(Show30DayAvg, "Avg 30 Days: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);

AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );

AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);

AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if percentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

AddLabel(ShowPercentOf30BarAvg, PercentOf30Bar + "%", (if PercentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.WHITE) );

AddLabel(ShowSellVolumePercent, "Cur Bar Sell %: " + SellVolPercent, (if SellVolPercent > 51 then Color.RED else if SellVolPercent < 49 then Color.GREEN else Color.ORANGE));

input length = 50;

plot Vol = volume;
plot VolAvg = Average(volume, length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.AssignValueColor(if close > close[1] then Vol.color("Up") else if close < close[1] then Vol.color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
 
@diazlaz I am going over each indicators one by one in the CSA to find the best possible combination and
I found an issue with FREMA. I have used FREMA before in combination with MACD and FREMA in the CSA plots different than in the MACD I was using it with...Please take a look at the pic below:


Is there a way to fix the FREMA in this CSA to reflect how it plots in the MACD script below? You can clearly see the difference based on the pic and how much faster the FREMA in MACD hits vs in the CSA. BTW: I have set the threshold to 1 and disabled all other indicators to NO to make sure that ONLY one indicator is being tested at a time.

Code:
# MACD with a more Normal Distribution
# Mobius
# V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

# V11.01.2019 - netarchitech added standard TOS Breakout Signals per HighBredCloud request
# V11.01.2019 - netarchitech added Ehlers and Mobius Forward/Reverse EMA per HighBredCloud request

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = no;

# Four Pole Filter
script g{
input length = 4;
input betaDev = 2;
input price = OHLC4;
def c;
def w;
def beta;
def alpha;
def G;
c = price;
w = (2 * Double.Pi / length);
beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
alpha = (-beta + Sqrt(beta * beta + 2 * beta));
G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot Line = G;
}
# Modified MACD
plot Value = g(length = fastLength) - g(length = slowLength);
plot Avg = g(price = Value, length = MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
#Value.SetLineWeight(2);
Avg.SetDefaultColor(GetColor(8));
#Avg.SetLineWeight(2);
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
Signal.AssignValueColor(if Signal > Signal[1]
                        then Color.GREEN
                        else Color.RED);
Signal.SetLineWeight(3);
Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.GRAY);

#addCloud(0, Signal, color.RED, color.GREEN);

EDIT: It appears that the colors in the FREMA in the MACD script that I have posted above is set not based on the ZERO line crossing of FREMA hence the early entry/exit. I am not sure IF there is a way to replicate "Negative and Up" and or "Positive and Down" state in the CSA to reflect those of the FREMA found in the MACD script that I have provided.
 
Last edited:
@diazlaz I also checked Schaff Trend and Wave...it also appears to be off from the stand alone indicator that I am using. I know you mentioned to me before on what to use as the logic to obtain the signals...I used the Shaff Wave crossing over the 10 EMA...I don't see the 10 EMA in the CSA script at all. Personally the Trend Line is a bit useless since there are other indicators in the CSA that work much better...You don't need to incorporate STCTrend or the Polarity from the script below. Just STCWave and AvgExpWave...possibly see what makes the STCWave change colors because that is a great indication of the change in trend direction other than the STCWave crossing the AvgExpWave...


Code:
#STSW = Schaff Trend Line and Schaff Wave Line
#Schaff Trend Line = Used for quick up/down trend declaration
#Schaff Wave Line = Trade Wave in the direction of trend as
#declared by Trend Line.
#Schaff Wave Line can be used alone to enter trend
#declared by the MACD.
#Schaff Wave can be used with the EMA for signals

declare lower;

input fastLengthTrend = 48;
input slowLengthTrend = 104;
input KPeriodTrend = 36;
input DPeriodTrend = 8;
input averageTypeTrend = AverageType.EXPONENTIAL;
input fastLengthWave = 12;
input slowLengthWave = 26;
input KPeriodWave = 9;
input DPeriodWave = 2;
input over_bought = 75;
input over_sold = 25;
input averageTypeWave = AverageType.EXPONENTIAL;

def macdTrend = MovingAverage(averageTypeTrend, close, fastLengthTrend) - MovingAverage(averageTypeTrend, close, slowLengthTrend);
def macdWave = MovingAverage(averageTypeWave, close, fastLengthWave) - MovingAverage(averageTypeWave, close, slowLengthWave);
def fastK1Trend = FastKCustom(macdTrend, KPeriodTrend);
def fastK1Wave = FastKCustom(macdWave, KPeriodWave);
def fastD1Trend = MovingAverage(averageTypeTrend, fastK1Trend, DPeriodTrend);
def fastD1Wave = MovingAverage(averageTypeWave, fastK1Wave, DPeriodWave);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriodTrend);
def fastK2Wave = FastKCustom(fastD1Wave, KPeriodWave);
plot STCTrend = MovingAverage(averageTypeTrend, fastK2Trend, DPeriodTrend);
plot STCWave = MovingAverage(averageTypeWave, fastK2Wave, DPeriodWave);
plot OverBought = over_bought;
plot OverSold = over_sold;

STCTrend.SetDefaultColor(GetColor(8));
STCWave.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

plot Fifty_Line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);

STCTrend.DefineColor("Up", GetColor(1));
STCTrend.DefineColor("Down", GetColor(0));
STCTrend.AssignValueColor(if STCTrend > STCTrend[1] then STCTrend.Color("Up") else STCTrend.Color("Down"));
STCWave.DefineColor("Up", GetColor(1));
STCWave.DefineColor("Down", GetColor(0));
STCWave.AssignValueColor(if STCWave > STCWave[1] then STCWave.Color("Up") else STCWave.Color("Down"));

input lengthWave = 10;
plot AvgExpWave = ExpAverage(STCWave, lengthWave);
AvgExpWave.SetDefaultColor(GetColor(1));
#
# Polarity

# v0.01

# 6.2.19

# Nube 

#hint: This study calculates a CCI from an average of high and low pivot prices then uses that CCI and a user defined number of deviations to determine polarity. A cross above +deviations or cross below -devations signals a polarity change

 

# subscript for calculating the mean of pivot prices

script pivotMean{ 

input pivotN = 4;

input stochasticN = 21;

def h = high; 

def l = low;

def norm = (close - Lowest(l, pivotN)) /

(Highest(h, pivotN) - Lowest(l, pivotN));

 

## Pivot High

def hh = if norm crosses above .5

then h

else if h > hh[1]

then h

else hh[1];

def hpBar = if h == hh

then BarNumber() 

else Double.NaN;

def hpPrice = if !IsNaN(hpBar) 

then h 

else hpPrice[1]; 

 

## Pivot Low

def ll = if norm crosses below .5

then l

else if l < ll[1]

then l

else ll[1];

def lpBar = if l == ll 

then BarNumber()

else Double.NaN;

def lpPrice = if !IsNaN(lpBar) 

then l 

else lpPrice[1];

 

plot 

pivotMean = Average((hpPrice + lpPrice) / 2, stochasticN);

}

 

# Inputs

input pivotLength = 4; #hint pivotLength: Number of bars for stochastic pivot calcuation

input meanLength = 21; #hint meanLength: Number of bars to calculate mean

input deviations = 1.0;#hint deviations: Number of deviations from mean to signal a polarity change

 

# Variables

def mean   = pivotMean(pivotLength, meanLength);

def linDev = lindev(close, meanLength);

def cci    = (close - mean) / linDev;

 

def polarity_;

if cci crosses above deviations{

polarity_ = 1;

}else

if cci crosses below -deviations{

polarity_ = -1; 

}else{

polarity_ = polarity_[1];

}

 

# Plots

plot 

Polarity = polarity_;

Polarity.AssignValueColor(if polarity_ > 0 then Color.Green else Color.Red);

 

#declare lower;

 

# f/ Polarity
 
@diazlaz and anyone that is interested...First of all...Thank you @diazlaz for this awesome version of the CSA...

I have done a quick test of each indicator in the CSA and found the following to give the best results. Please see the script below as I have commented out the indicators that I felt were not performing well in the CSA...I left out Schaff Wave on the 3.2 version because I think the logic needs to be fixed...I think, in order for the indicator to function properly. Otherwise the pic on the right is the original 3.2 version just released today...on the left is the commented out version that I found to work the best...I set the threshold to 5 and the time aggregation for MTF HA to 10 min while using the 5 min timeframe. Please judge for yourselves from the pic below.


In conclusion...I find that SuperTrends Tend to give the best results vs single indicators with the exceptions of TMO and TOP...those two indicators performed on par with the various SuperTrends in this CSA...I really think that for the long term trend this CSA is great...Now we just need an exit indicator IMO to confirm with the CSA. Can't wait to test this out live market. Hopefully with everything that I commented out the performance will increase by lowering the lag of such a massive CSA study for those who might have experienced issues in the past.

I still think there are few tweaks and or indicators that can be added and implemented to this CSA to make it more complete...but nonetheless this CSA is awesome! Once again, Big Thanks to @diazlaz for devoting his personal time to getting this done.

Commented out version of the original 3.2 release:

Code:
#CSA - trend, a momentum and a cycle based indicator for ThinkorSwim V3.2
#
#VERSION
# 2020.02.01 V3.2 @diazlaz - Added SWCA - Schaff Wave CrossOver Average
# 2020.01.29 V3.1 @diazlaz - Added ADXPaintBarsMode
#                            Integrated Derivative RSI Oscillator
# 2020.01.29 V3.0 @diazlaz - 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
#https://usethinkscript.com/threads/a-trend-momentum-and-cycle-trading-system-v3-0-csa.1596/
#
#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.
#


declare upper;

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

input displace = 0;

#CORE
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.MAGENTA); #Color.YELLOW
DefineGlobalColor("Off", Color.DARK_GRAY);
DefineGlobalColor("On", Color.GREEN);
DefineGlobalColor("Sync1", Color.YELLOW);
DefineGlobalColor("Sync2", Color.CYAN);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("NUp", Color.DARK_GREEN);
DefineGlobalColor("NDown", Color.DARK_RED);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Neutral2", Color.PLUM);

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, "A trend, momentum and cycle Trading System v3.2", Color.CYAN);

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

#START OF HA1 - Heikin Ashi Candles Module V1.0
#
#CHANGELOG
# 2020.01.26 V1.0 @diazlaz 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;

AddLabel(showlabels and enableHA1, "HA",
if IsNan(HA1_sState) then COLOR.DARK_GRAY else
if HA1_sState[-displace] > 0 then COLOR.GREEN else
if HA1_sState[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#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 @diazlaz 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;
AddLabel(showlabels and enableHAMTF, "HA",
if IsNan(HAMTF_sState) then COLOR.DARK_GRAY else
if HAMTF_sState[-displace] > 0 then COLOR.GREEN else
if HAMTF_sState[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF HAMTF - Heikin Ashi Candles MTF Module V1.0

#START OF TTM - TTM Trend Module V1.0
#
#CHANGELOG
# 2020.01.26 V1.0 @diazlaz 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;
#AddLabel(showlabels and enableTTM, "TTM", if IsNan(TTM_sState) then COLOR.#DARK_GRAY else
#if TTM_sState[-displace] > 0 then COLOR.GREEN else
#if TTM_sState[-displace] < 0 then COLOR.RED
#else COLOR.DARK_GRAY);
#END OF TTM - TTM Trend Module V1.0


#START OF ST1 - SuperTrend (Mobius) Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
AddLabel(showlabels and enableSuperTrend, "SuperTrend", if IsNan(ST1_ssupertrend) then COLOR.DARK_GRAY else
if ST1_ssupertrend[-displace] > 0 then COLOR.GREEN else
if ST1_ssupertrend[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF ST1 - SuperTrend (Mobius) Module V1.0


#START OF STHA - SuperTrend HA (Mobius) Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
AddLabel(showlabels and enableSuperTrend, "SuperTrendHA", if IsNan(STHA_ssupertrend) then COLOR.DARK_GRAY else
if STHA_ssupertrend[-displace] > 0 then COLOR.GREEN else
if STHA_ssupertrend[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF STHA - SuperTrend HA (Mobius) Module V1.0


#START OF FRE - Frema Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;

#AddLabel(showlabels and enableFrema, "Frema", if IsNan(FRE_sfrema) then #COLOR.DARK_GRAY else
#if FRE_sfrema[-displace] > 0 then COLOR.GREEN else
#if FRE_sfrema[-displace] < 0 then COLOR.RED
#else COLOR.DARK_GRAY);
#END OF FRE - Frema Module V1.0


#START OF TMO - TMO Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;

AddLabel(showlabels and enableTMO, "TMO", if IsNan(TMO_stmo) then COLOR.DARK_GRAY else
if TMO_stmo[-displace] > 0 then COLOR.GREEN else
if TMO_stmo[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF TMO - TMO Module V1.0


#START OF SL1 - SLIM Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
#AddLabel(showlabels and enableSLIM, "SLIM", if IsNan(SL1_sstate) then COLOR.DARK_GRAY else
#if SL1_sstate[-displace] >= 100 then COLOR.GREEN else
#if SL1_sstate[-displace] <= -100 then COLOR.RED
#else COLOR.YELLOW);
#END OF SL1 - SLIM Module V1.0


#START OF TOP - TOP Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
AddLabel(showlabels and enableTOP, "TOP", if IsNan(TOP_stop) then COLOR.DARK_GRAY else
if TOP_stop[-displace] > 0 then COLOR.GREEN else
if TOP_stop[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF TOP - TOP Module V1.0


#START OF DMI - DMI Trend Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
AddLabel(showlabels and enableDMI, "DMI", if IsNan(DMI_sdmi) then COLOR.DARK_GRAY else
if DMI_sdmi[-displace] > 0 then COLOR.GREEN else
if DMI_sdmi[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF DMI - DMI Trend Module V1.0


#START OF BOP - BOP Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
#AddLabel(showlabels and enableBOP, "BOP", if IsNan(BOP_sbop) then COLOR.#DARK_GRAY else
#if BOP_sbop[-displace] > 0 then COLOR.GREEN else
#if BOP_sbop[-displace] < 0 then COLOR.RED
#else COLOR.DARK_GRAY);
#END OF BOP - BOP Module V1.0


#START OF STCCI - Super Trend w/CCI Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
AddLabel(showlabels and enableSuperTrendCCI, "SuperTrendCCI", if IsNan(STCCI_ssupertrendcci) then COLOR.DARK_GRAY else
if STCCI_ssupertrendcci[-displace] > 0 then COLOR.GREEN else
if STCCI_ssupertrendcci[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF STCCI - Super Trend w/CCI Module V1.0


#START OF CTT - CCI + TTM squeeze + TTM trend Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
#AddLabel(showlabels and enableCCITTM, "CCI+TTM", if IsNan(CTT_sccittm) then #COLOR.DARK_GRAY else
#if CTT_sccittm[-displace] > 0 then COLOR.GREEN else
#if CTT_sccittm[-displace] < 0 then COLOR.RED
#else COLOR.DARK_GRAY);
#END OF CTT - CCI + TTM squeeze + TTM trend Module V1.0


#START OF DRSI - Derivative RSI Oscillator Module V1.0
#
#CHANGELOG
# 2020.01.29 V1.0 @diazlaz 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;
AddLabel(showlabels and enableDRSI, "DRSI", if IsNan(DRSI_sstate) then COLOR.DARK_GRAY else
if DRSI_sstate[-displace] > 0 then COLOR.GREEN else
if DRSI_sstate[-displace] < 0 then COLOR.RED
else COLOR.DARK_GRAY);
#END OF DRSI - Derivative RSI Oscillator Module V1.0


#START OF SWCA - Schaff Wave CrossOver Average Module V1.0
#
#CHANGELOG
# 2020.02.01 V1.0 @diazlaz 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;
#AddLabel(showlabels and enableSWCA, "SWCA", if IsNan(SWCA_sstate) then COLOR.DARK_GRAY else
#if SWCA_sstate[-displace] > 0 then COLOR.GREEN else
#if SWCA_sstate[-displace] < 0 then COLOR.RED
#else COLOR.DARK_GRAY);
#END OF SWCA - Schaff Wave CrossOver Average Module V1.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);
ADXCross.SetPaintingStrategy(PaintingStrategy.LINE);
ADXCross.AssignValueColor(
    if ADX > ADXTrending then Color.LIME
    else Color.DARK_GRAY);
ADXCross.SetLineWeight(5);
ADXCross.SetHiding(!showADXBar);

#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;

AddLabel(showlabels,
if ADX > ADXTrending then "Trending" else
"Non Trending",
if IsNan(c) then COLOR.DARK_GRAY else
if ADX > ADXTrending then COLOR.GREEN else
COLOR.DARK_GRAY);

AddLabel(showlabels,
"MACD",
if IsNan(c) then COLOR.DARK_GRAY else
if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else
COLOR.DARK_RED);


#STATE
def sResults = HA1_sState + HAMTF_sState + ST1_ssupertrend + STHA_ssupertrend + TMO_stmo + TOP_stop + DMI_sdmi
+ STCCI_ssupertrendcci + DRSI_sstate;

def sBullish = HA1_sBullish + HAMTF_sBullish + ST1_sbullish + STHA_sbullish + TMO_sbullish + TOP_sbullish + DMI_sbullish + STCCI_sbullish + DRSI_sbullish;

def sBearish = HA1_sBearish + HAMTF_sBearish + ST1_sbearish + STHA_sbearish + TMO_sbearish + TOP_sbearish + DMI_sbearish + STCCI_sbearish + DRSI_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];

#COLORBARS
AssignPriceColor(
if PaintBars then
    if ADXPaintBarsMode then if ADX > ADXTrending then COLOR.ORANGE else COLOR.DARK_GRAY
    else
    if bullish then COLOR.GREEN else if bearish then COLOR.RED
     else
     if enableNeutralMACDPainter then
      if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else COLOR.DARK_RED
     else
    COLOR.GRAY
else COLOR.CURRENT);

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

#END OF CSA - trend, a momentum and a cycle based indicator for ThinkorSwim V3.2
 
@diazlaz I will for sure keep you posted here. Other than the Relative Volume I posted above I really don't know of other indicators that might be beneficial to this study. Did you ever add the original Mobius Heikin Ashi SuperTrend that you corrected due to a potential his potential "mistake" that we talked about before? I am curious to see how using just the SuperTrends and HA would alter the results of the CSA...that will be my test next. The threshold will also be adjusted...I am thinking that if I use lets say 8 indicators I should set the threshold to 4? What do you think?

The CSA as of now seems to be a great trend indicator and it works awesome! You've already incorporated a lot of long trending studies that I am using. Now it's just a matter of preference for the end user to build what suits their trading style. You've truly given the end user to fully customize and a CSA to their liking, preference and trading style.

I do, however, want to bring up the possibility of a lower study to serve as an exit indicator to the CSA you made here. I tagged you in a thread that @YungTraderFromMontana started in his Bullish long term indicator thread...you may want to take a look to see what we've discussed.

There I mentioned a possibility of a lower study that serves as an exit indicator to the upper study. It would have to composed of different indicators...more "sensitive/volatile" to show a potential exit before the upper study reflects such a change I would assume...but who knows perhaps some indicators from the upper study could be used as well...not sure.

The indicators that I had in mind include the following: Stochastic RSI, Stochastic Momentum Index, Fisher Transform, Relative Volume, Lazy Bear's version of Ehlers Universal Oscillator...By themselves they are prone to produce fake signals in a choppy market...They do, however, work great in a trending market as with everything else when the market is trending.

I have something like this in mind for the lower study that will serve as an exit indicator to the upper study. Please see the pic below.


While the upper study colors the candlesticks...the lower study can be made into "dots" that when in confluence the 5 indicators or however many are reflected as dots.

Another option is to include the indicators I made to the upper study CSA...but at that point I don't know IF the outcome will change much as the CSA will try to find confluence when painting the candlesticks. I just don't know much about the outcome and I don't want to guess...I think it would be better to separate the long trending indicators from the more sensitive/volatile indicators personally.

Currently I use and MTF version of TMO along with an regular and MTF SuperTrend...Tend Magic and HA as an exit indicator along with the CSA you made..ONLY because I am still testing the CSA and its remarkable how well the CSA works...There are times tho where an exit indicator is needed as I do find the CSA lags...but that is normal.


regular timeframe SuperTrend, Trend Magic and HA is represented on the bottom of the TMO...and the MTF version is above the TMO...

@HighBredCloud do you mind sharing the chart in the image. Also, can you please point us to the lower CSA indicator you are using, I am assuming it posted somewhere in this forum?
 
@HighBredCloud do you mind sharing the chart in the image. Also, can you please point us to the lower CSA indicator you are using, I am assuming it posted somewhere in this forum?
In which image particularly are you referring to for me to share?...The lower CSA was just an example of Mobius MTF SuperTrend that can be found below if that is what you are referring to. This was just an idea I had in mind to make something similar as part of the lower study for this CSA using indicators that would serve as exit indicators to the upper study CSA.

Code:
# SuperTrend Multiple Time Frames
# Mobius with mods by tomsk to replace the script() function for secondary aggs with "standard" code
# V03.01.2016
# 11.4.2019

declare lower;

input agg1 = AggregationPeriod.Five_Min;
input agg2 = AggregationPeriod.Ten_Min;
input agg3 = AggregationPeriod.Fifteen_Min;
input agg4 = AggregationPeriod.Thirty_Min;
input agg5 = AggregationPeriod.Hour;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;

def Fh = FundamentalType.High;
def Fl = FundamentalType.Low;
def Fc = FundamentalType.Close;
def Fhl2 = FundamentalType.HL2;

def cl = close;
def x = isNaN(cl[2]) and !isNaN(cl[3]);
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = hl2 + (AtrMult * ATR);
def DN = hl2 + (-AtrMult * ATR);
def S = if close < S[1]
then Round(UP / tickSize(), 0) * tickSize()
else Round(DN / tickSize(), 0) * tickSize();
def FirstAgg = if close > S then 1 else 0;
plot FirstAggPlot = if isNaN(cl)
then double.nan
else 1;
FirstAggPlot.SetStyle(Curve.Points);
FirstAggPlot.SetLineWeight(3);
FirstAggPlot.AssignValueColor(if FirstAgg == 1
then color.green
else color.red);
AddChartBubble(x, 1, (GetAggregationPeriod()/1000/60) + " min", color.white, yes);

# SecondAgg
def h2 = Fundamental(Fh, period = agg2)[1];
def l2 = Fundamental(Fl, period = agg2)[1];
def c2 = Fundamental(Fc, period = agg2)[1];
def hl2 = Fundamental(Fhl2, period = agg2)[1];
def ATR2 = MovingAverage(AvgType, TrueRange(h2, c2, l2), nATR);
def UP2 = hl2 + (AtrMult * ATR2);
def DN2 = hl2 + (-AtrMult * ATR2);
def S2 = if c2 < S2[1]
then Round(UP2 / tickSize(), 0) * tickSize()
else Round(DN2 / tickSize(), 0) * tickSize();
def SecondAgg = if c2 > S2 then 1 else 0;
plot SecondAggPlot = if isNaN(cl)
then double.nan
else 2;
SecondAggPlot.SetStyle(Curve.Points);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg == 1
then color.green
else color.red);
AddChartBubble(x, 2, (agg2/1000/60) + " min", color.white, yes);

# ThirdAgg
def h3 = Fundamental(Fh, period = agg3)[1];
def l3 = Fundamental(Fl, period = agg3)[1];
def c3 = Fundamental(Fc, period = agg3)[1];
def hl3 = Fundamental(Fhl2, period = agg3)[1];
def ATR3 = MovingAverage(AvgType, TrueRange(h3, c3, l3), nATR);
def UP3 = hl3 + (AtrMult * ATR3);
def DN3 = hl3 + (-AtrMult * ATR3);
def S3 = if c3 < S3[1]
then Round(UP3 / tickSize(), 0) * tickSize()
else Round(DN3 / tickSize(), 0) * tickSize();
def ThirdAgg = if c3 > S3 then 1 else 0;
plot ThirdAggPlot = if isNaN(cl)
then double.nan
else 3;
ThirdAggPlot.SetStyle(Curve.Points);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg == 1
then color.green
else color.red);
AddChartBubble(x, 3, (agg3/1000/60) + " min", color.white, yes);

# FourthAgg
def h4 = Fundamental(Fh, period = agg4)[1];
def l4 = Fundamental(Fl, period = agg4)[1];
def c4 = Fundamental(Fc, period = agg4)[1];
def hl4 = Fundamental(Fhl2, period = agg4)[1];
def ATR4 = MovingAverage(AvgType, TrueRange(h4, c4, l4), nATR);
def UP4 = hl4 + (AtrMult * ATR4);
def DN4 = hl4 + (-AtrMult * ATR4);
def S4 = if c4 < S4[1]
then Round(UP4 / tickSize(), 0) * tickSize()
else Round(DN4 / tickSize(), 0) * tickSize();
def FourthAgg = if c4 > S4 then 1 else 0;
plot FourthAggPlot = if isNaN(cl)
then double.nan
else 4;
FourthAggPlot.SetStyle(Curve.Points);
FourthAggPlot.SetLineWeight(3);
FourthAggPlot.AssignValueColor(if FourthAgg == 1
then color.green
else color.red);
AddChartBubble(x, 4, (agg4/1000/60) + " min", color.white, yes);

# FifthAgg
def h5 = Fundamental(Fh, period = agg5)[1];
def l5 = Fundamental(Fl, period = agg5)[1];
def c5 = Fundamental(Fc, period = agg5)[1];
def hl5 = Fundamental(Fhl2, period = agg5)[1];
def ATR5 = MovingAverage(AvgType, TrueRange(h5, c5, l5), nATR);
def UP5 = hl5 + (AtrMult * ATR5);
def DN5 = hl5 + (-AtrMult * ATR5);
def S5 = if c5 < S5[1]
then Round(UP5 / tickSize(), 0) * tickSize()
else Round(DN5 / tickSize(), 0) * tickSize();
def FifthAgg = if c5 > S5 then 1 else 0;
plot FifthAggPlot = if isNaN(cl)
then double.nan
else 5;
FifthAggPlot.SetStyle(Curve.Points);
FifthAggPlot.SetLineWeight(3);
FifthAggPlot.AssignValueColor(if FifthAgg == 1
then color.green
else color.red);
AddChartBubble(x, 5, (agg5/1000/60)+ " min", color.white, yes);
plot Six = if isNaN(cl)
then double.nan
else 6;
Six.SetStyle(Curve.Points);
Six.SetLineWeight(3);
Six.AssignValueColor(if FirstAgg and
SecondAgg and
ThirdAgg and
FourthAgg and
FifthAgg
then color.green
else if !FirstAgg and
!SecondAgg and
!ThirdAgg and
!FourthAgg and
!FifthAgg
then color.red
else color.black);
# End Code ST MTF
 
@diazlaz I will for sure keep you posted here. Other than the Relative Volume I posted above I really don't know of other indicators that might be beneficial to this study. Did you ever add the original Mobius Heikin Ashi SuperTrend that you corrected due to a potential his potential "mistake" that we talked about before? I am curious to see how using just the SuperTrends and HA would alter the results of the CSA...that will be my test next. The threshold will also be adjusted...I am thinking that if I use lets say 8 indicators I should set the threshold to 4? What do you think?

The CSA as of now seems to be a great trend indicator and it works awesome! You've already incorporated a lot of long trending studies that I am using. Now it's just a matter of preference for the end user to build what suits their trading style. You've truly given the end user to fully customize and a CSA to their liking, preference and trading style.

I do, however, want to bring up the possibility of a lower study to serve as an exit indicator to the CSA you made here. I tagged you in a thread that @YungTraderFromMontana started in his Bullish long term indicator thread...you may want to take a look to see what we've discussed.

There I mentioned a possibility of a lower study that serves as an exit indicator to the upper study. It would have to composed of different indicators...more "sensitive/volatile" to show a potential exit before the upper study reflects such a change I would assume...but who knows perhaps some indicators from the upper study could be used as well...not sure.

The indicators that I had in mind include the following: Stochastic RSI, Stochastic Momentum Index, Fisher Transform, Relative Volume, Lazy Bear's version of Ehlers Universal Oscillator...By themselves they are prone to produce fake signals in a choppy market...They do, however, work great in a trending market as with everything else when the market is trending.

I have something like this in mind for the lower study that will serve as an exit indicator to the upper study. Please see the pic below.


While the upper study colors the candlesticks...the lower study can be made into "dots" that when in confluence the 5 indicators or however many are reflected as dots.

Another option is to include the indicators I made to the upper study CSA...but at that point I don't know IF the outcome will change much as the CSA will try to find confluence when painting the candlesticks. I just don't know much about the outcome and I don't want to guess...I think it would be better to separate the long trending indicators from the more sensitive/volatile indicators personally.

Currently I use and MTF version of TMO along with an regular and MTF SuperTrend...Tend Magic and HA as an exit indicator along with the CSA you made..ONLY because I am still testing the CSA and its remarkable how well the CSA works...There are times tho where an exit indicator is needed as I do find the CSA lags...but that is normal.


regular timeframe SuperTrend, Trend Magic and HA is represented on the bottom of the TMO...and the MTF version is above the TMO...
I like the idea of a stop/exit CSA and a "reversal/countertrend" CSA that can be added with the trend CSA, if you all have specific ideas, studies and basic code for each of the indicators, more than happy to start a separate thread in the development of stop/exits and if enough interest one on reversals. in the meantime, please suggest and post studies and code and we will add them to backlog for future development.
 
@diazlaz I am going over each indicators one by one in the CSA to find the best possible combination and
I found an issue with FREMA. I have used FREMA before in combination with MACD and FREMA in the CSA plots different than in the MACD I was using it with...Please take a look at the pic below:


Is there a way to fix the FREMA in this CSA to reflect how it plots in the MACD script below? You can clearly see the difference based on the pic and how much faster the FREMA in MACD hits vs in the CSA. BTW: I have set the threshold to 1 and disabled all other indicators to NO to make sure that ONLY one indicator is being tested at a time.

Code:
# MACD with a more Normal Distribution
# Mobius
# V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

# V11.01.2019 - netarchitech added standard TOS Breakout Signals per HighBredCloud request
# V11.01.2019 - netarchitech added Ehlers and Mobius Forward/Reverse EMA per HighBredCloud request

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = no;

# Four Pole Filter
script g{
input length = 4;
input betaDev = 2;
input price = OHLC4;
def c;
def w;
def beta;
def alpha;
def G;
c = price;
w = (2 * Double.Pi / length);
beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
alpha = (-beta + Sqrt(beta * beta + 2 * beta));
G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot Line = G;
}
# Modified MACD
plot Value = g(length = fastLength) - g(length = slowLength);
plot Avg = g(price = Value, length = MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
#Value.SetLineWeight(2);
Avg.SetDefaultColor(GetColor(8));
#Avg.SetLineWeight(2);
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
Signal.AssignValueColor(if Signal > Signal[1]
                        then Color.GREEN
                        else Color.RED);
Signal.SetLineWeight(3);
Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.GRAY);

#addCloud(0, Signal, color.RED, color.GREEN);

EDIT: It appears that the colors in the FREMA in the MACD script that I have posted above is set not based on the ZERO line crossing of FREMA hence the early entry/exit. I am not sure IF there is a way to replicate "Negative and Up" and or "Positive and Down" state in the CSA to reflect those of the FREMA found in the MACD script that I have provided.
will look at it in more detail and release a fix in the upcoming 3.2 maint. release
 
@diazlaz I also checked Schaff Trend and Wave...it also appears to be off from the stand alone indicator that I am using. I know you mentioned to me before on what to use as the logic to obtain the signals...I used the Shaff Wave crossing over the 10 EMA...I don't see the 10 EMA in the CSA script at all. Personally the Trend Line is a bit useless since there are other indicators in the CSA that work much better...You don't need to incorporate STCTrend or the Polarity from the script below. Just STCWave and AvgExpWave...possibly see what makes the STCWave change colors because that is a great indication of the change in trend direction other than the STCWave crossing the AvgExpWave...


Code:
#STSW = Schaff Trend Line and Schaff Wave Line
#Schaff Trend Line = Used for quick up/down trend declaration
#Schaff Wave Line = Trade Wave in the direction of trend as
#declared by Trend Line.
#Schaff Wave Line can be used alone to enter trend
#declared by the MACD.
#Schaff Wave can be used with the EMA for signals

declare lower;

input fastLengthTrend = 48;
input slowLengthTrend = 104;
input KPeriodTrend = 36;
input DPeriodTrend = 8;
input averageTypeTrend = AverageType.EXPONENTIAL;
input fastLengthWave = 12;
input slowLengthWave = 26;
input KPeriodWave = 9;
input DPeriodWave = 2;
input over_bought = 75;
input over_sold = 25;
input averageTypeWave = AverageType.EXPONENTIAL;

def macdTrend = MovingAverage(averageTypeTrend, close, fastLengthTrend) - MovingAverage(averageTypeTrend, close, slowLengthTrend);
def macdWave = MovingAverage(averageTypeWave, close, fastLengthWave) - MovingAverage(averageTypeWave, close, slowLengthWave);
def fastK1Trend = FastKCustom(macdTrend, KPeriodTrend);
def fastK1Wave = FastKCustom(macdWave, KPeriodWave);
def fastD1Trend = MovingAverage(averageTypeTrend, fastK1Trend, DPeriodTrend);
def fastD1Wave = MovingAverage(averageTypeWave, fastK1Wave, DPeriodWave);
def fastK2Trend = FastKCustom(fastD1Trend, KPeriodTrend);
def fastK2Wave = FastKCustom(fastD1Wave, KPeriodWave);
plot STCTrend = MovingAverage(averageTypeTrend, fastK2Trend, DPeriodTrend);
plot STCWave = MovingAverage(averageTypeWave, fastK2Wave, DPeriodWave);
plot OverBought = over_bought;
plot OverSold = over_sold;

STCTrend.SetDefaultColor(GetColor(8));
STCWave.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

plot Fifty_Line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);

STCTrend.DefineColor("Up", GetColor(1));
STCTrend.DefineColor("Down", GetColor(0));
STCTrend.AssignValueColor(if STCTrend > STCTrend[1] then STCTrend.Color("Up") else STCTrend.Color("Down"));
STCWave.DefineColor("Up", GetColor(1));
STCWave.DefineColor("Down", GetColor(0));
STCWave.AssignValueColor(if STCWave > STCWave[1] then STCWave.Color("Up") else STCWave.Color("Down"));

input lengthWave = 10;
plot AvgExpWave = ExpAverage(STCWave, lengthWave);
AvgExpWave.SetDefaultColor(GetColor(1));
#
# Polarity

# v0.01

# 6.2.19

# Nube

#hint: This study calculates a CCI from an average of high and low pivot prices then uses that CCI and a user defined number of deviations to determine polarity. A cross above +deviations or cross below -devations signals a polarity change



# subscript for calculating the mean of pivot prices

script pivotMean{

input pivotN = 4;

input stochasticN = 21;

def h = high;

def l = low;

def norm = (close - Lowest(l, pivotN)) /

(Highest(h, pivotN) - Lowest(l, pivotN));



## Pivot High

def hh = if norm crosses above .5

then h

else if h > hh[1]

then h

else hh[1];

def hpBar = if h == hh

then BarNumber()

else Double.NaN;

def hpPrice = if !IsNaN(hpBar)

then h

else hpPrice[1];



## Pivot Low

def ll = if norm crosses below .5

then l

else if l < ll[1]

then l

else ll[1];

def lpBar = if l == ll

then BarNumber()

else Double.NaN;

def lpPrice = if !IsNaN(lpBar)

then l

else lpPrice[1];



plot

pivotMean = Average((hpPrice + lpPrice) / 2, stochasticN);

}



# Inputs

input pivotLength = 4; #hint pivotLength: Number of bars for stochastic pivot calcuation

input meanLength = 21; #hint meanLength: Number of bars to calculate mean

input deviations = 1.0;#hint deviations: Number of deviations from mean to signal a polarity change



# Variables

def mean   = pivotMean(pivotLength, meanLength);

def linDev = lindev(close, meanLength);

def cci    = (close - mean) / linDev;



def polarity_;

if cci crosses above deviations{

polarity_ = 1;

}else

if cci crosses below -deviations{

polarity_ = -1;

}else{

polarity_ = polarity_[1];

}



# Plots

plot

Polarity = polarity_;

Polarity.AssignValueColor(if polarity_ > 0 then Color.Green else Color.Red);



#declare lower;



# f/ Polarity
will update in the upcoming 2.3 release. thanks for the feedback.
 
This indicator might have great usefulness, but the colors and setup are visually unappealing - so that's been putting me off from digging further. The colors are too strong/gimmicky, and I use small charts so the numerous labels up top take a great deal of space and I don't even know what the labels are telling me and if they're even useful at all.
 
This indicator might have great usefulness, but the colors and setup are visually unappealing - so that's been putting me off from digging further. The colors are too strong/gimmicky, and I use small charts so the numerous labels up top take a great deal of space and I don't even know what the labels are telling me and if they're even useful at all.

@anycolour

You can change the colors to any style you want. Everyone has a different color preference - I happen to like the way it is coded now. The few I didn't like I changed.
 
This indicator might have great usefulness, but the colors and setup are visually unappealing - so that's been putting me off from digging further. The colors are too strong/gimmicky, and I use small charts so the numerous labels up top take a great deal of space and I don't even know what the labels are telling me and if they're even useful at all.
You can disable the labels to your liking by setting show labels to no.
 
In which image particularly are you referring to for me to share?...The lower CSA was just an example of Mobius MTF SuperTrend that can be found below if that is what you are referring to. This was just an idea I had in mind to make something similar as part of the lower study for this CSA using indicators that would serve as exit indicators to the upper study CSA.

Code:
# SuperTrend Multiple Time Frames
# Mobius with mods by tomsk to replace the script() function for secondary aggs with "standard" code
# V03.01.2016
# 11.4.2019

declare lower;

input agg1 = AggregationPeriod.Five_Min;
input agg2 = AggregationPeriod.Ten_Min;
input agg3 = AggregationPeriod.Fifteen_Min;
input agg4 = AggregationPeriod.Thirty_Min;
input agg5 = AggregationPeriod.Hour;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;

def Fh = FundamentalType.High;
def Fl = FundamentalType.Low;
def Fc = FundamentalType.Close;
def Fhl2 = FundamentalType.HL2;

def cl = close;
def x = isNaN(cl[2]) and !isNaN(cl[3]);
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = hl2 + (AtrMult * ATR);
def DN = hl2 + (-AtrMult * ATR);
def S = if close < S[1]
then Round(UP / tickSize(), 0) * tickSize()
else Round(DN / tickSize(), 0) * tickSize();
def FirstAgg = if close > S then 1 else 0;
plot FirstAggPlot = if isNaN(cl)
then double.nan
else 1;
FirstAggPlot.SetStyle(Curve.Points);
FirstAggPlot.SetLineWeight(3);
FirstAggPlot.AssignValueColor(if FirstAgg == 1
then color.green
else color.red);
AddChartBubble(x, 1, (GetAggregationPeriod()/1000/60) + " min", color.white, yes);

# SecondAgg
def h2 = Fundamental(Fh, period = agg2)[1];
def l2 = Fundamental(Fl, period = agg2)[1];
def c2 = Fundamental(Fc, period = agg2)[1];
def hl2 = Fundamental(Fhl2, period = agg2)[1];
def ATR2 = MovingAverage(AvgType, TrueRange(h2, c2, l2), nATR);
def UP2 = hl2 + (AtrMult * ATR2);
def DN2 = hl2 + (-AtrMult * ATR2);
def S2 = if c2 < S2[1]
then Round(UP2 / tickSize(), 0) * tickSize()
else Round(DN2 / tickSize(), 0) * tickSize();
def SecondAgg = if c2 > S2 then 1 else 0;
plot SecondAggPlot = if isNaN(cl)
then double.nan
else 2;
SecondAggPlot.SetStyle(Curve.Points);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg == 1
then color.green
else color.red);
AddChartBubble(x, 2, (agg2/1000/60) + " min", color.white, yes);

# ThirdAgg
def h3 = Fundamental(Fh, period = agg3)[1];
def l3 = Fundamental(Fl, period = agg3)[1];
def c3 = Fundamental(Fc, period = agg3)[1];
def hl3 = Fundamental(Fhl2, period = agg3)[1];
def ATR3 = MovingAverage(AvgType, TrueRange(h3, c3, l3), nATR);
def UP3 = hl3 + (AtrMult * ATR3);
def DN3 = hl3 + (-AtrMult * ATR3);
def S3 = if c3 < S3[1]
then Round(UP3 / tickSize(), 0) * tickSize()
else Round(DN3 / tickSize(), 0) * tickSize();
def ThirdAgg = if c3 > S3 then 1 else 0;
plot ThirdAggPlot = if isNaN(cl)
then double.nan
else 3;
ThirdAggPlot.SetStyle(Curve.Points);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg == 1
then color.green
else color.red);
AddChartBubble(x, 3, (agg3/1000/60) + " min", color.white, yes);

# FourthAgg
def h4 = Fundamental(Fh, period = agg4)[1];
def l4 = Fundamental(Fl, period = agg4)[1];
def c4 = Fundamental(Fc, period = agg4)[1];
def hl4 = Fundamental(Fhl2, period = agg4)[1];
def ATR4 = MovingAverage(AvgType, TrueRange(h4, c4, l4), nATR);
def UP4 = hl4 + (AtrMult * ATR4);
def DN4 = hl4 + (-AtrMult * ATR4);
def S4 = if c4 < S4[1]
then Round(UP4 / tickSize(), 0) * tickSize()
else Round(DN4 / tickSize(), 0) * tickSize();
def FourthAgg = if c4 > S4 then 1 else 0;
plot FourthAggPlot = if isNaN(cl)
then double.nan
else 4;
FourthAggPlot.SetStyle(Curve.Points);
FourthAggPlot.SetLineWeight(3);
FourthAggPlot.AssignValueColor(if FourthAgg == 1
then color.green
else color.red);
AddChartBubble(x, 4, (agg4/1000/60) + " min", color.white, yes);

# FifthAgg
def h5 = Fundamental(Fh, period = agg5)[1];
def l5 = Fundamental(Fl, period = agg5)[1];
def c5 = Fundamental(Fc, period = agg5)[1];
def hl5 = Fundamental(Fhl2, period = agg5)[1];
def ATR5 = MovingAverage(AvgType, TrueRange(h5, c5, l5), nATR);
def UP5 = hl5 + (AtrMult * ATR5);
def DN5 = hl5 + (-AtrMult * ATR5);
def S5 = if c5 < S5[1]
then Round(UP5 / tickSize(), 0) * tickSize()
else Round(DN5 / tickSize(), 0) * tickSize();
def FifthAgg = if c5 > S5 then 1 else 0;
plot FifthAggPlot = if isNaN(cl)
then double.nan
else 5;
FifthAggPlot.SetStyle(Curve.Points);
FifthAggPlot.SetLineWeight(3);
FifthAggPlot.AssignValueColor(if FifthAgg == 1
then color.green
else color.red);
AddChartBubble(x, 5, (agg5/1000/60)+ " min", color.white, yes);
plot Six = if isNaN(cl)
then double.nan
else 6;
Six.SetStyle(Curve.Points);
Six.SetLineWeight(3);
Six.AssignValueColor(if FirstAgg and
SecondAgg and
ThirdAgg and
FourthAgg and
FifthAgg
then color.green
else if !FirstAgg and
!SecondAgg and
!ThirdAgg and
!FourthAgg and
!FifthAgg
then color.red
else color.black);
# End Code ST MTF

I tried changing the agg time frame to higher time frames( day, week, month), but nothing displayed on chart. it is possible to do, or am i doing something wrong?
 
This indicator might have great usefulness, but the colors and setup are visually unappealing - so that's been putting me off from digging further. The colors are too strong/gimmicky, and I use small charts so the numerous labels up top take a great deal of space and I don't even know what the labels are telling me and if they're even useful at all.
@anycolour You can turn the labels off...and would regular Uptick and Downtick instead of the Bright Green and Bright Red be better? You can use the commented out version of the CSA that I posted in post #66 if you want less visible labels...I only used indicators that seem to work the best for this current CSA version.
 
I tried changing the agg time frame to higher time frames( day, week, month), but nothing displayed on chart. it is possible to do, or am i doing something wrong?
@Johnny Cash The time aggregation that you see in the CSA is for Heikin Ashi MTF...I will suggest that you should not go too far into higher aggregation from your original timeframe that you trade on. For example...If you are trading on a 3 min time frame...set the HA MTF aggregation to a 5 min timeframe...if you are trading on a 5 min time frame set the HA MTF aggregation to a 10 min...Basically step up one more time frame in the aggregation field than your original timeframe. This is intended to eliminate the fake outs a smaller timeframe might give you. Setting the aggregation to more than the Daily such as Weekly or Monthly is probably not suitable for this CSA...In my opinion.
 
@HighBredCloud I will add the original Super Trend HA version in the upcoming 2.4 feature release, also will fix the HA button to be HAMTF in the upcoming 2.3. thanks for the feedback and testing. glad ur getting value out of it.
@diazlaz Please keep the regular HA...as it is in the CSA right now. The goal of the HA MTF is to set it one timeframe above the one that you are trading on to eliminate the possible fake outs of the HA on a smaller timeframe...Please go ahead and add on the original SuperTrend HA from Mobius tho. I for one am seeing great results with this CSA especially in the commented out version in post #66.
 
@anycolour You can turn the labels off...and would regular Uptick and Downtick instead of the Bright Green and Bright Red be better? You can use the commented out version of the CSA that I posted in post #66 if you want less visible labels...I only used indicators that seem to work the best for this current CSA version.
I will add global colors to make it easier to change all the global colors in one of the future maintenance releases. this will make it super easy to adjust the theme, color if you're using ToS with a white background or high contrast palette.
 

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
440 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