#// Created By Lij_MC
#// Use as a supplementary Indicator to confirm your entries, but it is as good on its 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
# Inputs
input ColorBars = no;
input ShowTrendBar = yes;
input UseChartTimeFrame = yes;
input Aggregation = AggregationPeriod.DAY;
input ma1_Length = 5;
input ma1_Type = {default "EMA", "SMA"};
input ma2_Length = 11;
input ma2_Type = {default "EMA", "SMA"};
input ma3_Length = 13;
input ma3_Type = {default "EMA", "SMA"};
input ma4_Length = 29;
input ma4_Type = {"EMA", default "SMA"};
# Colors
DefineGlobalColor("green", CreateColor(40, 138, 117));
DefineGlobalColor("Red", CreateColor(255, 82, 82));
DefineGlobalColor("Purple", CreateColor(128, 0, 128));
DefineGlobalColor("Brown", CreateColor(165, 42, 42));
# Wave Trend
def c = if UseChartTimeFrame then close else close(Period = Aggregation);
def ap = if UseChartTimeFrame then hlc3 else hlc3(Period = Aggregation);
def esa = ExpAverage(ap, 9);
def de = ExpAverage(AbsValue(ap - esa), 9);
def ci = (ap - esa) / (0.015 * de);
def tci = ExpAverage(ci, 12);
def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 3);
# Wave Trend Conditions
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 Conditions
def MACrossover1 = MA1 > MA2;
def MACrossover2 = MA3 > MA4;
# MA Direction Conditions
def MA1Direction = MA1 > MA1[1];
def MA2Direction = MA2 > MA2[1];
def MA3Direction = MA3 > MA3[1];
def MA4Direction = MA4 > MA4[1];
# Plot Wave Trend
plot WaveTrend1 = wt1;
plot WaveTrend2 = wt2;
WaveTrend1.SetDefaultColor(Color.CYAN);
WaveTrend2.SetDefaultColor(Color.MAGENTA);
# Add Labels for Alerts
AddLabel(WTCrossUp, "Buy Signal", Color.GREEN);
AddLabel(WTCrossDown, "Sell Signal", Color.RED);
AddLabel(MACrossover1, "MA Crossover 1", Color.BLUE);
AddLabel(MACrossover2, "MA Crossover 2", Color.ORANGE);
AddLabel(MA1Direction, "MA1 Direction", GlobalColor("Purple"));
AddLabel(MA2Direction, "MA2 Direction", Color.PINK);
AddLabel(MA3Direction, "MA3 Direction", GlobalColor("Purple"));
AddLabel(MA4Direction, "MA4 Direction", GlobalColor("Brown"));