Trend-Volatility-Volume-RSI Indicator

Ali_A

New member
Hello, I use these four indicators for trading SPY and ES, which have proven to be quite effective. These indicators are all lower indicators, but I'm interested in merging them into a single chart for more convenient use.

Trend Meter
https://usethinkscript.com/threads/trend-meter-for-thinkorswim.13179/
Volatility Oscillator
https://usethinkscript.com/threads/volatility-oscillator-for-thinkorswim.13184/
Volume Zone Oscillator
https://usethinkscript.com/threads/volume-zone-oscillator-vzo-for-thinkorswim.7976/
ToS Indicator MyRSIWithNET
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MyRSIWithNET

Below are the entry conditions for my trading strategy:

  1. Long Entry:
    • When the Trend Meter indicator displays a green dot above (regardless of its size) or When the TI_AdvancedVZO line is above the zero line and the Volatility Oscillator spikes above the upper band; Generate a green arrow to initiate a long position.
  2. Short Entry:
    • When the Trend Meter indicator displays a red dot above (regardless of its size) or When the TI_AdvancedVZO is below the zero line and the Volatility Oscillator spikes below the lower band; Generate a red arrow to initiate a short position.
  3. Chart Coloring:
    • Color the chart green when the MyRSI line on the MyRSIWithNET indicator crosses above zero.
    • Color the chart red when the MyRSI line on the MyRSIWithNET indicator crosses below zero.
Its '(Condition_1 AND Condition_3) OR (Condition_2 AND Condition_3)'. Thanks for reviewing this...


Additionally, it would be beneficial to create a strategy based on the above conditions, offering the flexibility to adjust profit and target levels.
 

Attachments

  • Indicator Screenshot.png
    Indicator Screenshot.png
    187.5 KB · Views: 964
Last edited by a moderator:
Solution
@Ali_A
Try this:

Ruby:
#Trend Meter
#// Inputs / Menus
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 TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"N/A"...
@Ali_A
Try this:

Ruby:
#Trend Meter
#// Inputs / Menus
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 TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"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 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

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

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

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

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

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

#// 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);
def TopDogDadDirection = If(TopDogDad > TopDogDad[1], 1, 0);
def TopDogMomOverDad = If(TopDogMom > TopDogDad, 1, 0);

#////// Trend Barmeter Calculations //////

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

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 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 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 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
def Signals2 = If(IsNaN(c) or IsNaN(MSBar2Color), na, If(ShowTrendBar and TrendMeterLine, 0, na));    # "Signals 2 - All 3 Trend Meters Now Align"

#// Trend Barmeter Plots
def ThinLine = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar2 == TrendBar2."N/A"), 115, na));
def ThinLine2 = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar1 == TrendBar1."N/A"), 112.5, na));

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

def LongSignal = if Long then 0 else na;
def ShortSignal = if short then 0 else na;


##############################
def TMBuyCond = !IsNaN(Signals2) and MSBar2Color > 0;
def TMSellCond = !IsNaN(Signals2) and MSBar2Color < 0;
##############################

#Volatility Oscillator

input length = 100;
def VOc = close; def VOo = open; def l = low; def h = high;
def VOdiff = VOc-VOo;

def VOx = StDev(VOdiff, length);
def VOy = StDev(VOdiff, length) * -1;

def spike = VOdiff;

def p1 = VOx; # "Upper Line")
def p2 = VOy; # "Lower Line")
##############################
def VOBuyCond = VOdiff > VOx;
def VOSellCond = VOdiff < VOy;
##############################

#Volume Zone Oscillator
input VZOlength = 14;

def VP = expAverage(Sign(close - close[1]) * volume, VZOlength);
def TV = expAverage(volume, VZOlength);

def VZO = 100 * VP / TV;
def VZO_DOTS = VZO;
def ZeroLine = 0;
##############################
def VZOBuyCond = VZO > 0;
def VZOSellCond = VZO < 0;
##############################

def MYRSI = reference MYRSIWithNET.myRSI;
AssignPriceColor(if MYRSI > 0 then Color.GREEN else if MYRSI < 0 then Color.RED else Color.CURRENT);

############################################################
############################################################

def B = if TMBuyCond and VOBuyCond then 0 else na;
def B1 = if VZOBuyCond and VOBuyCond then 0 else na;

def A = if TMSellCond and VOSellCond then 0 else na;
def A1 = if VZOSellCond and VOSellCond then 0 else na;

def Buy = !IsNAN(B) or !IsNAN(B1);
def Sell = !IsNAN(A) or !IsNAN(A1);

plot ArrowUp = if Buy then low else double.nan;
ArrowUP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.AssignValueColor(Color.GREEN);
plot ArrowDn = if Sell then high else double.nan;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.AssignValueColor(Color.RED);
 
Last edited by a moderator:
Solution
@Ali_A
Stripped out the strategy, and strategy logic.

Ruby:
#Trend Meter
#// Inputs / Menus
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 TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"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 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

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

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

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

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

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

#// 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);
def TopDogDadDirection = If(TopDogDad > TopDogDad[1], 1, 0);
def TopDogMomOverDad = If(TopDogMom > TopDogDad, 1, 0);

#////// Trend Barmeter Calculations //////

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

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 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 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 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
def Signals2 = If(IsNaN(c) or IsNaN(MSBar2Color), na, If(ShowTrendBar and TrendMeterLine, 0, na));    # "Signals 2 - All 3 Trend Meters Now Align"

#// Trend Barmeter Plots
def ThinLine = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar2 == TrendBar2."N/A"), 115, na));
def ThinLine2 = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar1 == TrendBar1."N/A"), 112.5, na));

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

def LongSignal = if Long then 0 else na;
def ShortSignal = if short then 0 else na;


##############################
def TMBuyCond = !IsNaN(Signals2) and MSBar2Color > 0;
def TMSellCond = !IsNaN(Signals2) and MSBar2Color < 0;
##############################

#Volatility Oscillator

input length = 100;
def VOc = close; def VOo = open; def l = low; def h = high;
def VOdiff = VOc-VOo;

def VOx = StDev(VOdiff, length);
def VOy = StDev(VOdiff, length) * -1;

def spike = VOdiff;

def p1 = VOx; # "Upper Line")
def p2 = VOy; # "Lower Line")
##############################
def VOBuyCond = VOdiff > VOx;
def VOSellCond = VOdiff < VOy;
##############################

#Volume Zone Oscillator
input VZOlength = 14;

def VP = expAverage(Sign(close - close[1]) * volume, VZOlength);
def TV = expAverage(volume, VZOlength);

def VZO = 100 * VP / TV;
def VZO_DOTS = VZO;
def ZeroLine = 0;
##############################
def VZOBuyCond = VZO > 0;
def VZOSellCond = VZO < 0;
##############################

def MYRSI = reference MYRSIWithNET.myRSI;
AssignPriceColor(if MYRSI > 0 then Color.GREEN else if MYRSI < 0 then Color.RED else Color.CURRENT);

############################################################
############################################################

def B = if TMBuyCond and VOBuyCond then 0 else na;
def B1 = if VZOBuyCond and VOBuyCond then 0 else na;

def A = if TMSellCond and VOSellCond then 0 else na;
def A1 = if VZOSellCond and VOSellCond then 0 else na;

def Buy = !IsNAN(B) or !IsNAN(B1);
def Sell = !IsNAN(A) or !IsNAN(A1);

plot ArrowUp = if Buy then low else double.nan;
ArrowUP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.AssignValueColor(Color.GREEN);
plot ArrowDn = if Sell then high else double.nan;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.AssignValueColor(Color.RED);
Thanks a million.. This is awesome!!!
 
@Ali_A
Try this:

Ruby:
#Trend Meter
#// Inputs / Menus
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 TrendMeterLine = yes;    # "All 3 Trend Meters Now Align"
input Filter1 = {"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 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

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

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

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

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

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

#// 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);
def TopDogDadDirection = If(TopDogDad > TopDogDad[1], 1, 0);
def TopDogMomOverDad = If(TopDogMom > TopDogDad, 1, 0);

#////// Trend Barmeter Calculations //////

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

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 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 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 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
def Signals2 = If(IsNaN(c) or IsNaN(MSBar2Color), na, If(ShowTrendBar and TrendMeterLine, 0, na));    # "Signals 2 - All 3 Trend Meters Now Align"

#// Trend Barmeter Plots
def ThinLine = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar2 == TrendBar2."N/A"), 115, na));
def ThinLine2 = If(IsNaN(c), na, If(ShowTrendBar and !(TrendBar1 == TrendBar1."N/A"), 112.5, na));

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

def LongSignal = if Long then 0 else na;
def ShortSignal = if short then 0 else na;


##############################
def TMBuyCond = !IsNaN(Signals2) and MSBar2Color > 0;
def TMSellCond = !IsNaN(Signals2) and MSBar2Color < 0;
##############################

#Volatility Oscillator

input length = 100;
def VOc = close; def VOo = open; def l = low; def h = high;
def VOdiff = VOc-VOo;

def VOx = StDev(VOdiff, length);
def VOy = StDev(VOdiff, length) * -1;

def spike = VOdiff;

def p1 = VOx; # "Upper Line")
def p2 = VOy; # "Lower Line")
##############################
def VOBuyCond = VOdiff > VOx;
def VOSellCond = VOdiff < VOy;
##############################

#Volume Zone Oscillator
input VZOlength = 14;

def VP = expAverage(Sign(close - close[1]) * volume, VZOlength);
def TV = expAverage(volume, VZOlength);

def VZO = 100 * VP / TV;
def VZO_DOTS = VZO;
def ZeroLine = 0;
##############################
def VZOBuyCond = VZO > 0;
def VZOSellCond = VZO < 0;
##############################

def MYRSI = reference MYRSIWithNET.myRSI;
AssignPriceColor(if MYRSI > 0 then Color.GREEN else if MYRSI < 0 then Color.RED else Color.CURRENT);

############################################################
############################################################

def B = if TMBuyCond and VOBuyCond then 0 else na;
def B1 = if VZOBuyCond and VOBuyCond then 0 else na;

def A = if TMSellCond and VOSellCond then 0 else na;
def A1 = if VZOSellCond and VOSellCond then 0 else na;

def Buy = !IsNAN(B) or !IsNAN(B1);
def Sell = !IsNAN(A) or !IsNAN(A1);

plot ArrowUp = if Buy then low else double.nan;
ArrowUP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.AssignValueColor(Color.GREEN);
plot ArrowDn = if Sell then high else double.nan;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.AssignValueColor(Color.RED);
Can this be turned into a watchlist column?
Can this be used to scan?
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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