Trend Meter For ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
Per member request: https://usethinkscript.com/threads/converted-tradingview-trend-meter.11113/
converted the code below. Moreover, I added signal based on the provided YouTube. Enjoy :)

CSS:
#// Created By Lij_MC
#// Use as a supplementary Indicator to confirm your entries, but it is as good on it's own.
#// The indicator consists of 3 different Trend Meters and a Trend Bar which are used to confirm trend
#// As a bonus Wave Trend Signals are marked as well, these are very powerful however please use with caution
#// How to Use
#// Look for Support or Resistance Levels for price to be attracted to
#// Find confluence with other indicators
#// Enter Long above the Setup Bar
#// Enter Short Below the Setup Bar
#study(title="Trend Meter")
# Converted and mod by Sam4Cok@Samer800 - 10/2022
declare lower;
#// Inputs / Menus
#// Trend Bar / Meter - Inputs / Menus
input VolatilityLength = 100;
input SignalMALength1 = 50;
input SignalMALength2 = 200;
input ShowTrendBar = yes;
input UseChartTimeFrame = yes;
input Aggregation = AggregationPeriod.HOUR;
#// MA Inputs
input ma1_Length = 5;    # 'Fast MA'
input ma1_Type   = {default "EMA", "SMA"};   # "TB1 Fast"
input ma2_Length = 11;   # 'Slow MA'
input ma2_Type   = {default "EMA", "SMA"};   # "TB1 Slow"
input ma3_Length = 13;   # 'Fast MA'
input ma3_Type   = { default "EMA", "SMA"};  # "TB2 Fast"
input ma4_Length = 36;   # 'Slow MA'
input ma4_Type   = {"EMA", default "SMA"};   # "TB2 Slow"
#--Trend inputs
input WaveTrendSignalLine = no;    # "Wave Trend Filtered by Trend"
input TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input Filter2 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input TrendMeter1 = {"MACD Crossover - 12, 26, 9", default "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter1"
input TrendMeter2 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", default "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 2"

input TrendMeter3 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", default "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 3"

input TrendBar1 = {default "MA Crossover", "MA Direction - Fast MA - TB1", "MA Direction - Slow MA - TB1", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 1"

input TrendBar2 = {default "MA Crossover", "MA Direction - Fast MA - TB2", "MA Direction - Slow MA - TB2", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 2"

def na = Double.NaN;
#def mClose = if UseChartTimeFrame then Close(period=GetAggregationPeriod()) else close(period=AggregationPeriod);
def agg = GetAggregationPeriod();
def c = if UseChartTimeFrame then close else close(Period = Aggregation);
def o = if UseChartTimeFrame then open else open(Period = Aggregation);
;
#---Color
DefineGlobalColor("green" , CreateColor(40, 138, 117));
DefineGlobalColor("Red"   , CreateColor(255, 82, 82));
#// Wave Trend - RSI

def RSIMC = RSI(price = c, Length = 14);

#// Wave Trend

def ap = if UseChartTimeFrame then hlc3 else hlc3(Period = Aggregation) ;    #  "Wave Trend - Source"
def n1 = 9;       #  "Wave Trend - WT Channel Length"
def n2 = 12;      #  "Wave Trend - WT Average Length"
def esa = ExpAverage(ap, n1);
def de = ExpAverage(AbsValue(ap - esa), n1);
def ci = (ap - esa) / (0.015 * de);
def tci = ExpAverage(ci, n2);

def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 3);

#// Wave Trend - Overbought & Oversold lines

def obLevel2 = 60;    #  "Wave Trend - WT Very Overbought")
def obLevel = 50;     #  "Wave Trend - WT Overbought")
def osLevel = -50;    #  "Wave Trend - WT Oversold")
def osLevel2 = -60;   #  "Wave Trend - WT Very Oversold")

#// Wave Trend - Conditions

def WTCross = Crosses(wt1, wt2);
def WTCrossUp = wt2 - wt1 <= 0;
def WTCrossDown = wt2 - wt1 >= 0;
def WTOverSold = wt2 <= osLevel2;
def WTOverBought = wt2 >= obLevel2;

#// MA Calculations


def MA1 = if ma1_Type == ma1_Type."SMA" then
    SimpleMovingAvg(c, ma1_Length) else ExpAverage(c, ma1_Length);

def MA2 = if ma2_Type == ma2_Type."SMA" then
    SimpleMovingAvg(c, ma2_Length) else ExpAverage(c, ma2_Length);

def MA3 = if ma3_Type == ma3_Type."SMA" then
    SimpleMovingAvg(c, ma3_Length) else ExpAverage(c, ma3_Length);

def MA4 = if ma4_Type == ma4_Type."SMA" then
    SimpleMovingAvg(c, ma4_Length) else ExpAverage(c, ma4_Length);

#// MA Crossover Condition

def MACrossover1 = if MA1 > MA2 then 1 else 0;
def MACrossover2 = if MA3 > MA4 then 1 else 0;

#// MA Direction Condition

def MA1Direction = if MA1 > MA1[1] then 1 else 0;
def MA2Direction = if MA2 > MA2[1] then 1 else 0;
def MA3Direction = if MA3 > MA3[1] then 1 else 0;
def MA4Direction = if MA4 > MA4[1] then 1 else 0;

#// MA Direction Change Condition

def MA1PositiveDirectionChange = if MA1Direction and !MA1Direction[1] then 1 else 0;
def MA2PositiveDirectionChange = if MA2Direction and !MA2Direction[1] then 1 else 0;
def MA3PositiveDirectionChange = if MA3Direction and !MA3Direction[1] then 1 else 0;
def MA4PositiveDirectionChange = if MA4Direction and !MA4Direction[1] then 1 else 0;

def MA1NegativeDirectionChange = if !MA1Direction and MA1Direction[1] then 1 else 0;
def MA2NegativeDirectionChange = if !MA2Direction and MA2Direction[1] then 1 else 0;
def MA3NegativeDirectionChange = if !MA3Direction and MA3Direction[1] then 1 else 0;
def MA4NegativeDirectionChange = if !MA4Direction and MA4Direction[1] then 1 else 0;

#// MACD and MOM & DAD - Top Dog Trading
#// Standard MACD Calculations

def MACDfastMA = 12;
def MACDslowMA = 26;
def MACDsignalSmooth = 9;

def MACDLine = ExpAverage(c, MACDfastMA) - ExpAverage(c, MACDslowMA);
def SignalLine = ExpAverage(MACDLine, MACDsignalSmooth);
def MACDHistogram = MACDLine - SignalLine;

#// MACD- Background Color Change Condition

def MACDHistogramCross = if MACDHistogram > 0 then 1 else 0;
def MACDLineOverZero = if MACDLine > 0 then 1 else 0;
def MACDLineOverZeroandHistogramCross = if MACDHistogramCross and MACDLineOverZero then 1 else 0;
def MACDLineUnderZeroandHistogramCross = if !MACDHistogramCross and !MACDLineOverZero then 1 else 0;

#// Fast MACD Calculations

def FastMACDfastMA = 8;
def FastMACDslowMA = 21;
def FastMACDsignalSmooth = 5;

def FastMACDLine = ExpAverage(c, FastMACDfastMA) - ExpAverage(c, FastMACDslowMA);
def FastSignalLine = ExpAverage(FastMACDLine, FastMACDsignalSmooth);
def FastMACDHistogram = FastMACDLine - FastSignalLine;

#// Fast MACD- Background Color Change Condition

def FastMACDHistogramCross = if FastMACDHistogram > 0 then 1 else 0;
def FastMACDLineOverZero = if FastMACDLine > 0 then 1 else 0;
def FastMACDLineOverZeroandHistogramCross = if FastMACDHistogramCross and FastMACDLineOverZero then 1 else 0;
def FastMACDLineUnderZeroandHistogramCross = if !FastMACDHistogramCross and !FastMACDLineOverZero then 1 else 0;

#// Top Dog Trading - Mom Dad Calculations

def TopDog_Fast_MA = 5;
def TopDog_Slow_MA = 20;
def TopDog_Sig = 30;

def TopDogMom = ExpAverage(c, TopDog_Fast_MA) - ExpAverage(c, TopDog_Slow_MA);
def TopDogDad = ExpAverage(TopDogMom, TopDog_Sig);

#// Top Dog Dad - Background Color Change Condition

def TopDogDadDirection = If(TopDogDad > TopDogDad[1], 1, 0);
def TopDogMomOverDad = If(TopDogMom > TopDogDad, 1, 0);
def TopDogMomOverZero = If(TopDogMom > 0, 1, 0);
def TopDogDadDirectandMomOverZero = If(TopDogDadDirection and TopDogMomOverZero, 1, 0);
def TopDogDadDirectandMomUnderZero = If(!TopDogDadDirection and !TopDogMomOverZero, 1, 0);

#////// Trend Barmeter Calculations //////
#// UCS_Trend / Trend Candles Trend Barmeter Calculations
#//UCS_Trend by ucsgears copy Trend Candles
#//Interpretation of TTM Trend bars. It is really close to the actual.

def haclose = if UseChartTimeFrame then ohlc4 else ohlc4(Period = Aggregation);
def haopen = if IsNaN(haopen[1]) then (o + c) / 2 else (haopen[1] + haclose[1]) / 2;

def ccolor = If(haclose - haopen > 0, 1, 0);

def inside6 = If(haopen <= Max(haopen[6], haclose[6]) and haopen >= Min(haopen[6], haclose[6]) and
   haclose <= Max(haopen[6], haclose[6]) and haclose >= Min(haopen[6], haclose[6]), 1, 0);

def inside5 = If(haopen <= Max(haopen[5], haclose[5]) and haopen >= Min(haopen[5], haclose[5]) and
   haclose <= Max(haopen[5], haclose[5]) and haclose >= Min(haopen[5], haclose[5]), 1, 0);

def inside4 = If(haopen <= Max(haopen[4], haclose[4]) and haopen >= Min(haopen[4], haclose[4]) and
   haclose <= Max(haopen[4], haclose[4]) and haclose >= Min(haopen[4], haclose[4]), 1, 0);

def inside3 = If(haopen <= Max(haopen[3], haclose[3]) and haopen >= Min(haopen[3], haclose[3]) and
   haclose <= Max(haopen[3], haclose[3]) and haclose >= Min(haopen[3], haclose[3]), 1, 0);

def inside2 = If(haopen <= Max(haopen[2], haclose[2]) and haopen >= Min(haopen[2], haclose[2]) and
   haclose <= Max(haopen[2], haclose[2]) and haclose >= Min(haopen[2], haclose[2]), 1, 0);

def inside1 = If(haopen <= Max(haopen[1], haclose[1]) and haopen >= Min(haopen[1], haclose[1]) and
   haclose <= Max(haopen[1], haclose[1]) and haclose >= Min(haopen[1], haclose[1]), 1, 0);

def colorvalue = if inside6 then ccolor[6] else if inside5 then ccolor[5] else if inside4 then ccolor[4] else if inside3 then ccolor[3] else if inside2 then ccolor[2] else if inside1 then ccolor[1] else ccolor;

def TrendBarTrend_Candle = if colorvalue then 1 else 0;

#// RSI 5 Trend Barmeter Calculations

def RSI5 = RSI(Price = c, Length = 5);
def RSI5Above50 = if RSI5 > 50 then 1 else 0;
def RSI5Color = if RSI5Above50 then 1 else 0;# ? #288a75 : color.red

#// RSI 5 Trend Barmeter Calculations

def RSI13 = RSI(Price = c, Length = 13);

#// Linear Regression Calculation For RSI Signal Line

def SignalLineLength1 = 21;

def x = BarNumber();
def y = RSI13;
def x_ = SimpleMovingAvg(x, SignalLineLength1);
def y_ = SimpleMovingAvg(y, SignalLineLength1);
def mx = StDev(x, SignalLineLength1);
def my = StDev(y, SignalLineLength1);
def corr = Correlation(x, y, SignalLineLength1);
def slope = corr * (my / mx);
def inter = y_ - slope * x_;
def LinReg1 = x * slope + inter;

def RSISigDirection = If(LinReg1 > LinReg1[1], 1, 0);
def RSISigCross = If(RSI13 > LinReg1, 1, 0);
def RSI13Above50 = If(RSI13 > 50, 1, 0);

#// Trend Barmeter Color Calculation

#RSI13Color = RSI13Above50 ? #288a75 : color.red
def TrendBarRSI13Color = If(RSI13Above50, 1, 0);
def TrendBarRSISigCrossColor = If(RSISigCross, 1, 0);
def TrendBarMACDColor = If(MACDHistogramCross, 1, 0);
def TrendBarFastMACDColor = If(FastMACDHistogramCross, 1, 0);
def TrendBarMACrossColor = If(MACrossover1, 1, 0);
def TrendBarMomOverDadColor = If(TopDogMomOverDad, 1, 0);
def TrendBarDadDirectionColor = If(TopDogDadDirection, 1, 0);

def TrendBar1Result = if TrendMeter1 ==  TrendMeter1."MA Crossover" then MACrossover1 else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar2Result = if TrendMeter2 == TrendMeter2."MA Crossover" then MACrossover1 else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar3Result = if TrendMeter3 == TrendMeter3."MA Crossover" then MACrossover1 else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else na;


def TrendBars2Positive = If(TrendBar1Result and TrendBar2Result or TrendBar1Result and
                            TrendBar3Result or TrendBar2Result and TrendBar3Result, 1, 0);

def TrendBars2Negative = If(!TrendBar1Result and !TrendBar2Result or !TrendBar1Result and
                            !TrendBar3Result or !TrendBar2Result and !TrendBar3Result, 1, 0);

def TrendBars3Positive = If(TrendBar1Result and TrendBar2Result and TrendBar3Result, 1, 0);
def TrendBars3Negative = If(!TrendBar1Result and !TrendBar2Result and !TrendBar3Result, 1, 0);

#// Signal Filters

def FilterXUp = FastMACDHistogramCross and ExpAverage(c, 15) > ExpAverage(c, 15)[1];
def FilterXDown = !FastMACDHistogramCross and ExpAverage(c, 15) < ExpAverage(c, 15)[1];

def TrendFilterPlus = If(ExpAverage(c, 15) > ExpAverage(c, 20) and ExpAverage(c, 20) > ExpAverage(c, 30) and ExpAverage(c, 30) > ExpAverage(c, 40) and ExpAverage(c, 40) > ExpAverage(c, 50), 1, 0);

def TrendFilterMinus = If(ExpAverage(c, 15) < ExpAverage(c, 20) and ExpAverage(c, 20) < ExpAverage(c, 30) and ExpAverage(c, 30) < ExpAverage(c, 40) and ExpAverage(c, 40) < ExpAverage(c, 50), 1, 0);

#// // Wave Trend - Conditions

def MSBar1PositiveWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter1 == Filter1."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar1NegativeWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter1 == Filter1."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else
   WTCross and WTCrossDown;

def MSBar2PositiveWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter2 == Filter2."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar2NegativeWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter2 == Filter2."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else WTCross and WTCrossDown;

#////////////////////////

def BackgroundColorChangePositive = TrendBars3Positive and !TrendBars3Positive[1];
def BackgroundColorChangeNegative = TrendBars3Negative and !TrendBars3Negative[1];

#// Signals Color Calculations

def MSBar1Color = if MSBar1PositiveWaveTrendSignal then 1 else
   if MSBar1NegativeWaveTrendSignal then -1 else na;#

def MSBar2Color = if BackgroundColorChangePositive then 1 else
   if BackgroundColorChangeNegative then -1 else na;

#// Trend Barmeter Color Assignments

def TrendBar1Color =
if TrendMeter1 == TrendMeter1."N/A" then na else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter1 == TrendMeter1."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar2Color =
if TrendMeter2 == TrendMeter2."N/A" then na else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter2 == TrendMeter2."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar3Color =
if TrendMeter3 == TrendMeter3."N/A" then na else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter3 == TrendMeter3."MA Crossover" then TrendBarMACrossColor else na;


def CrossoverType2 =
if TrendBar1 == TrendBar1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar1 == TrendBar1."MACD Crossover" then MACDHistogramCross else if
   TrendBar1 == TrendBar1."MA Direction - Fast MA - TB1" then MA1Direction else if
   TrendBar1 == TrendBar1."MA Direction - Slow MA - TB1" then MA2Direction else MACrossover1;

def TrendBar4Color1 = if TrendBar1 == TrendBar1."N/A" then na else
                      if CrossoverType2 then 1 else 0;

def CrossoverType3 =
if TrendBar2 == TrendBar2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar2 == TrendBar2."MACD Crossover" then MACDHistogramCross else if
   TrendBar2 == TrendBar2."MA Direction - Fast MA - TB2" then MA3Direction else if
   TrendBar2 == TrendBar2."MA Direction - Slow MA - TB2" then MA4Direction else MACrossover2;

def TrendBar5Color1 = if TrendBar2 == TrendBar2."N/A" then na else
                      if CrossoverType3 then 1 else 0;

#// Momentum Setup Plots

plot Signals1 = If(IsNaN(c) or IsNaN(MSBar1Color), na, If(ShowTrendBar and WaveTrendSignalLine, 129, na));    # "Signals 1 - Wave Trend Signals"
Signals1.SetPaintingStrategy(PaintingStrategy.SQUARES);
Signals1.AssignValueColor(if MSBar1Color > 0 then GlobalColor("green") else GlobalColor("RED"));

plot Signals2 = If(IsNaN(c) or IsNaN(MSBar2Color), na, If(ShowTrendBar and TrendMeterLine, 126, na));    # "Signals 2 - All 3 Trend Meters Now Align"
Signals2.SetPaintingStrategy(PaintingStrategy.POINTS);
Signals2.AssignValueColor(if MSBar2Color > 0 then GlobalColor("green") else GlobalColor("RED"));

#// Trend Barmeter Plots

plot TM1 = If(IsNaN(c), na, If(ShowTrendBar, 123, na)); # "Trend Meter 1"
TM1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM1.AssignValueColor(if TrendBar1Color then GlobalColor("green") else GlobalColor("RED"));

plot TM2 = If(IsNaN(c), na, If(ShowTrendBar, 120.5, na));# "Trend Meter 2"
TM2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM2.AssignValueColor(if TrendBar2Color then GlobalColor("green") else GlobalColor("RED"));

plot TM3 = If(IsNaN(c), na, If(ShowTrendBar, 118, na));# "Trend Meter 3"
TM3.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM3.AssignValueColor(if TrendBar3Color then GlobalColor("green") else GlobalColor("RED"));

plot ThinLine = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar2 == TrendBar2."N/A"), 115, na));
ThinLine.AssignValueColor(if TrendBar4Color1 then Color.GREEN else Color.RED);
ThinLine.SetLineWeight(2);

plot ThikLine = If(IsNaN(c), na, If(ShowTrendBar and TrendBar2 == TrendBar2."N/A" and !(TrendBar1 == TrendBar1."N/A"), 107.25, na));
ThikLine.AssignValueColor(if TrendBar4Color1 then  Color.GREEN else Color.RED);
ThikLine.SetLineWeight(5);

plot ThinLine2 = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar1 == TrendBar1."N/A"), 112.5, na));
ThinLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThinLine2.SetLineWeight(2);

plot ThikLine2 = If(IsNaN(c), na, If(ShowTrendBar and TrendBar1 == TrendBar1."N/A" and !(TrendBar2 == TrendBar2."N/A"), 107.25, na));
ThikLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThikLine2.SetLineWeight(5);

#--- Stratgy Line
def EMA1 = ExpAverage(c,SignalMALength1);
def EMA2 = ExpAverage(c,SignalMALength2);
def diff = c - o;
def UpperBand = StDev(diff, VolatilityLength);
def LowerBand = StDev(diff, VolatilityLength) * -1;
def Long = Signals2 and MSBar2Color>0 and ThinLine and ThinLine2 and TrendBar4Color1 and TrendBar5Color1 and diff>=UpperBand and EMA1>EMA2;
def short = Signals2 and MSBar2Color<0 and ThinLine and ThinLine2 and !TrendBar4Color1 and !TrendBar5Color1 and diff<=LowerBand and EMA1<EMA2;

plot LongSignal = if Long then 126 else na;
plot ShortSignal = if short then 126 else na;
LongSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
LongSignal.SetDefaultColor(Color.GREEN);
LongSignal.SetLineWeight(5);
ShortSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortSignal.SetDefaultColor(Color.RED);
ShortSignal.SetLineWeight(5);
#// Background Highlights

AddCloud(if TrendBars3Positive then Double.NEGATIVE_INFINITY else if TrendBars3Negative then Double.POSITIVE_INFINITY else na, if TrendBars3Positive then Double.POSITIVE_INFINITY else if TrendBars3Negative then Double.NEGATIVE_INFINITY else na, Color.DARK_RED, Color.DARK_GREEN);

#---END Code

Add Price color option

CSS:
#// Created By Lij_MC
#// Use as a supplementary Indicator to confirm your entries, but it is as good on it's own.
#// The indicator consists of 3 different Trend Meters and a Trend Bar which are used to confirm trend
#// As a bonus Wave Trend Signals are marked as well, these are very powerful however please use with caution
#// How to Use
#// Look for Support or Resistance Levels for price to be attracted to
#// Find confluence with other indicators
#// Enter Long above the Setup Bar
#// Enter Short Below the Setup Bar
#study(title="Trend Meter")
# Converted and mod by Sam4Cok@Samer800 - 10/2022
# Added Price Color option by Sam4Cok@Samer800 - 11/2022 as requested from useThinkScript.com member
declare lower;
#// Inputs / Menus
#// Trend Bar / Meter - Inputs / Menus
input ColorBars = no;
input VolatilityLength = 100;
input SignalMALength1 = 20;
input SignalMALength2 = 50;
input ShowTrendBar = yes;
input UseChartTimeFrame = yes;
input Aggregation = AggregationPeriod.HOUR;
#// MA Inputs
input ma1_Length = 5;    # 'Fast MA'
input ma1_Type   = {default "EMA", "SMA"};   # "TB1 Fast"
input ma2_Length = 11;   # 'Slow MA'
input ma2_Type   = {default "EMA", "SMA"};   # "TB1 Slow"
input ma3_Length = 13;   # 'Fast MA'
input ma3_Type   = { default "EMA", "SMA"};  # "TB2 Fast"
input ma4_Length = 29;   # 'Slow MA'
input ma4_Type   = {"EMA", default "SMA"};   # "TB2 Slow"
#--Trend inputs
input WaveTrendSignalLine = no;    # "Wave Trend Filtered by Trend"
input TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input Filter2 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input TrendMeter1 = {"MACD Crossover - 12, 26, 9", default "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter1"
input TrendMeter2 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", default "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 2"

input TrendMeter3 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", default "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 3"

input TrendBar1 = {default "MA Crossover", "MA Direction - Fast MA - TB1", "MA Direction - Slow MA - TB1", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 1"

input TrendBar2 = {default "MA Crossover", "MA Direction - Fast MA - TB2", "MA Direction - Slow MA - TB2", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 2"

def na = Double.NaN;
def agg = GetAggregationPeriod();
def c = if UseChartTimeFrame then close else close(Period = Aggregation);
def o = if UseChartTimeFrame then open else open(Period = Aggregation);
;
#---Color
DefineGlobalColor("green" , CreateColor(40, 138, 117));
DefineGlobalColor("Red"   , CreateColor(255, 82, 82));
#// Wave Trend - RSI

def RSIMC = RSI(price = c, Length = 14);

#// Wave Trend

def ap = if UseChartTimeFrame then hlc3 else hlc3(Period = Aggregation) ;    #  "Wave Trend - Source"
def n1 = 9;       #  "Wave Trend - WT Channel Length"
def n2 = 12;      #  "Wave Trend - WT Average Length"
def esa = ExpAverage(ap, n1);
def de = ExpAverage(AbsValue(ap - esa), n1);
def ci = (ap - esa) / (0.015 * de);
def tci = ExpAverage(ci, n2);

def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 3);

#// Wave Trend - Overbought & Oversold lines

def obLevel2 = 60;    #  "Wave Trend - WT Very Overbought")
def obLevel = 50;     #  "Wave Trend - WT Overbought")
def osLevel = -50;    #  "Wave Trend - WT Oversold")
def osLevel2 = -60;   #  "Wave Trend - WT Very Oversold")

#// Wave Trend - Conditions

def WTCross = Crosses(wt1, wt2);
def WTCrossUp = wt2 - wt1 <= 0;
def WTCrossDown = wt2 - wt1 >= 0;
def WTOverSold = wt2 <= osLevel2;
def WTOverBought = wt2 >= obLevel2;

#// MA Calculations


def MA1 = if ma1_Type == ma1_Type."SMA" then
    SimpleMovingAvg(c, ma1_Length) else ExpAverage(c, ma1_Length);

def MA2 = if ma2_Type == ma2_Type."SMA" then
    SimpleMovingAvg(c, ma2_Length) else ExpAverage(c, ma2_Length);

def MA3 = if ma3_Type == ma3_Type."SMA" then
    SimpleMovingAvg(c, ma3_Length) else ExpAverage(c, ma3_Length);

def MA4 = if ma4_Type == ma4_Type."SMA" then
    SimpleMovingAvg(c, ma4_Length) else ExpAverage(c, ma4_Length);

#// MA Crossover Condition

def MACrossover1 = if MA1 > MA2 then 1 else 0;
def MACrossover2 = if MA3 > MA4 then 1 else 0;

#// MA Direction Condition

def MA1Direction = if MA1 > MA1[1] then 1 else 0;
def MA2Direction = if MA2 > MA2[1] then 1 else 0;
def MA3Direction = if MA3 > MA3[1] then 1 else 0;
def MA4Direction = if MA4 > MA4[1] then 1 else 0;

#// MA Direction Change Condition

def MA1PositiveDirectionChange = if MA1Direction and !MA1Direction[1] then 1 else 0;
def MA2PositiveDirectionChange = if MA2Direction and !MA2Direction[1] then 1 else 0;
def MA3PositiveDirectionChange = if MA3Direction and !MA3Direction[1] then 1 else 0;
def MA4PositiveDirectionChange = if MA4Direction and !MA4Direction[1] then 1 else 0;

def MA1NegativeDirectionChange = if !MA1Direction and MA1Direction[1] then 1 else 0;
def MA2NegativeDirectionChange = if !MA2Direction and MA2Direction[1] then 1 else 0;
def MA3NegativeDirectionChange = if !MA3Direction and MA3Direction[1] then 1 else 0;
def MA4NegativeDirectionChange = if !MA4Direction and MA4Direction[1] then 1 else 0;

#// MACD and MOM & DAD - Top Dog Trading
#// Standard MACD Calculations

def MACDfastMA = 12;
def MACDslowMA = 26;
def MACDsignalSmooth = 9;

def MACDLine = ExpAverage(c, MACDfastMA) - ExpAverage(c, MACDslowMA);
def SignalLine = ExpAverage(MACDLine, MACDsignalSmooth);
def MACDHistogram = MACDLine - SignalLine;

#// MACD- Background Color Change Condition

def MACDHistogramCross = if MACDHistogram > 0 then 1 else 0;
def MACDLineOverZero = if MACDLine > 0 then 1 else 0;
def MACDLineOverZeroandHistogramCross = if MACDHistogramCross and MACDLineOverZero then 1 else 0;
def MACDLineUnderZeroandHistogramCross = if !MACDHistogramCross and !MACDLineOverZero then 1 else 0;

#// Fast MACD Calculations

def FastMACDfastMA = 8;
def FastMACDslowMA = 21;
def FastMACDsignalSmooth = 5;

def FastMACDLine = ExpAverage(c, FastMACDfastMA) - ExpAverage(c, FastMACDslowMA);
def FastSignalLine = ExpAverage(FastMACDLine, FastMACDsignalSmooth);
def FastMACDHistogram = FastMACDLine - FastSignalLine;

#// Fast MACD- Background Color Change Condition

def FastMACDHistogramCross = if FastMACDHistogram > 0 then 1 else 0;
def FastMACDLineOverZero = if FastMACDLine > 0 then 1 else 0;
def FastMACDLineOverZeroandHistogramCross = if FastMACDHistogramCross and FastMACDLineOverZero then 1 else 0;
def FastMACDLineUnderZeroandHistogramCross = if !FastMACDHistogramCross and !FastMACDLineOverZero then 1 else 0;

#// Top Dog Trading - Mom Dad Calculations

def TopDog_Fast_MA = 5;
def TopDog_Slow_MA = 20;
def TopDog_Sig = 30;

def TopDogMom = ExpAverage(c, TopDog_Fast_MA) - ExpAverage(c, TopDog_Slow_MA);
def TopDogDad = ExpAverage(TopDogMom, TopDog_Sig);

#// Top Dog Dad - Background Color Change Condition

def TopDogDadDirection = If(TopDogDad > TopDogDad[1], 1, 0);
def TopDogMomOverDad = If(TopDogMom > TopDogDad, 1, 0);
def TopDogMomOverZero = If(TopDogMom > 0, 1, 0);
def TopDogDadDirectandMomOverZero = If(TopDogDadDirection and TopDogMomOverZero, 1, 0);
def TopDogDadDirectandMomUnderZero = If(!TopDogDadDirection and !TopDogMomOverZero, 1, 0);

#////// Trend Barmeter Calculations //////
#// UCS_Trend / Trend Candles Trend Barmeter Calculations
#//UCS_Trend by ucsgears copy Trend Candles
#//Interpretation of TTM Trend bars. It is really close to the actual.

def haclose = if UseChartTimeFrame then ohlc4 else ohlc4(Period = Aggregation);
def haopen = if IsNaN(haopen[1]) then (o + c) / 2 else (haopen[1] + haclose[1]) / 2;

def ccolor = If(haclose - haopen > 0, 1, 0);

def inside6 = If(haopen <= Max(haopen[6], haclose[6]) and haopen >= Min(haopen[6], haclose[6]) and
   haclose <= Max(haopen[6], haclose[6]) and haclose >= Min(haopen[6], haclose[6]), 1, 0);

def inside5 = If(haopen <= Max(haopen[5], haclose[5]) and haopen >= Min(haopen[5], haclose[5]) and
   haclose <= Max(haopen[5], haclose[5]) and haclose >= Min(haopen[5], haclose[5]), 1, 0);

def inside4 = If(haopen <= Max(haopen[4], haclose[4]) and haopen >= Min(haopen[4], haclose[4]) and
   haclose <= Max(haopen[4], haclose[4]) and haclose >= Min(haopen[4], haclose[4]), 1, 0);

def inside3 = If(haopen <= Max(haopen[3], haclose[3]) and haopen >= Min(haopen[3], haclose[3]) and
   haclose <= Max(haopen[3], haclose[3]) and haclose >= Min(haopen[3], haclose[3]), 1, 0);

def inside2 = If(haopen <= Max(haopen[2], haclose[2]) and haopen >= Min(haopen[2], haclose[2]) and
   haclose <= Max(haopen[2], haclose[2]) and haclose >= Min(haopen[2], haclose[2]), 1, 0);

def inside1 = If(haopen <= Max(haopen[1], haclose[1]) and haopen >= Min(haopen[1], haclose[1]) and
   haclose <= Max(haopen[1], haclose[1]) and haclose >= Min(haopen[1], haclose[1]), 1, 0);

def colorvalue = if inside6 then ccolor[6] else if inside5 then ccolor[5] else if inside4 then ccolor[4] else if inside3 then ccolor[3] else if inside2 then ccolor[2] else if inside1 then ccolor[1] else ccolor;

def TrendBarTrend_Candle = if colorvalue then 1 else 0;

#// RSI 5 Trend Barmeter Calculations

def RSI5 = RSI(Price = c, Length = 5);
def RSI5Above50 = if RSI5 > 50 then 1 else 0;
def RSI5Color = if RSI5Above50 then 1 else 0;# ? #288a75 : color.red

#// RSI 5 Trend Barmeter Calculations

def RSI13 = RSI(Price = c, Length = 13);

#// Linear Regression Calculation For RSI Signal Line

def SignalLineLength1 = 21;

def x = BarNumber();
def y = RSI13;
def x_ = SimpleMovingAvg(x, SignalLineLength1);
def y_ = SimpleMovingAvg(y, SignalLineLength1);
def mx = StDev(x, SignalLineLength1);
def my = StDev(y, SignalLineLength1);
def corr = Correlation(x, y, SignalLineLength1);
def slope = corr * (my / mx);
def inter = y_ - slope * x_;
def LinReg1 = x * slope + inter;

def RSISigDirection = If(LinReg1 > LinReg1[1], 1, 0);
def RSISigCross = If(RSI13 > LinReg1, 1, 0);
def RSI13Above50 = If(RSI13 > 50, 1, 0);

#// Trend Barmeter Color Calculation

#RSI13Color = RSI13Above50 ? #288a75 : color.red
def TrendBarRSI13Color = If(RSI13Above50, 1, 0);
def TrendBarRSISigCrossColor = If(RSISigCross, 1, 0);
def TrendBarMACDColor = If(MACDHistogramCross, 1, 0);
def TrendBarFastMACDColor = If(FastMACDHistogramCross, 1, 0);
def TrendBarMACrossColor = If(MACrossover1, 1, 0);
def TrendBarMomOverDadColor = If(TopDogMomOverDad, 1, 0);
def TrendBarDadDirectionColor = If(TopDogDadDirection, 1, 0);

def TrendBar1Result = if TrendMeter1 ==  TrendMeter1."MA Crossover" then MACrossover1 else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar2Result = if TrendMeter2 == TrendMeter2."MA Crossover" then MACrossover1 else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar3Result = if TrendMeter3 == TrendMeter3."MA Crossover" then MACrossover1 else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else na;


def TrendBars2Positive = If(TrendBar1Result and TrendBar2Result or TrendBar1Result and
                            TrendBar3Result or TrendBar2Result and TrendBar3Result, 1, 0);

def TrendBars2Negative = If(!TrendBar1Result and !TrendBar2Result or !TrendBar1Result and
                            !TrendBar3Result or !TrendBar2Result and !TrendBar3Result, 1, 0);

def TrendBars3Positive = If(TrendBar1Result and TrendBar2Result and TrendBar3Result, 1, 0);
def TrendBars3Negative = If(!TrendBar1Result and !TrendBar2Result and !TrendBar3Result, 1, 0);

#// Signal Filters

def FilterXUp = FastMACDHistogramCross and ExpAverage(c, 15) > ExpAverage(c, 15)[1];
def FilterXDown = !FastMACDHistogramCross and ExpAverage(c, 15) < ExpAverage(c, 15)[1];

def TrendFilterPlus = If(ExpAverage(c, 15) > ExpAverage(c, 20) and ExpAverage(c, 20) > ExpAverage(c, 30) and ExpAverage(c, 30) > ExpAverage(c, 40) and ExpAverage(c, 40) > ExpAverage(c, 50), 1, 0);

def TrendFilterMinus = If(ExpAverage(c, 15) < ExpAverage(c, 20) and ExpAverage(c, 20) < ExpAverage(c, 30) and ExpAverage(c, 30) < ExpAverage(c, 40) and ExpAverage(c, 40) < ExpAverage(c, 50), 1, 0);

#// // Wave Trend - Conditions

def MSBar1PositiveWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter1 == Filter1."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar1NegativeWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter1 == Filter1."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else
   WTCross and WTCrossDown;

def MSBar2PositiveWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter2 == Filter2."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar2NegativeWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter2 == Filter2."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else WTCross and WTCrossDown;

#////////////////////////

def BackgroundColorChangePositive = TrendBars3Positive and !TrendBars3Positive[1];
def BackgroundColorChangeNegative = TrendBars3Negative and !TrendBars3Negative[1];

#// Signals Color Calculations

def MSBar1Color = if MSBar1PositiveWaveTrendSignal then 1 else 
   if MSBar1NegativeWaveTrendSignal then -1 else na;#

def MSBar2Color = if BackgroundColorChangePositive then 1 else
   if BackgroundColorChangeNegative then -1 else na;

#// Trend Barmeter Color Assignments

def TrendBar1Color =
if TrendMeter1 == TrendMeter1."N/A" then na else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter1 == TrendMeter1."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar2Color =
if TrendMeter2 == TrendMeter2."N/A" then na else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter2 == TrendMeter2."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar3Color =
if TrendMeter3 == TrendMeter3."N/A" then na else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter3 == TrendMeter3."MA Crossover" then TrendBarMACrossColor else na;


def CrossoverType2 =
if TrendBar1 == TrendBar1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar1 == TrendBar1."MACD Crossover" then MACDHistogramCross else if
   TrendBar1 == TrendBar1."MA Direction - Fast MA - TB1" then MA1Direction else if
   TrendBar1 == TrendBar1."MA Direction - Slow MA - TB1" then MA2Direction else MACrossover1;

def TrendBar4Color1 = if TrendBar1 == TrendBar1."N/A" then na else
                      if CrossoverType2 then 1 else 0;

def CrossoverType3 =
if TrendBar2 == TrendBar2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar2 == TrendBar2."MACD Crossover" then MACDHistogramCross else if
   TrendBar2 == TrendBar2."MA Direction - Fast MA - TB2" then MA3Direction else if
   TrendBar2 == TrendBar2."MA Direction - Slow MA - TB2" then MA4Direction else MACrossover2;

def TrendBar5Color1 = if TrendBar2 == TrendBar2."N/A" then na else
                      if CrossoverType3 then 1 else 0;

#// Momentum Setup Plots

plot Signals1 = If(IsNaN(c) or IsNaN(MSBar1Color), na, If(ShowTrendBar and WaveTrendSignalLine, 129, na));    # "Signals 1 - Wave Trend Signals"
Signals1.SetPaintingStrategy(PaintingStrategy.SQUARES);
Signals1.AssignValueColor(if MSBar1Color > 0 then GlobalColor("green") else GlobalColor("RED"));

plot Signals2 = If(IsNaN(c) or IsNaN(MSBar2Color), na, If(ShowTrendBar and TrendMeterLine, 126, na));    # "Signals 2 - All 3 Trend Meters Now Align"
Signals2.SetPaintingStrategy(PaintingStrategy.POINTS);
Signals2.AssignValueColor(if MSBar2Color > 0 then GlobalColor("green") else GlobalColor("RED"));

#// Trend Barmeter Plots

plot TM1 = If(IsNaN(c), na, If(ShowTrendBar, 123, na)); # "Trend Meter 1"
TM1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM1.AssignValueColor(if TrendBar1Color then GlobalColor("green") else GlobalColor("RED"));

plot TM2 = If(IsNaN(c), na, If(ShowTrendBar, 120.5, na));# "Trend Meter 2"
TM2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM2.AssignValueColor(if TrendBar2Color then GlobalColor("green") else GlobalColor("RED"));

plot TM3 = If(IsNaN(c), na, If(ShowTrendBar, 118, na));# "Trend Meter 3"
TM3.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM3.AssignValueColor(if TrendBar3Color then GlobalColor("green") else GlobalColor("RED"));

plot ThinLine = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar2 == TrendBar2."N/A"), 115, na));
ThinLine.AssignValueColor(if TrendBar4Color1 then Color.GREEN else Color.RED);
ThinLine.SetLineWeight(2);

plot ThikLine = If(IsNaN(c), na, If(ShowTrendBar and TrendBar2 == TrendBar2."N/A" and !(TrendBar1 == TrendBar1."N/A"), 107.25, na));
ThikLine.AssignValueColor(if TrendBar4Color1 then  Color.GREEN else Color.RED);
ThikLine.SetLineWeight(5);

plot ThinLine2 = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar1 == TrendBar1."N/A"), 112.5, na));
ThinLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThinLine2.SetLineWeight(2);

plot ThikLine2 = If(IsNaN(c), na, If(ShowTrendBar and TrendBar1 == TrendBar1."N/A" and !(TrendBar2 == TrendBar2."N/A"), 107.25, na));
ThikLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThikLine2.SetLineWeight(5);

#--- Stratgy Line
def EMA1 = ExpAverage(c,SignalMALength1);
def EMA2 = ExpAverage(c,SignalMALength2);
def diff = c - o;
def UpperBand = StDev(diff, VolatilityLength);
def LowerBand = StDev(diff, VolatilityLength) * -1;
def Long = Signals2 and MSBar2Color>0 and ThinLine and ThinLine2 and TrendBar4Color1 and TrendBar5Color1 and diff>=UpperBand and EMA1>EMA2;
def short = Signals2 and MSBar2Color<0 and ThinLine and ThinLine2 and !TrendBar4Color1 and !TrendBar5Color1 and diff<=LowerBand and EMA1<EMA2;

plot LongSignal = if Long then 126 else na;
plot ShortSignal = if short then 126 else na;
LongSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
LongSignal.SetDefaultColor(Color.GREEN);
LongSignal.SetLineWeight(5);
ShortSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortSignal.SetDefaultColor(Color.RED);
ShortSignal.SetLineWeight(5);

#// Background Highlights
AddCloud(if TrendBars3Positive then Double.NEGATIVE_INFINITY else if TrendBars3Negative then Double.POSITIVE_INFINITY else na, if TrendBars3Positive then Double.POSITIVE_INFINITY else if TrendBars3Negative then Double.NEGATIVE_INFINITY else na, Color.DARK_RED, Color.DARK_GREEN);

#--- BarColor
AssignPriceColor(if !ColorBars then Color.CURRENT else
    if TrendBars3Positive and CrossoverType2 and CrossoverType3 then Color.GREEN else
    if TrendBars3Positive and (!CrossoverType2 or !CrossoverType3) then Color.DARK_GREEN else
    if TrendBars3Negative and !CrossoverType2 and !CrossoverType3 then Color.RED else
    if TrendBars3Negative and (!CrossoverType2 or !CrossoverType3) then Color.DARK_RED else Color.GRAY);
#---END Code
 
Last edited:

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

converted the code below. Moreover, I added signal based on the provided YouTube. Enjoy :)

CSS:
#// Created By Lij_MC
#// Use as a supplementary Indicator to confirm your entries, but it is as good on it's own.
#// The indicator consists of 3 different Trend Meters and a Trend Bar which are used to confirm trend
#// As a bonus Wave Trend Signals are marked as well, these are very powerful however please use with caution
#// How to Use
#// Look for Support or Resistance Levels for price to be attracted to
#// Find confluence with other indicators
#// Enter Long above the Setup Bar
#// Enter Short Below the Setup Bar
#study(title="Trend Meter")
# Converted and mod by Sam4Cok@Samer800 - 10/2022
declare lower;
#// Inputs / Menus
#// Trend Bar / Meter - Inputs / Menus
input VolatilityLength = 100;
input SignalMALength1 = 50;
input SignalMALength2 = 200;
input ShowTrendBar = yes;
input UseChartTimeFrame = yes;
input Aggregation = AggregationPeriod.HOUR;
#// MA Inputs
input ma1_Length = 5;    # 'Fast MA'
input ma1_Type   = {default "EMA", "SMA"};   # "TB1 Fast"
input ma2_Length = 11;   # 'Slow MA'
input ma2_Type   = {default "EMA", "SMA"};   # "TB1 Slow"
input ma3_Length = 13;   # 'Fast MA'
input ma3_Type   = { default "EMA", "SMA"};  # "TB2 Fast"
input ma4_Length = 36;   # 'Slow MA'
input ma4_Type   = {"EMA", default "SMA"};   # "TB2 Slow"
#--Trend inputs
input WaveTrendSignalLine = no;    # "Wave Trend Filtered by Trend"
input TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input Filter2 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input TrendMeter1 = {"MACD Crossover - 12, 26, 9", default "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter1"
input TrendMeter2 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", default "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 2"

input TrendMeter3 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", default "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 3"

input TrendBar1 = {default "MA Crossover", "MA Direction - Fast MA - TB1", "MA Direction - Slow MA - TB1", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 1"

input TrendBar2 = {default "MA Crossover", "MA Direction - Fast MA - TB2", "MA Direction - Slow MA - TB2", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 2"

def na = Double.NaN;
#def mClose = if UseChartTimeFrame then Close(period=GetAggregationPeriod()) else close(period=AggregationPeriod);
def agg = GetAggregationPeriod();
def c = if UseChartTimeFrame then close else close(Period = Aggregation);
def o = if UseChartTimeFrame then open else open(Period = Aggregation);
;
#---Color
DefineGlobalColor("green" , CreateColor(40, 138, 117));
DefineGlobalColor("Red"   , CreateColor(255, 82, 82));
#// Wave Trend - RSI

def RSIMC = RSI(price = c, Length = 14);

#// Wave Trend

def ap = if UseChartTimeFrame then hlc3 else hlc3(Period = Aggregation) ;    #  "Wave Trend - Source"
def n1 = 9;       #  "Wave Trend - WT Channel Length"
def n2 = 12;      #  "Wave Trend - WT Average Length"
def esa = ExpAverage(ap, n1);
def de = ExpAverage(AbsValue(ap - esa), n1);
def ci = (ap - esa) / (0.015 * de);
def tci = ExpAverage(ci, n2);

def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 3);

#// Wave Trend - Overbought & Oversold lines

def obLevel2 = 60;    #  "Wave Trend - WT Very Overbought")
def obLevel = 50;     #  "Wave Trend - WT Overbought")
def osLevel = -50;    #  "Wave Trend - WT Oversold")
def osLevel2 = -60;   #  "Wave Trend - WT Very Oversold")

#// Wave Trend - Conditions

def WTCross = Crosses(wt1, wt2);
def WTCrossUp = wt2 - wt1 <= 0;
def WTCrossDown = wt2 - wt1 >= 0;
def WTOverSold = wt2 <= osLevel2;
def WTOverBought = wt2 >= obLevel2;

#// MA Calculations


def MA1 = if ma1_Type == ma1_Type."SMA" then
    SimpleMovingAvg(c, ma1_Length) else ExpAverage(c, ma1_Length);

def MA2 = if ma2_Type == ma2_Type."SMA" then
    SimpleMovingAvg(c, ma2_Length) else ExpAverage(c, ma2_Length);

def MA3 = if ma3_Type == ma3_Type."SMA" then
    SimpleMovingAvg(c, ma3_Length) else ExpAverage(c, ma3_Length);

def MA4 = if ma4_Type == ma4_Type."SMA" then
    SimpleMovingAvg(c, ma4_Length) else ExpAverage(c, ma4_Length);

#// MA Crossover Condition

def MACrossover1 = if MA1 > MA2 then 1 else 0;
def MACrossover2 = if MA3 > MA4 then 1 else 0;

#// MA Direction Condition

def MA1Direction = if MA1 > MA1[1] then 1 else 0;
def MA2Direction = if MA2 > MA2[1] then 1 else 0;
def MA3Direction = if MA3 > MA3[1] then 1 else 0;
def MA4Direction = if MA4 > MA4[1] then 1 else 0;

#// MA Direction Change Condition

def MA1PositiveDirectionChange = if MA1Direction and !MA1Direction[1] then 1 else 0;
def MA2PositiveDirectionChange = if MA2Direction and !MA2Direction[1] then 1 else 0;
def MA3PositiveDirectionChange = if MA3Direction and !MA3Direction[1] then 1 else 0;
def MA4PositiveDirectionChange = if MA4Direction and !MA4Direction[1] then 1 else 0;

def MA1NegativeDirectionChange = if !MA1Direction and MA1Direction[1] then 1 else 0;
def MA2NegativeDirectionChange = if !MA2Direction and MA2Direction[1] then 1 else 0;
def MA3NegativeDirectionChange = if !MA3Direction and MA3Direction[1] then 1 else 0;
def MA4NegativeDirectionChange = if !MA4Direction and MA4Direction[1] then 1 else 0;

#// MACD and MOM & DAD - Top Dog Trading
#// Standard MACD Calculations

def MACDfastMA = 12;
def MACDslowMA = 26;
def MACDsignalSmooth = 9;

def MACDLine = ExpAverage(c, MACDfastMA) - ExpAverage(c, MACDslowMA);
def SignalLine = ExpAverage(MACDLine, MACDsignalSmooth);
def MACDHistogram = MACDLine - SignalLine;

#// MACD- Background Color Change Condition

def MACDHistogramCross = if MACDHistogram > 0 then 1 else 0;
def MACDLineOverZero = if MACDLine > 0 then 1 else 0;
def MACDLineOverZeroandHistogramCross = if MACDHistogramCross and MACDLineOverZero then 1 else 0;
def MACDLineUnderZeroandHistogramCross = if !MACDHistogramCross and !MACDLineOverZero then 1 else 0;

#// Fast MACD Calculations

def FastMACDfastMA = 8;
def FastMACDslowMA = 21;
def FastMACDsignalSmooth = 5;

def FastMACDLine = ExpAverage(c, FastMACDfastMA) - ExpAverage(c, FastMACDslowMA);
def FastSignalLine = ExpAverage(FastMACDLine, FastMACDsignalSmooth);
def FastMACDHistogram = FastMACDLine - FastSignalLine;

#// Fast MACD- Background Color Change Condition

def FastMACDHistogramCross = if FastMACDHistogram > 0 then 1 else 0;
def FastMACDLineOverZero = if FastMACDLine > 0 then 1 else 0;
def FastMACDLineOverZeroandHistogramCross = if FastMACDHistogramCross and FastMACDLineOverZero then 1 else 0;
def FastMACDLineUnderZeroandHistogramCross = if !FastMACDHistogramCross and !FastMACDLineOverZero then 1 else 0;

#// Top Dog Trading - Mom Dad Calculations

def TopDog_Fast_MA = 5;
def TopDog_Slow_MA = 20;
def TopDog_Sig = 30;

def TopDogMom = ExpAverage(c, TopDog_Fast_MA) - ExpAverage(c, TopDog_Slow_MA);
def TopDogDad = ExpAverage(TopDogMom, TopDog_Sig);

#// Top Dog Dad - Background Color Change Condition

def TopDogDadDirection = If(TopDogDad > TopDogDad[1], 1, 0);
def TopDogMomOverDad = If(TopDogMom > TopDogDad, 1, 0);
def TopDogMomOverZero = If(TopDogMom > 0, 1, 0);
def TopDogDadDirectandMomOverZero = If(TopDogDadDirection and TopDogMomOverZero, 1, 0);
def TopDogDadDirectandMomUnderZero = If(!TopDogDadDirection and !TopDogMomOverZero, 1, 0);

#////// Trend Barmeter Calculations //////
#// UCS_Trend / Trend Candles Trend Barmeter Calculations
#//UCS_Trend by ucsgears copy Trend Candles
#//Interpretation of TTM Trend bars. It is really close to the actual.

def haclose = if UseChartTimeFrame then ohlc4 else ohlc4(Period = Aggregation);
def haopen = if IsNaN(haopen[1]) then (o + c) / 2 else (haopen[1] + haclose[1]) / 2;

def ccolor = If(haclose - haopen > 0, 1, 0);

def inside6 = If(haopen <= Max(haopen[6], haclose[6]) and haopen >= Min(haopen[6], haclose[6]) and
   haclose <= Max(haopen[6], haclose[6]) and haclose >= Min(haopen[6], haclose[6]), 1, 0);

def inside5 = If(haopen <= Max(haopen[5], haclose[5]) and haopen >= Min(haopen[5], haclose[5]) and
   haclose <= Max(haopen[5], haclose[5]) and haclose >= Min(haopen[5], haclose[5]), 1, 0);

def inside4 = If(haopen <= Max(haopen[4], haclose[4]) and haopen >= Min(haopen[4], haclose[4]) and
   haclose <= Max(haopen[4], haclose[4]) and haclose >= Min(haopen[4], haclose[4]), 1, 0);

def inside3 = If(haopen <= Max(haopen[3], haclose[3]) and haopen >= Min(haopen[3], haclose[3]) and
   haclose <= Max(haopen[3], haclose[3]) and haclose >= Min(haopen[3], haclose[3]), 1, 0);

def inside2 = If(haopen <= Max(haopen[2], haclose[2]) and haopen >= Min(haopen[2], haclose[2]) and
   haclose <= Max(haopen[2], haclose[2]) and haclose >= Min(haopen[2], haclose[2]), 1, 0);

def inside1 = If(haopen <= Max(haopen[1], haclose[1]) and haopen >= Min(haopen[1], haclose[1]) and
   haclose <= Max(haopen[1], haclose[1]) and haclose >= Min(haopen[1], haclose[1]), 1, 0);

def colorvalue = if inside6 then ccolor[6] else if inside5 then ccolor[5] else if inside4 then ccolor[4] else if inside3 then ccolor[3] else if inside2 then ccolor[2] else if inside1 then ccolor[1] else ccolor;

def TrendBarTrend_Candle = if colorvalue then 1 else 0;

#// RSI 5 Trend Barmeter Calculations

def RSI5 = RSI(Price = c, Length = 5);
def RSI5Above50 = if RSI5 > 50 then 1 else 0;
def RSI5Color = if RSI5Above50 then 1 else 0;# ? #288a75 : color.red

#// RSI 5 Trend Barmeter Calculations

def RSI13 = RSI(Price = c, Length = 13);

#// Linear Regression Calculation For RSI Signal Line

def SignalLineLength1 = 21;

def x = BarNumber();
def y = RSI13;
def x_ = SimpleMovingAvg(x, SignalLineLength1);
def y_ = SimpleMovingAvg(y, SignalLineLength1);
def mx = StDev(x, SignalLineLength1);
def my = StDev(y, SignalLineLength1);
def corr = Correlation(x, y, SignalLineLength1);
def slope = corr * (my / mx);
def inter = y_ - slope * x_;
def LinReg1 = x * slope + inter;

def RSISigDirection = If(LinReg1 > LinReg1[1], 1, 0);
def RSISigCross = If(RSI13 > LinReg1, 1, 0);
def RSI13Above50 = If(RSI13 > 50, 1, 0);

#// Trend Barmeter Color Calculation

#RSI13Color = RSI13Above50 ? #288a75 : color.red
def TrendBarRSI13Color = If(RSI13Above50, 1, 0);
def TrendBarRSISigCrossColor = If(RSISigCross, 1, 0);
def TrendBarMACDColor = If(MACDHistogramCross, 1, 0);
def TrendBarFastMACDColor = If(FastMACDHistogramCross, 1, 0);
def TrendBarMACrossColor = If(MACrossover1, 1, 0);
def TrendBarMomOverDadColor = If(TopDogMomOverDad, 1, 0);
def TrendBarDadDirectionColor = If(TopDogDadDirection, 1, 0);

def TrendBar1Result = if TrendMeter1 ==  TrendMeter1."MA Crossover" then MACrossover1 else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar2Result = if TrendMeter2 == TrendMeter2."MA Crossover" then MACrossover1 else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar3Result = if TrendMeter3 == TrendMeter3."MA Crossover" then MACrossover1 else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else na;


def TrendBars2Positive = If(TrendBar1Result and TrendBar2Result or TrendBar1Result and
                            TrendBar3Result or TrendBar2Result and TrendBar3Result, 1, 0);

def TrendBars2Negative = If(!TrendBar1Result and !TrendBar2Result or !TrendBar1Result and
                            !TrendBar3Result or !TrendBar2Result and !TrendBar3Result, 1, 0);

def TrendBars3Positive = If(TrendBar1Result and TrendBar2Result and TrendBar3Result, 1, 0);
def TrendBars3Negative = If(!TrendBar1Result and !TrendBar2Result and !TrendBar3Result, 1, 0);

#// Signal Filters

def FilterXUp = FastMACDHistogramCross and ExpAverage(c, 15) > ExpAverage(c, 15)[1];
def FilterXDown = !FastMACDHistogramCross and ExpAverage(c, 15) < ExpAverage(c, 15)[1];

def TrendFilterPlus = If(ExpAverage(c, 15) > ExpAverage(c, 20) and ExpAverage(c, 20) > ExpAverage(c, 30) and ExpAverage(c, 30) > ExpAverage(c, 40) and ExpAverage(c, 40) > ExpAverage(c, 50), 1, 0);

def TrendFilterMinus = If(ExpAverage(c, 15) < ExpAverage(c, 20) and ExpAverage(c, 20) < ExpAverage(c, 30) and ExpAverage(c, 30) < ExpAverage(c, 40) and ExpAverage(c, 40) < ExpAverage(c, 50), 1, 0);

#// // Wave Trend - Conditions

def MSBar1PositiveWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter1 == Filter1."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar1NegativeWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter1 == Filter1."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else
   WTCross and WTCrossDown;

def MSBar2PositiveWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter2 == Filter2."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar2NegativeWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter2 == Filter2."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else WTCross and WTCrossDown;

#////////////////////////

def BackgroundColorChangePositive = TrendBars3Positive and !TrendBars3Positive[1];
def BackgroundColorChangeNegative = TrendBars3Negative and !TrendBars3Negative[1];

#// Signals Color Calculations

def MSBar1Color = if MSBar1PositiveWaveTrendSignal then 1 else
   if MSBar1NegativeWaveTrendSignal then -1 else na;#

def MSBar2Color = if BackgroundColorChangePositive then 1 else
   if BackgroundColorChangeNegative then -1 else na;

#// Trend Barmeter Color Assignments

def TrendBar1Color =
if TrendMeter1 == TrendMeter1."N/A" then na else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter1 == TrendMeter1."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar2Color =
if TrendMeter2 == TrendMeter2."N/A" then na else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter2 == TrendMeter2."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar3Color =
if TrendMeter3 == TrendMeter3."N/A" then na else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter3 == TrendMeter3."MA Crossover" then TrendBarMACrossColor else na;


def CrossoverType2 =
if TrendBar1 == TrendBar1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar1 == TrendBar1."MACD Crossover" then MACDHistogramCross else if
   TrendBar1 == TrendBar1."MA Direction - Fast MA - TB1" then MA1Direction else if
   TrendBar1 == TrendBar1."MA Direction - Slow MA - TB1" then MA2Direction else MACrossover1;

def TrendBar4Color1 = if TrendBar1 == TrendBar1."N/A" then na else
                      if CrossoverType2 then 1 else 0;

def CrossoverType3 =
if TrendBar2 == TrendBar2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar2 == TrendBar2."MACD Crossover" then MACDHistogramCross else if
   TrendBar2 == TrendBar2."MA Direction - Fast MA - TB2" then MA3Direction else if
   TrendBar2 == TrendBar2."MA Direction - Slow MA - TB2" then MA4Direction else MACrossover2;

def TrendBar5Color1 = if TrendBar2 == TrendBar2."N/A" then na else
                      if CrossoverType3 then 1 else 0;

#// Momentum Setup Plots

plot Signals1 = If(IsNaN(c) or IsNaN(MSBar1Color), na, If(ShowTrendBar and WaveTrendSignalLine, 129, na));    # "Signals 1 - Wave Trend Signals"
Signals1.SetPaintingStrategy(PaintingStrategy.SQUARES);
Signals1.AssignValueColor(if MSBar1Color > 0 then GlobalColor("green") else GlobalColor("RED"));

plot Signals2 = If(IsNaN(c) or IsNaN(MSBar2Color), na, If(ShowTrendBar and TrendMeterLine, 126, na));    # "Signals 2 - All 3 Trend Meters Now Align"
Signals2.SetPaintingStrategy(PaintingStrategy.POINTS);
Signals2.AssignValueColor(if MSBar2Color > 0 then GlobalColor("green") else GlobalColor("RED"));

#// Trend Barmeter Plots

plot TM1 = If(IsNaN(c), na, If(ShowTrendBar, 123, na)); # "Trend Meter 1"
TM1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM1.AssignValueColor(if TrendBar1Color then GlobalColor("green") else GlobalColor("RED"));

plot TM2 = If(IsNaN(c), na, If(ShowTrendBar, 120.5, na));# "Trend Meter 2"
TM2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM2.AssignValueColor(if TrendBar2Color then GlobalColor("green") else GlobalColor("RED"));

plot TM3 = If(IsNaN(c), na, If(ShowTrendBar, 118, na));# "Trend Meter 3"
TM3.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM3.AssignValueColor(if TrendBar3Color then GlobalColor("green") else GlobalColor("RED"));

plot ThinLine = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar2 == TrendBar2."N/A"), 115, na));
ThinLine.AssignValueColor(if TrendBar4Color1 then Color.GREEN else Color.RED);
ThinLine.SetLineWeight(2);

plot ThikLine = If(IsNaN(c), na, If(ShowTrendBar and TrendBar2 == TrendBar2."N/A" and !(TrendBar1 == TrendBar1."N/A"), 107.25, na));
ThikLine.AssignValueColor(if TrendBar4Color1 then  Color.GREEN else Color.RED);
ThikLine.SetLineWeight(5);

plot ThinLine2 = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar1 == TrendBar1."N/A"), 112.5, na));
ThinLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThinLine2.SetLineWeight(2);

plot ThikLine2 = If(IsNaN(c), na, If(ShowTrendBar and TrendBar1 == TrendBar1."N/A" and !(TrendBar2 == TrendBar2."N/A"), 107.25, na));
ThikLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThikLine2.SetLineWeight(5);

#--- Stratgy Line
def EMA1 = ExpAverage(c,SignalMALength1);
def EMA2 = ExpAverage(c,SignalMALength2);
def diff = c - o;
def UpperBand = StDev(diff, VolatilityLength);
def LowerBand = StDev(diff, VolatilityLength) * -1;
def Long = Signals2 and MSBar2Color>0 and ThinLine and ThinLine2 and TrendBar4Color1 and TrendBar5Color1 and diff>=UpperBand and EMA1>EMA2;
def short = Signals2 and MSBar2Color<0 and ThinLine and ThinLine2 and !TrendBar4Color1 and !TrendBar5Color1 and diff<=LowerBand and EMA1<EMA2;

plot LongSignal = if Long then 126 else na;
plot ShortSignal = if short then 126 else na;
LongSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
LongSignal.SetDefaultColor(Color.GREEN);
LongSignal.SetLineWeight(5);
ShortSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortSignal.SetDefaultColor(Color.RED);
ShortSignal.SetLineWeight(5);
#// Background Highlights

AddCloud(if TrendBars3Positive then Double.NEGATIVE_INFINITY else if TrendBars3Negative then Double.POSITIVE_INFINITY else na, if TrendBars3Positive then Double.POSITIVE_INFINITY else if TrendBars3Negative then Double.NEGATIVE_INFINITY else na, Color.DARK_RED, Color.DARK_GREEN);

#---END Code
Nice indicator. How do you tend to use it? What time frames work best for you?
 
Nice indicator. How do you tend to use it? What time frames work best for you?
This is another awesome conversion by @samer800. It was done per members' requests.
You can read more and find the video here:
https://usethinkscript.com/threads/converted-tradingview-trend-meter.11113/
and here:
https://www.tradingview.com/script/Ciurp4Qn-Trend-Meter/

This works on all timeframes.
How to use:
Use as a supplementary Indicator to confirm your entries, but it is as good on it's own.
#// The indicator consists of 3 different Trend Meters and a Trend Bar which are used to confirm trend
#// As a bonus Wave Trend Signals are marked as well, these are very powerful however please use with caution
#// How to Use
#// Look for Support or Resistance Levels for price to be attracted to
#// Find confluence with other indicators
#// Enter Long above the Setup Bar
#// Enter Short Below the Setup Bar
 
trend01.jpg


LongSignal sometimes do not appear as circled in screenshot. 4 green dots and 2 green lines. I am assuming this occurs with ShortSignal as well.

I'm on 3m tf if that helps.
 
Last edited by a moderator:
trend01.jpg


LongSignal sometimes do not appear as circled in screenshot. 4 green dots and 2 green lines. I am assuming this occurs with ShortSignal as well.

I'm on 3m tf if that helps.
bigger points green and red based on the strategy provided in the YouTube.
long signal, when trend meter all green + EMA1 > EMA2 + Volatility above the upper band.
Short Signal, when trend meter all red + EMA1 < EMA2 + Volatility below the lowerr band
 
Samer800 - thanks for this.
Question for you or the group: what's the best way to find good candidates for this? My ideas so far:
1)tried to create a scan for the big dot (long and short) but the script is too complex to allow it
2)my next thought was to create a scan for the volatility "spike" crossing above P1 or below P2 with the idea being you could then look at those tickers and see if the other conditions for the TrendMeter are also simultaneously true. Alas, the Vol Osc script also is too complex to allow this.
3)so basically, my only remaining idea is to have the indicator running on multiple favorite tickers using a flex grid and watch for the signal to appear on one of them

Anyone have other ideas?
 
Thanks @samer800! I've been playing around this morning and I am seeing something that I cannot explain. Looking at the code, the input "aggregation" is only ever utilized when "use chart time frame" is set to "No". I am looking at 30 min /ES with "use chart timeframe = yes" and "aggregation = 30m" and the indicator looks great. When I change to "aggregation = 1min" the entire lower window goes blank. I feel that there's a ToS lesson for me hiding somewhere here. Any ideas? TIA!
 
Thanks @samer800! I've been playing around this morning and I am seeing something that I cannot explain. Looking at the code, the input "aggregation" is only ever utilized when "use chart time frame" is set to "No". I am looking at 30 min /ES with "use chart timeframe = yes" and "aggregation = 30m" and the indicator looks great. When I change to "aggregation = 1min" the entire lower window goes blank. I feel that there's a ToS lesson for me hiding somewhere here. Any ideas? TIA!
If you're referring to trying to use a 1min aggregation while on a 30min chart, that's impossible -- with timeframe aggregations you can only aggregate at >= the current chart time. So if you're on a 30min chart, you'll only be able to look at 30min, 1hr, 4hr, etc. aggregations on ToS. Trying to look at lower aggregations will cause any aggregate study to blank out as you've mentioned.
 
Per member request: https://usethinkscript.com/threads/converted-tradingview-trend-meter.11113/
converted the code below. Moreover, I added signal based on the provided YouTube. Enjoy :)

CSS:
#// Created By Lij_MC
#// Use as a supplementary Indicator to confirm your entries, but it is as good on it's own.
#// The indicator consists of 3 different Trend Meters and a Trend Bar which are used to confirm trend
#// As a bonus Wave Trend Signals are marked as well, these are very powerful however please use with caution
#// How to Use
#// Look for Support or Resistance Levels for price to be attracted to
#// Find confluence with other indicators
#// Enter Long above the Setup Bar
#// Enter Short Below the Setup Bar
#study(title="Trend Meter")
# Converted and mod by Sam4Cok@Samer800 - 10/2022
declare lower;
#// Inputs / Menus
#// Trend Bar / Meter - Inputs / Menus
input VolatilityLength = 100;
input SignalMALength1 = 50;
input SignalMALength2 = 200;
input ShowTrendBar = yes;
input UseChartTimeFrame = yes;
input Aggregation = AggregationPeriod.HOUR;
#// MA Inputs
input ma1_Length = 5;    # 'Fast MA'
input ma1_Type   = {default "EMA", "SMA"};   # "TB1 Fast"
input ma2_Length = 11;   # 'Slow MA'
input ma2_Type   = {default "EMA", "SMA"};   # "TB1 Slow"
input ma3_Length = 13;   # 'Fast MA'
input ma3_Type   = { default "EMA", "SMA"};  # "TB2 Fast"
input ma4_Length = 36;   # 'Slow MA'
input ma4_Type   = {"EMA", default "SMA"};   # "TB2 Slow"
#--Trend inputs
input WaveTrendSignalLine = no;    # "Wave Trend Filtered by Trend"
input TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input Filter2 = {"N/A", default "Trend Filter", "Filter X", "Filter X + Trend Filter"};#WT Signals
input TrendMeter1 = {"MACD Crossover - 12, 26, 9", default "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter1"
input TrendMeter2 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", default "RSI 13: > or < 50", "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 2"

input TrendMeter3 = {"MACD Crossover - 12, 26, 9", "MACD Crossover - Fast - 8, 21, 5", "Mom Dad Cross (Top Dog Trading)", "RSI Signal Line Cross - RSI 13, Sig 21", "RSI 13: > or < 50", default "RSI 5: > or < 50", "Trend Candles", "DAD Direction (Top Dog Trading)", "MA Crossover", "N/A"};#"Trend Meter 3"

input TrendBar1 = {default "MA Crossover", "MA Direction - Fast MA - TB1", "MA Direction - Slow MA - TB1", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 1"

input TrendBar2 = {default "MA Crossover", "MA Direction - Fast MA - TB2", "MA Direction - Slow MA - TB2", "DAD Direction (Top Dog Trading)", "MACD Crossover", "N/A"};#"Trend Bar 2"

def na = Double.NaN;
#def mClose = if UseChartTimeFrame then Close(period=GetAggregationPeriod()) else close(period=AggregationPeriod);
def agg = GetAggregationPeriod();
def c = if UseChartTimeFrame then close else close(Period = Aggregation);
def o = if UseChartTimeFrame then open else open(Period = Aggregation);
;
#---Color
DefineGlobalColor("green" , CreateColor(40, 138, 117));
DefineGlobalColor("Red"   , CreateColor(255, 82, 82));
#// Wave Trend - RSI

def RSIMC = RSI(price = c, Length = 14);

#// Wave Trend

def ap = if UseChartTimeFrame then hlc3 else hlc3(Period = Aggregation) ;    #  "Wave Trend - Source"
def n1 = 9;       #  "Wave Trend - WT Channel Length"
def n2 = 12;      #  "Wave Trend - WT Average Length"
def esa = ExpAverage(ap, n1);
def de = ExpAverage(AbsValue(ap - esa), n1);
def ci = (ap - esa) / (0.015 * de);
def tci = ExpAverage(ci, n2);

def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 3);

#// Wave Trend - Overbought & Oversold lines

def obLevel2 = 60;    #  "Wave Trend - WT Very Overbought")
def obLevel = 50;     #  "Wave Trend - WT Overbought")
def osLevel = -50;    #  "Wave Trend - WT Oversold")
def osLevel2 = -60;   #  "Wave Trend - WT Very Oversold")

#// Wave Trend - Conditions

def WTCross = Crosses(wt1, wt2);
def WTCrossUp = wt2 - wt1 <= 0;
def WTCrossDown = wt2 - wt1 >= 0;
def WTOverSold = wt2 <= osLevel2;
def WTOverBought = wt2 >= obLevel2;

#// MA Calculations


def MA1 = if ma1_Type == ma1_Type."SMA" then
    SimpleMovingAvg(c, ma1_Length) else ExpAverage(c, ma1_Length);

def MA2 = if ma2_Type == ma2_Type."SMA" then
    SimpleMovingAvg(c, ma2_Length) else ExpAverage(c, ma2_Length);

def MA3 = if ma3_Type == ma3_Type."SMA" then
    SimpleMovingAvg(c, ma3_Length) else ExpAverage(c, ma3_Length);

def MA4 = if ma4_Type == ma4_Type."SMA" then
    SimpleMovingAvg(c, ma4_Length) else ExpAverage(c, ma4_Length);

#// MA Crossover Condition

def MACrossover1 = if MA1 > MA2 then 1 else 0;
def MACrossover2 = if MA3 > MA4 then 1 else 0;

#// MA Direction Condition

def MA1Direction = if MA1 > MA1[1] then 1 else 0;
def MA2Direction = if MA2 > MA2[1] then 1 else 0;
def MA3Direction = if MA3 > MA3[1] then 1 else 0;
def MA4Direction = if MA4 > MA4[1] then 1 else 0;

#// MA Direction Change Condition

def MA1PositiveDirectionChange = if MA1Direction and !MA1Direction[1] then 1 else 0;
def MA2PositiveDirectionChange = if MA2Direction and !MA2Direction[1] then 1 else 0;
def MA3PositiveDirectionChange = if MA3Direction and !MA3Direction[1] then 1 else 0;
def MA4PositiveDirectionChange = if MA4Direction and !MA4Direction[1] then 1 else 0;

def MA1NegativeDirectionChange = if !MA1Direction and MA1Direction[1] then 1 else 0;
def MA2NegativeDirectionChange = if !MA2Direction and MA2Direction[1] then 1 else 0;
def MA3NegativeDirectionChange = if !MA3Direction and MA3Direction[1] then 1 else 0;
def MA4NegativeDirectionChange = if !MA4Direction and MA4Direction[1] then 1 else 0;

#// MACD and MOM & DAD - Top Dog Trading
#// Standard MACD Calculations

def MACDfastMA = 12;
def MACDslowMA = 26;
def MACDsignalSmooth = 9;

def MACDLine = ExpAverage(c, MACDfastMA) - ExpAverage(c, MACDslowMA);
def SignalLine = ExpAverage(MACDLine, MACDsignalSmooth);
def MACDHistogram = MACDLine - SignalLine;

#// MACD- Background Color Change Condition

def MACDHistogramCross = if MACDHistogram > 0 then 1 else 0;
def MACDLineOverZero = if MACDLine > 0 then 1 else 0;
def MACDLineOverZeroandHistogramCross = if MACDHistogramCross and MACDLineOverZero then 1 else 0;
def MACDLineUnderZeroandHistogramCross = if !MACDHistogramCross and !MACDLineOverZero then 1 else 0;

#// Fast MACD Calculations

def FastMACDfastMA = 8;
def FastMACDslowMA = 21;
def FastMACDsignalSmooth = 5;

def FastMACDLine = ExpAverage(c, FastMACDfastMA) - ExpAverage(c, FastMACDslowMA);
def FastSignalLine = ExpAverage(FastMACDLine, FastMACDsignalSmooth);
def FastMACDHistogram = FastMACDLine - FastSignalLine;

#// Fast MACD- Background Color Change Condition

def FastMACDHistogramCross = if FastMACDHistogram > 0 then 1 else 0;
def FastMACDLineOverZero = if FastMACDLine > 0 then 1 else 0;
def FastMACDLineOverZeroandHistogramCross = if FastMACDHistogramCross and FastMACDLineOverZero then 1 else 0;
def FastMACDLineUnderZeroandHistogramCross = if !FastMACDHistogramCross and !FastMACDLineOverZero then 1 else 0;

#// Top Dog Trading - Mom Dad Calculations

def TopDog_Fast_MA = 5;
def TopDog_Slow_MA = 20;
def TopDog_Sig = 30;

def TopDogMom = ExpAverage(c, TopDog_Fast_MA) - ExpAverage(c, TopDog_Slow_MA);
def TopDogDad = ExpAverage(TopDogMom, TopDog_Sig);

#// Top Dog Dad - Background Color Change Condition

def TopDogDadDirection = If(TopDogDad > TopDogDad[1], 1, 0);
def TopDogMomOverDad = If(TopDogMom > TopDogDad, 1, 0);
def TopDogMomOverZero = If(TopDogMom > 0, 1, 0);
def TopDogDadDirectandMomOverZero = If(TopDogDadDirection and TopDogMomOverZero, 1, 0);
def TopDogDadDirectandMomUnderZero = If(!TopDogDadDirection and !TopDogMomOverZero, 1, 0);

#////// Trend Barmeter Calculations //////
#// UCS_Trend / Trend Candles Trend Barmeter Calculations
#//UCS_Trend by ucsgears copy Trend Candles
#//Interpretation of TTM Trend bars. It is really close to the actual.

def haclose = if UseChartTimeFrame then ohlc4 else ohlc4(Period = Aggregation);
def haopen = if IsNaN(haopen[1]) then (o + c) / 2 else (haopen[1] + haclose[1]) / 2;

def ccolor = If(haclose - haopen > 0, 1, 0);

def inside6 = If(haopen <= Max(haopen[6], haclose[6]) and haopen >= Min(haopen[6], haclose[6]) and
   haclose <= Max(haopen[6], haclose[6]) and haclose >= Min(haopen[6], haclose[6]), 1, 0);

def inside5 = If(haopen <= Max(haopen[5], haclose[5]) and haopen >= Min(haopen[5], haclose[5]) and
   haclose <= Max(haopen[5], haclose[5]) and haclose >= Min(haopen[5], haclose[5]), 1, 0);

def inside4 = If(haopen <= Max(haopen[4], haclose[4]) and haopen >= Min(haopen[4], haclose[4]) and
   haclose <= Max(haopen[4], haclose[4]) and haclose >= Min(haopen[4], haclose[4]), 1, 0);

def inside3 = If(haopen <= Max(haopen[3], haclose[3]) and haopen >= Min(haopen[3], haclose[3]) and
   haclose <= Max(haopen[3], haclose[3]) and haclose >= Min(haopen[3], haclose[3]), 1, 0);

def inside2 = If(haopen <= Max(haopen[2], haclose[2]) and haopen >= Min(haopen[2], haclose[2]) and
   haclose <= Max(haopen[2], haclose[2]) and haclose >= Min(haopen[2], haclose[2]), 1, 0);

def inside1 = If(haopen <= Max(haopen[1], haclose[1]) and haopen >= Min(haopen[1], haclose[1]) and
   haclose <= Max(haopen[1], haclose[1]) and haclose >= Min(haopen[1], haclose[1]), 1, 0);

def colorvalue = if inside6 then ccolor[6] else if inside5 then ccolor[5] else if inside4 then ccolor[4] else if inside3 then ccolor[3] else if inside2 then ccolor[2] else if inside1 then ccolor[1] else ccolor;

def TrendBarTrend_Candle = if colorvalue then 1 else 0;

#// RSI 5 Trend Barmeter Calculations

def RSI5 = RSI(Price = c, Length = 5);
def RSI5Above50 = if RSI5 > 50 then 1 else 0;
def RSI5Color = if RSI5Above50 then 1 else 0;# ? #288a75 : color.red

#// RSI 5 Trend Barmeter Calculations

def RSI13 = RSI(Price = c, Length = 13);

#// Linear Regression Calculation For RSI Signal Line

def SignalLineLength1 = 21;

def x = BarNumber();
def y = RSI13;
def x_ = SimpleMovingAvg(x, SignalLineLength1);
def y_ = SimpleMovingAvg(y, SignalLineLength1);
def mx = StDev(x, SignalLineLength1);
def my = StDev(y, SignalLineLength1);
def corr = Correlation(x, y, SignalLineLength1);
def slope = corr * (my / mx);
def inter = y_ - slope * x_;
def LinReg1 = x * slope + inter;

def RSISigDirection = If(LinReg1 > LinReg1[1], 1, 0);
def RSISigCross = If(RSI13 > LinReg1, 1, 0);
def RSI13Above50 = If(RSI13 > 50, 1, 0);

#// Trend Barmeter Color Calculation

#RSI13Color = RSI13Above50 ? #288a75 : color.red
def TrendBarRSI13Color = If(RSI13Above50, 1, 0);
def TrendBarRSISigCrossColor = If(RSISigCross, 1, 0);
def TrendBarMACDColor = If(MACDHistogramCross, 1, 0);
def TrendBarFastMACDColor = If(FastMACDHistogramCross, 1, 0);
def TrendBarMACrossColor = If(MACrossover1, 1, 0);
def TrendBarMomOverDadColor = If(TopDogMomOverDad, 1, 0);
def TrendBarDadDirectionColor = If(TopDogDadDirection, 1, 0);

def TrendBar1Result = if TrendMeter1 ==  TrendMeter1."MA Crossover" then MACrossover1 else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar2Result = if TrendMeter2 == TrendMeter2."MA Crossover" then MACrossover1 else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else na;

def TrendBar3Result = if TrendMeter3 == TrendMeter3."MA Crossover" then MACrossover1 else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then MACDHistogramCross else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then FastMACDHistogramCross else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TopDogMomOverDad else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then RSISigCross else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Above50 else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then RSI13Above50 else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else na;


def TrendBars2Positive = If(TrendBar1Result and TrendBar2Result or TrendBar1Result and
                            TrendBar3Result or TrendBar2Result and TrendBar3Result, 1, 0);

def TrendBars2Negative = If(!TrendBar1Result and !TrendBar2Result or !TrendBar1Result and
                            !TrendBar3Result or !TrendBar2Result and !TrendBar3Result, 1, 0);

def TrendBars3Positive = If(TrendBar1Result and TrendBar2Result and TrendBar3Result, 1, 0);
def TrendBars3Negative = If(!TrendBar1Result and !TrendBar2Result and !TrendBar3Result, 1, 0);

#// Signal Filters

def FilterXUp = FastMACDHistogramCross and ExpAverage(c, 15) > ExpAverage(c, 15)[1];
def FilterXDown = !FastMACDHistogramCross and ExpAverage(c, 15) < ExpAverage(c, 15)[1];

def TrendFilterPlus = If(ExpAverage(c, 15) > ExpAverage(c, 20) and ExpAverage(c, 20) > ExpAverage(c, 30) and ExpAverage(c, 30) > ExpAverage(c, 40) and ExpAverage(c, 40) > ExpAverage(c, 50), 1, 0);

def TrendFilterMinus = If(ExpAverage(c, 15) < ExpAverage(c, 20) and ExpAverage(c, 20) < ExpAverage(c, 30) and ExpAverage(c, 30) < ExpAverage(c, 40) and ExpAverage(c, 40) < ExpAverage(c, 50), 1, 0);

#// // Wave Trend - Conditions

def MSBar1PositiveWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter1 == Filter1."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar1NegativeWaveTrendSignal =
if Filter1 == Filter1."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter1 == Filter1."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter1 == Filter1."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else
   WTCross and WTCrossDown;

def MSBar2PositiveWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXUp and WTCross and WTCrossUp else if
   Filter2 == Filter2."Trend Filter" then TrendFilterPlus and WTCross and WTCrossUp else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXUp and TrendFilterPlus and WTCross and WTCrossUp else WTCross and WTCrossUp;

def MSBar2NegativeWaveTrendSignal =
if Filter2 == Filter2."Filter X" then FilterXDown and WTCross and WTCrossDown else if
   Filter2 == Filter2."Trend Filter" then TrendFilterMinus and WTCross and WTCrossDown else if
   Filter2 == Filter2."Filter X + Trend Filter" then
   FilterXDown and TrendFilterMinus and WTCross and WTCrossDown else WTCross and WTCrossDown;

#////////////////////////

def BackgroundColorChangePositive = TrendBars3Positive and !TrendBars3Positive[1];
def BackgroundColorChangeNegative = TrendBars3Negative and !TrendBars3Negative[1];

#// Signals Color Calculations

def MSBar1Color = if MSBar1PositiveWaveTrendSignal then 1 else
   if MSBar1NegativeWaveTrendSignal then -1 else na;#

def MSBar2Color = if BackgroundColorChangePositive then 1 else
   if BackgroundColorChangeNegative then -1 else na;

#// Trend Barmeter Color Assignments

def TrendBar1Color =
if TrendMeter1 == TrendMeter1."N/A" then na else if
   TrendMeter1 == TrendMeter1."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter1 == TrendMeter1."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter1 == TrendMeter1."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter1 == TrendMeter1."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter1 == TrendMeter1."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter1 == TrendMeter1."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter1 == TrendMeter1."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter1 == TrendMeter1."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter1 == TrendMeter1."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar2Color =
if TrendMeter2 == TrendMeter2."N/A" then na else if
   TrendMeter2 == TrendMeter2."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter2 == TrendMeter2."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter2 == TrendMeter2."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter2 == TrendMeter2."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter2 == TrendMeter2."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter2 == TrendMeter2."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter2 == TrendMeter2."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter2 == TrendMeter2."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter2 == TrendMeter2."MA Crossover" then TrendBarMACrossColor else na;

def TrendBar3Color =
if TrendMeter3 == TrendMeter3."N/A" then na else if
   TrendMeter3 == TrendMeter3."MACD Crossover - 12, 26, 9" then TrendBarMACDColor else if
   TrendMeter3 == TrendMeter3."MACD Crossover - Fast - 8, 21, 5" then TrendBarFastMACDColor else if
   TrendMeter3 == TrendMeter3."Mom Dad Cross (Top Dog Trading)" then TrendBarMomOverDadColor else if
   TrendMeter3 == TrendMeter3."DAD Direction (Top Dog Trading)" then TrendBarDadDirectionColor else if
   TrendMeter3 == TrendMeter3."RSI Signal Line Cross - RSI 13, Sig 21" then TrendBarRSISigCrossColor else if
   TrendMeter3 == TrendMeter3."RSI 5: > or < 50" then RSI5Color else if
   TrendMeter3 == TrendMeter3."RSI 13: > or < 50" then TrendBarRSI13Color else if
   TrendMeter3 == TrendMeter3."Trend Candles" then TrendBarTrend_Candle else if
   TrendMeter3 == TrendMeter3."MA Crossover" then TrendBarMACrossColor else na;


def CrossoverType2 =
if TrendBar1 == TrendBar1."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar1 == TrendBar1."MACD Crossover" then MACDHistogramCross else if
   TrendBar1 == TrendBar1."MA Direction - Fast MA - TB1" then MA1Direction else if
   TrendBar1 == TrendBar1."MA Direction - Slow MA - TB1" then MA2Direction else MACrossover1;

def TrendBar4Color1 = if TrendBar1 == TrendBar1."N/A" then na else
                      if CrossoverType2 then 1 else 0;

def CrossoverType3 =
if TrendBar2 == TrendBar2."DAD Direction (Top Dog Trading)" then TopDogDadDirection else if
   TrendBar2 == TrendBar2."MACD Crossover" then MACDHistogramCross else if
   TrendBar2 == TrendBar2."MA Direction - Fast MA - TB2" then MA3Direction else if
   TrendBar2 == TrendBar2."MA Direction - Slow MA - TB2" then MA4Direction else MACrossover2;

def TrendBar5Color1 = if TrendBar2 == TrendBar2."N/A" then na else
                      if CrossoverType3 then 1 else 0;

#// Momentum Setup Plots

plot Signals1 = If(IsNaN(c) or IsNaN(MSBar1Color), na, If(ShowTrendBar and WaveTrendSignalLine, 129, na));    # "Signals 1 - Wave Trend Signals"
Signals1.SetPaintingStrategy(PaintingStrategy.SQUARES);
Signals1.AssignValueColor(if MSBar1Color > 0 then GlobalColor("green") else GlobalColor("RED"));

plot Signals2 = If(IsNaN(c) or IsNaN(MSBar2Color), na, If(ShowTrendBar and TrendMeterLine, 126, na));    # "Signals 2 - All 3 Trend Meters Now Align"
Signals2.SetPaintingStrategy(PaintingStrategy.POINTS);
Signals2.AssignValueColor(if MSBar2Color > 0 then GlobalColor("green") else GlobalColor("RED"));

#// Trend Barmeter Plots

plot TM1 = If(IsNaN(c), na, If(ShowTrendBar, 123, na)); # "Trend Meter 1"
TM1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM1.AssignValueColor(if TrendBar1Color then GlobalColor("green") else GlobalColor("RED"));

plot TM2 = If(IsNaN(c), na, If(ShowTrendBar, 120.5, na));# "Trend Meter 2"
TM2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM2.AssignValueColor(if TrendBar2Color then GlobalColor("green") else GlobalColor("RED"));

plot TM3 = If(IsNaN(c), na, If(ShowTrendBar, 118, na));# "Trend Meter 3"
TM3.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
TM3.AssignValueColor(if TrendBar3Color then GlobalColor("green") else GlobalColor("RED"));

plot ThinLine = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar2 == TrendBar2."N/A"), 115, na));
ThinLine.AssignValueColor(if TrendBar4Color1 then Color.GREEN else Color.RED);
ThinLine.SetLineWeight(2);

plot ThikLine = If(IsNaN(c), na, If(ShowTrendBar and TrendBar2 == TrendBar2."N/A" and !(TrendBar1 == TrendBar1."N/A"), 107.25, na));
ThikLine.AssignValueColor(if TrendBar4Color1 then  Color.GREEN else Color.RED);
ThikLine.SetLineWeight(5);

plot ThinLine2 = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar1 == TrendBar1."N/A"), 112.5, na));
ThinLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThinLine2.SetLineWeight(2);

plot ThikLine2 = If(IsNaN(c), na, If(ShowTrendBar and TrendBar1 == TrendBar1."N/A" and !(TrendBar2 == TrendBar2."N/A"), 107.25, na));
ThikLine2.AssignValueColor(if TrendBar5Color1 then  Color.GREEN else Color.RED);
ThikLine2.SetLineWeight(5);

#--- Stratgy Line
def EMA1 = ExpAverage(c,SignalMALength1);
def EMA2 = ExpAverage(c,SignalMALength2);
def diff = c - o;
def UpperBand = StDev(diff, VolatilityLength);
def LowerBand = StDev(diff, VolatilityLength) * -1;
def Long = Signals2 and MSBar2Color>0 and ThinLine and ThinLine2 and TrendBar4Color1 and TrendBar5Color1 and diff>=UpperBand and EMA1>EMA2;
def short = Signals2 and MSBar2Color<0 and ThinLine and ThinLine2 and !TrendBar4Color1 and !TrendBar5Color1 and diff<=LowerBand and EMA1<EMA2;

plot LongSignal = if Long then 126 else na;
plot ShortSignal = if short then 126 else na;
LongSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
LongSignal.SetDefaultColor(Color.GREEN);
LongSignal.SetLineWeight(5);
ShortSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortSignal.SetDefaultColor(Color.RED);
ShortSignal.SetLineWeight(5);
#// Background Highlights

AddCloud(if TrendBars3Positive then Double.NEGATIVE_INFINITY else if TrendBars3Negative then Double.POSITIVE_INFINITY else na, if TrendBars3Positive then Double.POSITIVE_INFINITY else if TrendBars3Negative then Double.NEGATIVE_INFINITY else na, Color.DARK_RED, Color.DARK_GREEN);

#---END Code
would it be possible to paint the bars ? TM candles
 
hello,
any ideas why the indicators disappears at higher time frame (Daily or weekly...) in Thinkorswim?
Thank you
 
hello,
any ideas why the indicators disappears at higher time frame (Daily or weekly...) in Thinkorswim?
Thank you
The aggregation can not be less than your chart
In settings, change the aggregation to something not less than your chart.
input Aggregation = AggregationPeriod.HOUR;
 
Happy Thanksgiving everyone.
I changed the value of "Signal ma length1" to 50 and "Signal ma length2" to 200. It seems to work more like in the video. Has anyone tried it?
 
Actually I did it on my own! Yes, the script is too complex to allow a scan out of it, so I broke down the components of the Signals2 and the volatility oscilator, and wrote scan filters for each of them .

Couple of points to note :
  • This scan looks for Signals2 only, not the LONG signal (big green dot). That is because I have observed that more often than not, when the LONG signal is triggered, the stock is almost close to resistance, thus making reversal imminent. If I combine Signals2 with the volatility oscillator, swing trades are pretty decent.
  • My scan looks for the green dot within two bars, since I trade on the daily timeframe.
  • This scan looks for spikes in the volatility oscillator for LONG trades, within 2 bars
  • This is what my setup looks like
    1712051377243.png

  • How I trade using this :
    exactly as the video suggests : putting top priority in the price action and S/R, followed by the combination of the trend meter and the volatility oscillator. I also rely on the traders dynamic index https://usethinkscript.com/threads/traders-dynamic-index-tdi-indicator-for-thinkorswim.651/, which I have not shown in the screenshot.
 

Attachments

  • 1712051322989.png
    1712051322989.png
    382.7 KB · Views: 92
  • 1712051572473.png
    1712051572473.png
    69.6 KB · Views: 54
Last edited by a moderator:
Actually I did it on my own! Yes, the script is too complex to allow a scan out of it, so I broke down the components of the Signals2 and the volatility oscilator, and wrote scan filters for each of them .

Couple of points to note :
  • This scan looks for Signals2 only, not the LONG signal (big green dot). That is because I have observed that more often than not, when the LONG signal is triggered, the stock is almost close to resistance, thus making reversal imminent. If I combine Signals2 with the volatility oscillator, swing trades are pretty decent.
  • My scan looks for the green dot within two bars, since I trade on the daily timeframe.
  • This scan looks for spikes in the volatility oscillator for LONG trades, within 2 bars
  • This is what my setup looks like
    View attachment 21495
  • How I trade using this :
    exactly as the video suggests : putting top priority in the price action and S/R, followed by the combination of the trend meter and the volatility oscillator. I also rely on the traders dynamic index, which I have not shown in the screenshot.
Thank you for your post.
Could you share the link to your chart setup.
What "trader dynamic index" ?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
226 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