MTF Candle Color

Spark

New member
Im trying to create a MTF that reference the colors on the chart based on the close of the current candles on each timeframe. However, the MTF seems to aggregate the current bar color for all the MTF labels on higher timeframe.
The 5m chart is currently green indicating acceleration but it highlights ALL the MTF labels green. The middle 15m chart shows Violet and the left 1H shows Cyan. I believe it has something to do with the aggregation period portion of the code. Im not entirely sure where but I think im missing something that tells the code current timeframe to aggregate the higher timeframe based on a certain input MA_AggPeriod.


Code:
# MTF Candle Colors (Its based on where price closes in relation to the moving averages *Pictures does NOT show the moving averages)


# Input the aggregation period desired for the 50HMA
def timeFrame = GetAggregationPeriod();

input MA_AggPeriod = AggregationPeriod.WEEK;

# General length
input GlobalLength = 18;

# -- Pulse Inputs ----------
#input length = 8; # 3-8 is key range.
input pulseLength = 8; # 8 is a key Pulse Level!!


# -- General MA Inputs -------
input ShortMaLenght = 10; #10 is a key Level!!
#input VHMALength1 = 10; #10 is a key Level!!
input HMA50Length = 50; #50 is a key Level!!
input smalength = 200;


# Price inputs
input price = close;
input priceLow = low;
input priceHgh = High;

# -- Moving average types
input averageTypeHull = AverageType.HULL;


# --------------- END Spark's Super Trend Inputs ---------------












#---------------------------------  PULSE MA  -------------------------------

# Variable Moving Average (VMA) is an exponential moving average that adjusts its smoothing constant on the basis of market volatility.

# Lets define variables that track the movement of px.
def pxUp = if price > price[1] then price - price[1] else 0;
def pxDown = if price < price[1] then price + price[1] else 0;

# Lets define some variables that tracks the movement of price between a number of bars.
def sumPXUpBars = Sum(pxUp, pulseLength);
def sumPXDownBars = Sum(pxDown, pulseLength);

def sumPXBars = sumPXUpBars + sumPXDownBars == 0;

def ad3 = if sumPXBars then 0 else (sumPXUpBars - sumPXDownBars) / (sumPXUpBars + sumPXDownBars) * 100;

def coeff = 2 / (pulseLength + 1) * AbsValue(ad3) / 100;

def asd = CompoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);




#---------------------------------  END PULSE MA  -------------------------------







# --------------- Volume & HULL Weighted Moving Avg (VHMA & VWMA) ------------------------------

# Lets create 4 MAs.
def HMA10Hgh = MovingAverage(averageTypeHull, priceHgh, ShortMaLenght); #White/Gray


def VWMA10Low = Sum(volume * priceLow, ShortMaLenght) / Sum(volume, ShortMaLenght); #White/Gray

def HMA_50 = MovingAverage(averageTypeHull, price, HMA50Length);


def Time_Frame_HMA_50 = if timeFrame == AggregationPeriod.TWO_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.FIVE_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.FIFTEEN_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.THIRTY_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.HOUR
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.FOUR_HOURS
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.DAY
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)   
    else Double.NaN;


def SMA200 = Average(price, smalength);

#------- END Volume & HULL Weighted Moving Avg (VHMA & VWMA) ------------------------------








#  --------------------------------- Plot the MAs to the Chart ------------------------------

def VMA = asd; # Pulse  (Multi Colors)
#def Multi_TF_VMA = Time_frame_asd; # Pulse  (Multi Colors)
plot HMA50 = HMA_50;
plot Time_Frame_HMA50 = Time_Frame_HMA_50;
def VWMA10 = VWMA10Low; #White/Gray
def HMA10 = HMA10Hgh; #White/Gray
plot SMA = SMA200; #Gold/Grey

#  ---  END Plot the MAs to the Chart ----------





# -------------- BB & KC Channel -------------------


input BBCloudsOn = yes;
input BBBandsOn = yes;
input KCBandsOn = yes;
#input KCFactor = 1.0;


# ----------- Plot Mid Upper and Lower BB Line ------------

def BB_Midline = BollingerBands().MidLine;
plot BBM = if BBBandsOn then BB_Midline else Double.NaN;
# Upper BB Line
def BB_Upperband = BollingerBands().UpperBand;
plot BBH = if BBBandsOn and priceHgh >= BB_Upperband then BB_Upperband else Double.NaN;
# Lower Bb Line
def BB_Lowerband = BollingerBands().LowerBand;
plot BBL = if BBBandsOn and priceLow <= BB_Lowerband then BB_Lowerband else Double.NaN;

# Assign direction to the BB bands
def BB_Midline_Up = BB_Midline > BB_Midline[1] and priceLow > BB_Midline;
def BB_Midline_DOWN = BB_Midline < BB_Midline[1] and priceHgh < BB_Midline;
def BB_Bands_UP = (BB_Upperband > BB_Upperband[1]) and (BB_Lowerband > BB_Lowerband[1]);
def BB_Bands_Down = (BB_Upperband < BB_Upperband[1]) and (BB_Lowerband < BB_Lowerband[1]);


BBH.SetLineWeight(3);
BBH.SetStyle(Curve.LONG_DASH);
BBH.AssignValueColor(if BB_Bands_UP
    then Color.LIGHT_GREEN
    else Color.LIGHT_RED);

# Set syle for BB Midline
BBM.SetLineWeight(1);
BBM.SetStyle(Curve.FIRM);
BBM.AssignValueColor(if BB_Midline_Up
    then Color.LIGHT_GREEN
    else Color.LIGHT_RED);


BBL.SetLineWeight(3);
BBL.SetStyle(Curve.LONG_DASH);
BBL.AssignValueColor(if BB_Bands_Down
    then Color.LIGHT_RED
    else Color.LIGHT_GREEN);



#  -------------- Plot Mid upper and lower KC Line --------------

def KC_Midline =   KeltnerChannels().Avg;
plot KCM = if KCBandsOn then KC_Midline else Double.NaN;

# Upper KC Line
def KC_Upperband =   KeltnerChannels().Upper_Band;
plot KCH = if KCBandsOn and priceHgh >= KC_Upperband  then KC_Upperband else Double.NaN;

# Lower KC Line
def KC_lowerband =   KeltnerChannels().Lower_Band;
plot KCL = if KCBandsOn and priceLow <= KC_lowerband then KC_lowerband else Double.NaN;   



# Assign direction to the kc bands
def KC_Midline_Up = KC_Midline > KC_Midline[1] and price > KC_Midline;
def KC_Bands_UP = (KC_Upperband > KC_Upperband[1]) and (KC_lowerband > KC_lowerband[1]);
def KC_Bands_Down = (KC_Upperband < KC_Upperband[1]) and (KC_lowerband < KC_lowerband[1]);


KCH.SetLineWeight(3);
KCH.SetStyle(Curve.SHORT_DASH);
KCH.AssignValueColor(if KC_Bands_UP
   then Color.PLUM 
   else Color.BLUE);


# Style the mid line
KCM.SetLineWeight(4);
KCM.SetStyle(Curve.FIRM);
KCM.AssignValueColor(if KC_Midline_Up
   then Color.DARK_GREEN
   else Color.DARK_RED);


KCL.SetLineWeight(3);
KCL.SetStyle(Curve.SHORT_DASH);
KCL.AssignValueColor(if KC_Bands_Down 
    then Color.BLUE
    else Color.PLUM);


# ---------------- BB&KC Indicator --------------





# -----------  BB & KC Bands Squeeze Clouds -------------

# When the BB upper and lower bands cross inside the KC's we are in a Squeeze. The code below should activate a certain color to indicate this.

DefineGlobalColor("BB Squeeze", Color.GREEN);
DefineGlobalColor("BB UnSqueezed", Color.CURRENT);

AddCloud(KC_Upperband, BB_Upperband, GlobalColor("BB Squeeze"), GlobalColor("BB UnSqueezed"));
AddCloud(BB_Lowerband, KC_lowerband, GlobalColor("BB Squeeze"), GlobalColor("BB UnSqueezed"));




# ------------ Bull/Bear ATR Trend  ---------------------

# Average True Range Inputs
input ATRlength = 14; # 9-38 Key Level 
#input ATRs = 2.5; #1 key Level

# Cacl EMA to be used as a point of reference.
def ATR_EMA = ExpAverage(close, ATRlength);





# ---------------------------- Identify Market Conditions, PX Action & Strategies ---------------------------

# -----------------  Px Action & MKT Structures ----------------

def Bull_Mkt = price > HMA50 and HMA50 >= Time_Frame_HMA_50;

#AddChartBubble (yes and Bull_Mkt and !Bull_Mkt[1], priceLow, "MKT", Color.DARK_GREEN);


def Bear_Mkt = price < HMA50 and HMA50 <= Time_Frame_HMA_50;


#AddChartBubble (yes and Bear_Mkt and !Bear_Mkt[1], priceHgh, "MKT", Color.DARK_RED);








# -------------- Bull/Bear Stacked Ma's -----------------

def Bull_Stack = HMA10 > VMA and VMA >= HMA50 and HMA50 > Time_Frame_HMA_50;

def Bear_Stack = VWMA10 < VMA and VMA < HMA50 and HMA50 < Time_Frame_HMA_50;



# ------- Bullish/Bearish Trend ------------

# Bullish Trend
def Trend_Bullish = VMA > ATR_EMA;

def Trend_Bullish_Invalid =  VMA > ATR_EMA and price < HMA50 and price < Time_Frame_HMA50;

#AddChartBubble (Trend_Buy_Sell_Bubble_On and Trend_Bullish and ! Trend_Bullish[1], priceLow, "B", Color.GREEN);


# Bearish Trend
def Trend_Bearish = VMA < ATR_EMA;

def Trend_Bearish_Invalid =  VMA < ATR_EMA and price > HMA50 and price > Time_Frame_HMA50;

#AddChartBubble (Trend_Buy_Sell_Bubble_On and Trend_Bearish and ! Trend_Bearish[1], priceHgh, "S", Color.RED);





#--------- Bull Pull Backs & Chart Bubbles --------

# Lets define a Bullish Pull back! (ALL GOOD)!!
def Bull_Pullbacks = (Trend_Bullish and priceLow <= priceLow[2] and price > Time_Frame_HMA50) or  (priceLow <= VWMA10 and price > Time_Frame_HMA50);

plot Bull_Pullback = Bull_Pullbacks;

Bull_Pullback.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
Bull_Pullback.SetDefaultColor(Color.GREEN);



# ------------- Bear Pull Backs & Chart Bubbles -----------

# Lets define a Bearish Pull back! (ALL GOOD)!!
def Bear_Pullbacks = (Trend_Bearish and priceHgh > priceHgh[2] and price < Time_Frame_HMA50) or (priceHgh > HMA10 and price < Time_Frame_HMA50);

#(Trend_Bearish and priceHgh >= HMA10 and price < HMA50) or (Trend_Bearish and priceHgh >= VMA and price < HMA50) ;

plot Bear_Pullback = Bear_Pullbacks;

Bear_Pullback.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
Bear_Pullback.SetDefaultColor(Color.RED);












# -------- Bull/Bear Push  ----
def BB_Bullish_Push = HMA10 >= KC_Upperband and priceHgh >= KC_Upperband;

def Bull_PX_Push = priceHgh > HMA10 and price > VMA and priceLow >= HMA50;

#AddChartBubble (PX_Buy_Sell_Bubbles_On and Bull_PX_Push and !Bull_PX_Push[1], priceLow, "B", Color.PLUM);


def BB_Bearish_Flush = VWMA10 < KC_lowerband and priceLow <= KC_lowerband;

def Bear_PX_Flush = priceLow < VWMA10 and price < VMA and priceHgh < HMA50;


#AddChartBubble (PX_Buy_Sell_Bubbles_On and Bear_PX_Flush and !Bear_PX_Flush[1], priceHgh, "S", Color.MAGENTA);




# ------------ Impusle Bar Candle ------------ 

def Impulse_Bar = high > KC_Upperband  and low < KC_lowerband; 



# ---- Define Market Phase -------

# Lets define areas of acceleration!! (ALL GOOD)!!
def acceleration = price >= VMA and priceLow > VWMA10 and VMA > VMA[1] and price > BB_Midline and priceLow >= Time_Frame_HMA50;


# Lets define areas of Deceleration!! (ALL GOOD)!!
def deceleration = price < VMA and priceHgh < HMA10 and VMA < VMA[1] and price < BB_Midline and priceHgh < Time_Frame_HMA50;

# Lets define areas of Accumulation!! (ALL GOOD)!!
def accumulation = priceLow < VMA and priceHgh > HMA10 and VMA > VMA[1] and price > Time_Frame_HMA50 and !acceleration;


# Lets define areas of Distribution!! (ALL GOOD)!!
def distribution = priceHgh > VMA and priceLow < VWMA10 and VMA < VMA[1]  and price < Time_Frame_HMA50 and !deceleration;


def Bulls_Get_Ready = price > Time_Frame_HMA50  and price < HMA50 and !accumulation and !acceleration and !distribution and !deceleration;

def Bulls_Get_Ready_Trend = Trend_Bullish and price > Time_Frame_HMA50  and price < HMA50 and !accumulation and !distribution and !deceleration;

def Bulls_Get_Ready_Trend1 = Trend_Bullish and price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !distribution;


def Bears_Get_Ready = price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !acceleration and !distribution and !deceleration;

def Bears_Get_Ready_Trend = Trend_Bearish and price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !acceleration and !distribution;

def Bears_Get_Ready_Trend1 = Trend_Bearish and price > Time_Frame_HMA50 and price < HMA50 and !accumulation and !distribution;




# ---------------  Global Candle Logic ----------------------


DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bull PullBack", Color.DARK_GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Bear PullBack", Color.DARK_RED);


DefineGlobalColor("Break Out", Color.GREEN);
DefineGlobalColor("Break Down", Color.RED);
DefineGlobalColor("Reject", Color.DARK_RED);
DefineGlobalColor("Bounce", Color.DARK_GREEN);


DefineGlobalColor("Overbought Bar", Color.YELLOW);
DefineGlobalColor("Oversold Bar", Color.YELLOW);
DefineGlobalColor("KC Power UP", Color.DARK_ORANGE);
DefineGlobalColor("KC Power Down", Color.DARK_ORANGE);
DefineGlobalColor("Impulse Bar", Color.PLUM);


DefineGlobalColor("Accel", Color.GREEN);
DefineGlobalColor("Accum", Color.WHITE);
DefineGlobalColor("Dist", Color.BLUE);
DefineGlobalColor("Decel", Color.RED);
DefineGlobalColor("Bulls Get Ready", Color.CYAN);
DefineGlobalColor("Bears Get Ready", Color.VIOLET);





# --------------- END Global Candle Logic ----------------------


def MTF_On = yes;


## Month Aggregation Period Variables
def monthAcceleration;
def monthDeceleration;
def monthDistribution;
def monthAccumulation;
def monthBulls_Get_Ready;
def monthBears_Get_Ready;
def monthBears_Get_Ready_Trend;
def monthBulls_Get_Ready_Trend;
def monthBears_Get_Ready_Trend1;
def monthBulls_Get_Ready_Trend1;
def monthBull_Pullbacks;
def monthBear_Pullbacks;
def monthTrend_Bearish_Invalid;
def monthTrend_Bullish_Invalid;
def monthTrend_Bearish;
def monthTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.MONTH {
    monthAcceleration = acceleration;
    monthDeceleration = deceleration;
    monthDistribution = distribution;
    monthAccumulation = accumulation;
    monthBulls_Get_Ready = Bulls_Get_Ready;
    monthBears_Get_Ready = Bears_Get_Ready;
    monthBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    monthBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    monthBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    monthBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    monthBull_Pullbacks = Bull_Pullbacks;
    monthBear_Pullbacks = Bear_Pullbacks;
    monthTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    monthTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    monthTrend_Bearish = Trend_Bearish;
    monthTrend_Bullish = Trend_Bullish;

}
else {
    monthAcceleration = 0;
    monthDeceleration = 0;
    monthDistribution = 0;
    monthAccumulation = 0;
    monthBulls_Get_Ready = 0;
    monthBears_Get_Ready = 0;
    monthBears_Get_Ready_Trend = 0;
    monthBulls_Get_Ready_Trend = 0;
    monthBears_Get_Ready_Trend1 = 0;
    monthBulls_Get_Ready_Trend1 = 0;
    monthBull_Pullbacks = 0;
    monthBear_Pullbacks = 0;
    monthTrend_Bearish_Invalid = 0;
    monthTrend_Bullish_Invalid = 0;
    monthTrend_Bearish = 0;
    monthTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if monthAcceleration
    then "M"
    else if monthDistribution
    then "M"
    else if monthBulls_Get_Ready
    then "M"
    else if monthBears_Get_Ready
    then "M"
    else if monthBears_Get_Ready_Trend
    then "M"
    else if monthBulls_Get_Ready_Trend
    then "M"
    else if monthBears_Get_Ready_Trend1
    then "M"
    else if monthBulls_Get_Ready_Trend1
    then "M"
    else if monthBull_Pullbacks
    then "M"
    else if monthBear_Pullbacks
    then "M"
    else if monthTrend_Bearish_Invalid
    then "M"
    else if monthTrend_Bullish_Invalid
    then "M"
    else if monthTrend_Bearish
    then "M"
    else if monthTrend_Bullish
    then "M"
    else ""
,
    if monthAccumulation
    then GlobalColor("Accum")
    else if monthDistribution
    then GlobalColor("Dist")
    else if monthBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if monthBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if monthBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if monthBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if monthBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if monthBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if monthBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if monthBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if monthTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if monthTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if monthTrend_Bearish
    then GlobalColor("Bearish")
    else if monthTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## week Aggregation Period Variables
def weekAcceleration;
def weekDeceleration;
def weekDistribution;
def weekAccumulation;
def weekBulls_Get_Ready;
def weekBears_Get_Ready;
def weekBears_Get_Ready_Trend;
def weekBulls_Get_Ready_Trend;
def weekBears_Get_Ready_Trend1;
def weekBulls_Get_Ready_Trend1;
def weekBull_Pullbacks;
def weekBear_Pullbacks;
def weekTrend_Bearish_Invalid;
def weekTrend_Bullish_Invalid;
def weekTrend_Bearish;
def weekTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    weekAcceleration = acceleration;
    weekDeceleration = deceleration;
    weekDistribution = distribution;
    weekAccumulation = accumulation;
    weekBulls_Get_Ready = Bulls_Get_Ready;
    weekBears_Get_Ready = Bears_Get_Ready;
    weekBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    weekBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    weekBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    weekBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    weekBull_Pullbacks = Bull_Pullbacks;
    weekBear_Pullbacks = Bear_Pullbacks;
    weekTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    weekTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    weekTrend_Bearish = Trend_Bearish;
    weekTrend_Bullish = Trend_Bullish;

}
else {
    weekAcceleration = 0;
    weekDeceleration = 0;
    weekDistribution = 0;
    weekAccumulation = 0;
    weekBulls_Get_Ready = 0;
    weekBears_Get_Ready = 0;
    weekBears_Get_Ready_Trend = 0;
    weekBulls_Get_Ready_Trend = 0;
    weekBears_Get_Ready_Trend1 = 0;
    weekBulls_Get_Ready_Trend1 = 0;
    weekBull_Pullbacks = 0;
    weekBear_Pullbacks = 0;
    weekTrend_Bearish_Invalid = 0;
    weekTrend_Bullish_Invalid = 0;
    weekTrend_Bearish = 0;
    weekTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if weekAcceleration
    then "W"
    else if weekDistribution
    then "W"
    else if weekBulls_Get_Ready
    then "W"
    else if weekBears_Get_Ready
    then "W"
    else if weekBears_Get_Ready_Trend
    then "W"
    else if weekBulls_Get_Ready_Trend
    then "W"
    else if weekBears_Get_Ready_Trend1
    then "W"
    else if weekBulls_Get_Ready_Trend1
    then "W"
    else if weekBull_Pullbacks
    then "W"
    else if weekBear_Pullbacks
    then "W"
    else if weekTrend_Bearish_Invalid
    then "W"
    else if weekTrend_Bullish_Invalid
    then "W"
    else if weekTrend_Bearish
    then "W"
    else if weekTrend_Bullish
    then "W"
    else ""
,
    if weekAccumulation
    then GlobalColor("Accum")
    else if weekDistribution
    then GlobalColor("Dist")
    else if weekBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if weekBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if weekBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if weekBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if weekBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if weekBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if weekBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if weekBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if weekTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if weekTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if weekTrend_Bearish
    then GlobalColor("Bearish")
    else if weekTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## day Aggregation Period Variables
def dayAcceleration;
def dayDeceleration;
def dayDistribution;
def dayAccumulation;
def dayBulls_Get_Ready;
def dayBears_Get_Ready;
def dayBears_Get_Ready_Trend;
def dayBulls_Get_Ready_Trend;
def dayBears_Get_Ready_Trend1;
def dayBulls_Get_Ready_Trend1;
def dayBull_Pullbacks;
def dayBear_Pullbacks;
def dayTrend_Bearish_Invalid;
def dayTrend_Bullish_Invalid;
def dayTrend_Bearish;
def dayTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.DAY {
    dayAcceleration = acceleration;
    dayDeceleration = deceleration;
    dayDistribution = distribution;
    dayAccumulation = accumulation;
    dayBulls_Get_Ready = Bulls_Get_Ready;
    dayBears_Get_Ready = Bears_Get_Ready;
    dayBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    dayBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    dayBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    dayBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    dayBull_Pullbacks = Bull_Pullbacks;
    dayBear_Pullbacks = Bear_Pullbacks;
    dayTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    dayTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    dayTrend_Bearish = Trend_Bearish;
    dayTrend_Bullish = Trend_Bullish;

}
else {
    dayAcceleration = 0;
    dayDeceleration = 0;
    dayDistribution = 0;
    dayAccumulation = 0;
    dayBulls_Get_Ready = 0;
    dayBears_Get_Ready = 0;
    dayBears_Get_Ready_Trend = 0;
    dayBulls_Get_Ready_Trend = 0;
    dayBears_Get_Ready_Trend1 = 0;
    dayBulls_Get_Ready_Trend1 = 0;
    dayBull_Pullbacks = 0;
    dayBear_Pullbacks = 0;
    dayTrend_Bearish_Invalid = 0;
    dayTrend_Bullish_Invalid = 0;
    dayTrend_Bearish = 0;
    dayTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if dayAcceleration
    then "D"
    else if dayDistribution
    then "D"
    else if dayBulls_Get_Ready
    then "D"
    else if dayBears_Get_Ready
    then "D"
    else if dayBears_Get_Ready_Trend
    then "D"
    else if dayBulls_Get_Ready_Trend
    then "D"
    else if dayBears_Get_Ready_Trend1
    then "D"
    else if dayBulls_Get_Ready_Trend1
    then "D"
    else if dayBull_Pullbacks
    then "D"
    else if dayBear_Pullbacks
    then "D"
    else if dayTrend_Bearish_Invalid
    then "D"
    else if dayTrend_Bullish_Invalid
    then "D"
    else if dayTrend_Bearish
    then "D"
    else if dayTrend_Bullish
    then "D"
    else ""
,
    if dayAccumulation
    then GlobalColor("Accum")
    else if dayDistribution
    then GlobalColor("Dist")
    else if dayBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if dayBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if dayBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if dayBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if dayBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if dayBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if dayBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if dayBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if dayTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if dayTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if dayTrend_Bearish
    then GlobalColor("Bearish")
    else if dayTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Four_hours Aggregation Period Variables
def Four_hoursAcceleration;
def Four_hoursDeceleration;
def Four_hoursDistribution;
def Four_hoursAccumulation;
def Four_hoursBulls_Get_Ready;
def Four_hoursBears_Get_Ready;
def Four_hoursBears_Get_Ready_Trend;
def Four_hoursBulls_Get_Ready_Trend;
def Four_hoursBears_Get_Ready_Trend1;
def Four_hoursBulls_Get_Ready_Trend1;
def Four_hoursBull_Pullbacks;
def Four_hoursBear_Pullbacks;
def Four_hoursTrend_Bearish_Invalid;
def Four_hoursTrend_Bullish_Invalid;
def Four_hoursTrend_Bearish;
def Four_hoursTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    Four_hoursAcceleration = acceleration;
    Four_hoursDeceleration = deceleration;
    Four_hoursDistribution = distribution;
    Four_hoursAccumulation = accumulation;
    Four_hoursBulls_Get_Ready = Bulls_Get_Ready;
    Four_hoursBears_Get_Ready = Bears_Get_Ready;
    Four_hoursBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Four_hoursBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Four_hoursBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Four_hoursBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Four_hoursBull_Pullbacks = Bull_Pullbacks;
    Four_hoursBear_Pullbacks = Bear_Pullbacks;
    Four_hoursTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Four_hoursTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Four_hoursTrend_Bearish = Trend_Bearish;
    Four_hoursTrend_Bullish = Trend_Bullish;

}
else {
    Four_hoursAcceleration = 0;
    Four_hoursDeceleration = 0;
    Four_hoursDistribution = 0;
    Four_hoursAccumulation = 0;
    Four_hoursBulls_Get_Ready = 0;
    Four_hoursBears_Get_Ready = 0;
    Four_hoursBears_Get_Ready_Trend = 0;
    Four_hoursBulls_Get_Ready_Trend = 0;
    Four_hoursBears_Get_Ready_Trend1 = 0;
    Four_hoursBulls_Get_Ready_Trend1 = 0;
    Four_hoursBull_Pullbacks = 0;
    Four_hoursBear_Pullbacks = 0;
    Four_hoursTrend_Bearish_Invalid = 0;
    Four_hoursTrend_Bullish_Invalid = 0;
    Four_hoursTrend_Bearish = 0;
    Four_hoursTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Four_hoursAcceleration
    then "4H"
    else if Four_hoursDistribution
    then "4H"
    else if Four_hoursBulls_Get_Ready
    then "4H"
    else if Four_hoursBears_Get_Ready
    then "4H"
    else if Four_hoursBears_Get_Ready_Trend
    then "4H"
    else if Four_hoursBulls_Get_Ready_Trend
    then "4H"
    else if Four_hoursBears_Get_Ready_Trend1
    then "4H"
    else if Four_hoursBulls_Get_Ready_Trend1
    then "4H"
    else if Four_hoursBull_Pullbacks
    then "4H"
    else if Four_hoursBear_Pullbacks
    then "4H"
    else if Four_hoursTrend_Bearish_Invalid
    then "4H"
    else if Four_hoursTrend_Bullish_Invalid
    then "4H"
    else if Four_hoursTrend_Bearish
    then "4H"
    else if Four_hoursTrend_Bullish
    then "4H"
    else ""
,
    if Four_hoursAccumulation
    then GlobalColor("Accum")
    else if Four_hoursDistribution
    then GlobalColor("Dist")
    else if Four_hoursBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Four_hoursBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Four_hoursTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Four_hoursTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Four_hoursTrend_Bearish
    then GlobalColor("Bearish")
    else if Four_hoursTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);




## hour Aggregation Period Variables
def hourAcceleration;
def hourDeceleration;
def hourDistribution;
def hourAccumulation;
def hourBulls_Get_Ready;
def hourBears_Get_Ready;
def hourBears_Get_Ready_Trend;
def hourBulls_Get_Ready_Trend;
def hourBears_Get_Ready_Trend1;
def hourBulls_Get_Ready_Trend1;
def hourBull_Pullbacks;
def hourBear_Pullbacks;
def hourTrend_Bearish_Invalid;
def hourTrend_Bullish_Invalid;
def hourTrend_Bearish;
def hourTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    hourAcceleration = acceleration;
    hourDeceleration = deceleration;
    hourDistribution = distribution;
    hourAccumulation = accumulation;
    hourBulls_Get_Ready = Bulls_Get_Ready;
    hourBears_Get_Ready = Bears_Get_Ready;
    hourBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    hourBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    hourBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    hourBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    hourBull_Pullbacks = Bull_Pullbacks;
    hourBear_Pullbacks = Bear_Pullbacks;
    hourTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    hourTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    hourTrend_Bearish = Trend_Bearish;
    hourTrend_Bullish = Trend_Bullish;

}
else {
    hourAcceleration = 0;
    hourDeceleration = 0;
    hourDistribution = 0;
    hourAccumulation = 0;
    hourBulls_Get_Ready = 0;
    hourBears_Get_Ready = 0;
    hourBears_Get_Ready_Trend = 0;
    hourBulls_Get_Ready_Trend = 0;
    hourBears_Get_Ready_Trend1 = 0;
    hourBulls_Get_Ready_Trend1 = 0;
    hourBull_Pullbacks = 0;
    hourBear_Pullbacks = 0;
    hourTrend_Bearish_Invalid = 0;
    hourTrend_Bullish_Invalid = 0;
    hourTrend_Bearish = 0;
    hourTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if hourAcceleration
    then "H"
    else if hourDistribution
    then "H"
    else if hourBulls_Get_Ready
    then "H"
    else if hourBears_Get_Ready
    then "H"
    else if hourBears_Get_Ready_Trend
    then "H"
    else if hourBulls_Get_Ready_Trend
    then "H"
    else if hourBears_Get_Ready_Trend1
    then "H"
    else if hourBulls_Get_Ready_Trend1
    then "H"
    else if hourBull_Pullbacks
    then "H"
    else if hourBear_Pullbacks
    then "H"
    else if hourTrend_Bearish_Invalid
    then "H"
    else if hourTrend_Bullish_Invalid
    then "H"
    else if hourTrend_Bearish
    then "H"
    else if hourTrend_Bullish
    then "H"
    else ""
,
    if hourAccumulation
    then GlobalColor("Accum")
    else if hourDistribution
    then GlobalColor("Dist")
    else if hourBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if hourBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if hourBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if hourBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if hourBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if hourBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if hourBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if hourBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if hourTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if hourTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if hourTrend_Bearish
    then GlobalColor("Bearish")
    else if hourTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Fifteen_Min Aggregation Period Variables
def Fifteen_MinAcceleration;
def Fifteen_MinDeceleration;
def Fifteen_MinDistribution;
def Fifteen_MinAccumulation;
def Fifteen_MinBulls_Get_Ready;
def Fifteen_MinBears_Get_Ready;
def Fifteen_MinBears_Get_Ready_Trend;
def Fifteen_MinBulls_Get_Ready_Trend;
def Fifteen_MinBears_Get_Ready_Trend1;
def Fifteen_MinBulls_Get_Ready_Trend1;
def Fifteen_MinBull_Pullbacks;
def Fifteen_MinBear_Pullbacks;
def Fifteen_MinTrend_Bearish_Invalid;
def Fifteen_MinTrend_Bullish_Invalid;
def Fifteen_MinTrend_Bearish;
def Fifteen_MinTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    Fifteen_MinAcceleration = acceleration;
    Fifteen_MinDeceleration = deceleration;
    Fifteen_MinDistribution = distribution;
    Fifteen_MinAccumulation = accumulation;
    Fifteen_MinBulls_Get_Ready = Bulls_Get_Ready;
    Fifteen_MinBears_Get_Ready = Bears_Get_Ready;
    Fifteen_MinBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Fifteen_MinBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Fifteen_MinBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Fifteen_MinBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Fifteen_MinBull_Pullbacks = Bull_Pullbacks;
    Fifteen_MinBear_Pullbacks = Bear_Pullbacks;
    Fifteen_MinTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Fifteen_MinTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Fifteen_MinTrend_Bearish = Trend_Bearish;
    Fifteen_MinTrend_Bullish = Trend_Bullish;

}
else {
    Fifteen_MinAcceleration = 0;
    Fifteen_MinDeceleration = 0;
    Fifteen_MinDistribution = 0;
    Fifteen_MinAccumulation = 0;
    Fifteen_MinBulls_Get_Ready = 0;
    Fifteen_MinBears_Get_Ready = 0;
    Fifteen_MinBears_Get_Ready_Trend = 0;
    Fifteen_MinBulls_Get_Ready_Trend = 0;
    Fifteen_MinBears_Get_Ready_Trend1 = 0;
    Fifteen_MinBulls_Get_Ready_Trend1 = 0;
    Fifteen_MinBull_Pullbacks = 0;
    Fifteen_MinBear_Pullbacks = 0;
    Fifteen_MinTrend_Bearish_Invalid = 0;
    Fifteen_MinTrend_Bullish_Invalid = 0;
    Fifteen_MinTrend_Bearish = 0;
    Fifteen_MinTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Fifteen_MinAcceleration
    then "15M"
    else if Fifteen_MinDistribution
    then "15M"
    else if Fifteen_MinBulls_Get_Ready
    then "15M"
    else if Fifteen_MinBears_Get_Ready
    then "15M"
    else if Fifteen_MinBears_Get_Ready_Trend
    then "15M"
    else if Fifteen_MinBulls_Get_Ready_Trend
    then "15M"
    else if Fifteen_MinBears_Get_Ready_Trend1
    then "15M"
    else if Fifteen_MinBulls_Get_Ready_Trend1
    then "15M"
    else if Fifteen_MinBull_Pullbacks
    then "15M"
    else if Fifteen_MinBear_Pullbacks
    then "15M"
    else if Fifteen_MinTrend_Bearish_Invalid
    then "15M"
    else if Fifteen_MinTrend_Bullish_Invalid
    then "15M"
    else if Fifteen_MinTrend_Bearish
    then "15M"
    else if Fifteen_MinTrend_Bullish
    then "15M"
    else ""
,
    if Fifteen_MinAccumulation
    then GlobalColor("Accum")
    else if Fifteen_MinDistribution
    then GlobalColor("Dist")
    else if Fifteen_MinBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Fifteen_MinBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Fifteen_MinTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Fifteen_MinTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Fifteen_MinTrend_Bearish
    then GlobalColor("Bearish")
    else if Fifteen_MinTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Five_Min Aggregation Period Variables
def Five_MinAcceleration;
def Five_MinDeceleration;
def Five_MinDistribution;
def Five_MinAccumulation;
def Five_MinBulls_Get_Ready;
def Five_MinBears_Get_Ready;
def Five_MinBears_Get_Ready_Trend;
def Five_MinBulls_Get_Ready_Trend;
def Five_MinBears_Get_Ready_Trend1;
def Five_MinBulls_Get_Ready_Trend1;
def Five_MinBull_Pullbacks;
def Five_MinBear_Pullbacks;
def Five_MinTrend_Bearish_Invalid;
def Five_MinTrend_Bullish_Invalid;
def Five_MinTrend_Bearish;
def Five_MinTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
    Five_MinAcceleration = acceleration;
    Five_MinDeceleration = deceleration;
    Five_MinDistribution = distribution;
    Five_MinAccumulation = accumulation;
    Five_MinBulls_Get_Ready = Bulls_Get_Ready;
    Five_MinBears_Get_Ready = Bears_Get_Ready;
    Five_MinBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Five_MinBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Five_MinBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Five_MinBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Five_MinBull_Pullbacks = Bull_Pullbacks;
    Five_MinBear_Pullbacks = Bear_Pullbacks;
    Five_MinTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Five_MinTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Five_MinTrend_Bearish = Trend_Bearish;
    Five_MinTrend_Bullish = Trend_Bullish;

}
else {
    Five_MinAcceleration = 0;
    Five_MinDeceleration = 0;
    Five_MinDistribution = 0;
    Five_MinAccumulation = 0;
    Five_MinBulls_Get_Ready = 0;
    Five_MinBears_Get_Ready = 0;
    Five_MinBears_Get_Ready_Trend = 0;
    Five_MinBulls_Get_Ready_Trend = 0;
    Five_MinBears_Get_Ready_Trend1 = 0;
    Five_MinBulls_Get_Ready_Trend1 = 0;
    Five_MinBull_Pullbacks = 0;
    Five_MinBear_Pullbacks = 0;
    Five_MinTrend_Bearish_Invalid = 0;
    Five_MinTrend_Bullish_Invalid = 0;
    Five_MinTrend_Bearish = 0;
    Five_MinTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Five_MinAcceleration
    then "5M"
    else if Five_MinDistribution
    then "5M"
    else if Five_MinBulls_Get_Ready
    then "5M"
    else if Five_MinBears_Get_Ready
    then "5M"
    else if Five_MinBears_Get_Ready_Trend
    then "5M"
    else if Five_MinBulls_Get_Ready_Trend
    then "5M"
    else if Five_MinBears_Get_Ready_Trend1
    then "5M"
    else if Five_MinBulls_Get_Ready_Trend1
    then "5M"
    else if Five_MinBull_Pullbacks
    then "5M"
    else if Five_MinBear_Pullbacks
    then "5M"
    else if Five_MinTrend_Bearish_Invalid
    then "5M"
    else if Five_MinTrend_Bullish_Invalid
    then "5M"
    else if Five_MinTrend_Bearish
    then "5M"
    else if Five_MinTrend_Bullish
    then "5M"
    else ""
,
    if Five_MinAccumulation
    then GlobalColor("Accum")
    else if Five_MinDistribution
    then GlobalColor("Dist")
    else if Five_MinBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Five_MinBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Five_MinBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Five_MinBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Five_MinBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Five_MinTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Five_MinTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Five_MinTrend_Bearish
    then GlobalColor("Bearish")
    else if Five_MinTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);
V0Bz2Ak.png
 
Last edited:
Im trying to create a MTF that reference the colors on the chart based on the close of the current candles on each timeframe. However, the MTF seems to aggregate the current bar color for all the MTF labels on higher timeframe.
The 5m chart is currently green indicating acceleration but it highlights ALL the MTF labels green. The middle 15m chart shows Violet and the left 1H shows Cyan. I believe it has something to do with the aggregation period portion of the code. Im not entirely sure where but I think im missing something that tells the code current timeframe to aggregate the higher timeframe based on a certain input MA_AggPeriod.


Code:
# MTF Candle Colors (Its based on where price closes in relation to the moving averages *Pictures does NOT show the moving averages)


# Input the aggregation period desired for the 50HMA
def timeFrame = GetAggregationPeriod();

input MA_AggPeriod = AggregationPeriod.WEEK;

# General length
input GlobalLength = 18;

# -- Pulse Inputs ----------
#input length = 8; # 3-8 is key range.
input pulseLength = 8; # 8 is a key Pulse Level!!


# -- General MA Inputs -------
input ShortMaLenght = 10; #10 is a key Level!!
#input VHMALength1 = 10; #10 is a key Level!!
input HMA50Length = 50; #50 is a key Level!!
input smalength = 200;


# Price inputs
input price = close;
input priceLow = low;
input priceHgh = High;

# -- Moving average types
input averageTypeHull = AverageType.HULL;


# --------------- END Spark's Super Trend Inputs ---------------












#---------------------------------  PULSE MA  -------------------------------

# Variable Moving Average (VMA) is an exponential moving average that adjusts its smoothing constant on the basis of market volatility.

# Lets define variables that track the movement of px.
def pxUp = if price > price[1] then price - price[1] else 0;
def pxDown = if price < price[1] then price + price[1] else 0;

# Lets define some variables that tracks the movement of price between a number of bars.
def sumPXUpBars = Sum(pxUp, pulseLength);
def sumPXDownBars = Sum(pxDown, pulseLength);

def sumPXBars = sumPXUpBars + sumPXDownBars == 0;

def ad3 = if sumPXBars then 0 else (sumPXUpBars - sumPXDownBars) / (sumPXUpBars + sumPXDownBars) * 100;

def coeff = 2 / (pulseLength + 1) * AbsValue(ad3) / 100;

def asd = CompoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);




#---------------------------------  END PULSE MA  -------------------------------







# --------------- Volume & HULL Weighted Moving Avg (VHMA & VWMA) ------------------------------

# Lets create 4 MAs.
def HMA10Hgh = MovingAverage(averageTypeHull, priceHgh, ShortMaLenght); #White/Gray


def VWMA10Low = Sum(volume * priceLow, ShortMaLenght) / Sum(volume, ShortMaLenght); #White/Gray

def HMA_50 = MovingAverage(averageTypeHull, price, HMA50Length);


def Time_Frame_HMA_50 = if timeFrame == AggregationPeriod.TWO_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.FIVE_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.FIFTEEN_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.THIRTY_MIN
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.HOUR
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.FOUR_HOURS
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
    else if timeFrame == AggregationPeriod.DAY
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)   
    else Double.NaN;


def SMA200 = Average(price, smalength);

#------- END Volume & HULL Weighted Moving Avg (VHMA & VWMA) ------------------------------








#  --------------------------------- Plot the MAs to the Chart ------------------------------

def VMA = asd; # Pulse  (Multi Colors)
#def Multi_TF_VMA = Time_frame_asd; # Pulse  (Multi Colors)
plot HMA50 = HMA_50;
plot Time_Frame_HMA50 = Time_Frame_HMA_50;
def VWMA10 = VWMA10Low; #White/Gray
def HMA10 = HMA10Hgh; #White/Gray
plot SMA = SMA200; #Gold/Grey

#  ---  END Plot the MAs to the Chart ----------


# ---- Define Market Phase -------

# Lets define areas of acceleration!! (ALL GOOD)!!
def acceleration = price >= VMA and priceLow > VWMA10 and VMA > VMA[1] and price > BB_Midline and priceLow >= Time_Frame_HMA50;


# Lets define areas of Deceleration!! (ALL GOOD)!!
def deceleration = price < VMA and priceHgh < HMA10 and VMA < VMA[1] and price < BB_Midline and priceHgh < Time_Frame_HMA50;

# Lets define areas of Accumulation!! (ALL GOOD)!!
def accumulation = priceLow < VMA and priceHgh > HMA10 and VMA > VMA[1] and price > Time_Frame_HMA50 and !acceleration;


# Lets define areas of Distribution!! (ALL GOOD)!!
def distribution = priceHgh > VMA and priceLow < VWMA10 and VMA < VMA[1]  and price < Time_Frame_HMA50 and !deceleration;


def Bulls_Get_Ready = price > Time_Frame_HMA50  and price < HMA50 and !accumulation and !acceleration and !distribution and !deceleration;

def Bulls_Get_Ready_Trend = Trend_Bullish and price > Time_Frame_HMA50  and price < HMA50 and !accumulation and !distribution and !deceleration;

def Bulls_Get_Ready_Trend1 = Trend_Bullish and price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !distribution;


def Bears_Get_Ready = price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !acceleration and !distribution and !deceleration;

def Bears_Get_Ready_Trend = Trend_Bearish and price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !acceleration and !distribution;

def Bears_Get_Ready_Trend1 = Trend_Bearish and price > Time_Frame_HMA50 and price < HMA50 and !accumulation and !distribution;




# ---------------  Global Candle Logic ----------------------


DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bull PullBack", Color.DARK_GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Bear PullBack", Color.DARK_RED);


DefineGlobalColor("Break Out", Color.GREEN);
DefineGlobalColor("Break Down", Color.RED);
DefineGlobalColor("Reject", Color.DARK_RED);
DefineGlobalColor("Bounce", Color.DARK_GREEN);


DefineGlobalColor("Overbought Bar", Color.YELLOW);
DefineGlobalColor("Oversold Bar", Color.YELLOW);
DefineGlobalColor("KC Power UP", Color.DARK_ORANGE);
DefineGlobalColor("KC Power Down", Color.DARK_ORANGE);
DefineGlobalColor("Impulse Bar", Color.PLUM);


DefineGlobalColor("Accel", Color.GREEN);
DefineGlobalColor("Accum", Color.WHITE);
DefineGlobalColor("Dist", Color.BLUE);
DefineGlobalColor("Decel", Color.RED);
DefineGlobalColor("Bulls Get Ready", Color.CYAN);
DefineGlobalColor("Bears Get Ready", Color.VIOLET);





# --------------- END Global Candle Logic ----------------------


def MTF_On = yes;


## Month Aggregation Period Variables
def monthAcceleration;
def monthDeceleration;
def monthDistribution;
def monthAccumulation;
def monthBulls_Get_Ready;
def monthBears_Get_Ready;
def monthBears_Get_Ready_Trend;
def monthBulls_Get_Ready_Trend;
def monthBears_Get_Ready_Trend1;
def monthBulls_Get_Ready_Trend1;
def monthBull_Pullbacks;
def monthBear_Pullbacks;
def monthTrend_Bearish_Invalid;
def monthTrend_Bullish_Invalid;
def monthTrend_Bearish;
def monthTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.MONTH {
    monthAcceleration = acceleration;
    monthDeceleration = deceleration;
    monthDistribution = distribution;
    monthAccumulation = accumulation;
    monthBulls_Get_Ready = Bulls_Get_Ready;
    monthBears_Get_Ready = Bears_Get_Ready;
    monthBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    monthBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    monthBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    monthBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    monthBull_Pullbacks = Bull_Pullbacks;
    monthBear_Pullbacks = Bear_Pullbacks;
    monthTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    monthTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    monthTrend_Bearish = Trend_Bearish;
    monthTrend_Bullish = Trend_Bullish;

}
else {
    monthAcceleration = 0;
    monthDeceleration = 0;
    monthDistribution = 0;
    monthAccumulation = 0;
    monthBulls_Get_Ready = 0;
    monthBears_Get_Ready = 0;
    monthBears_Get_Ready_Trend = 0;
    monthBulls_Get_Ready_Trend = 0;
    monthBears_Get_Ready_Trend1 = 0;
    monthBulls_Get_Ready_Trend1 = 0;
    monthBull_Pullbacks = 0;
    monthBear_Pullbacks = 0;
    monthTrend_Bearish_Invalid = 0;
    monthTrend_Bullish_Invalid = 0;
    monthTrend_Bearish = 0;
    monthTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if monthAcceleration
    then "M"
    else if monthDistribution
    then "M"
    else if monthBulls_Get_Ready
    then "M"
    else if monthBears_Get_Ready
    then "M"
    else if monthBears_Get_Ready_Trend
    then "M"
    else if monthBulls_Get_Ready_Trend
    then "M"
    else if monthBears_Get_Ready_Trend1
    then "M"
    else if monthBulls_Get_Ready_Trend1
    then "M"
    else if monthBull_Pullbacks
    then "M"
    else if monthBear_Pullbacks
    then "M"
    else if monthTrend_Bearish_Invalid
    then "M"
    else if monthTrend_Bullish_Invalid
    then "M"
    else if monthTrend_Bearish
    then "M"
    else if monthTrend_Bullish
    then "M"
    else ""
,
    if monthAccumulation
    then GlobalColor("Accum")
    else if monthDistribution
    then GlobalColor("Dist")
    else if monthBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if monthBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if monthBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if monthBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if monthBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if monthBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if monthBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if monthBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if monthTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if monthTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if monthTrend_Bearish
    then GlobalColor("Bearish")
    else if monthTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## week Aggregation Period Variables
def weekAcceleration;
def weekDeceleration;
def weekDistribution;
def weekAccumulation;
def weekBulls_Get_Ready;
def weekBears_Get_Ready;
def weekBears_Get_Ready_Trend;
def weekBulls_Get_Ready_Trend;
def weekBears_Get_Ready_Trend1;
def weekBulls_Get_Ready_Trend1;
def weekBull_Pullbacks;
def weekBear_Pullbacks;
def weekTrend_Bearish_Invalid;
def weekTrend_Bullish_Invalid;
def weekTrend_Bearish;
def weekTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    weekAcceleration = acceleration;
    weekDeceleration = deceleration;
    weekDistribution = distribution;
    weekAccumulation = accumulation;
    weekBulls_Get_Ready = Bulls_Get_Ready;
    weekBears_Get_Ready = Bears_Get_Ready;
    weekBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    weekBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    weekBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    weekBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    weekBull_Pullbacks = Bull_Pullbacks;
    weekBear_Pullbacks = Bear_Pullbacks;
    weekTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    weekTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    weekTrend_Bearish = Trend_Bearish;
    weekTrend_Bullish = Trend_Bullish;

}
else {
    weekAcceleration = 0;
    weekDeceleration = 0;
    weekDistribution = 0;
    weekAccumulation = 0;
    weekBulls_Get_Ready = 0;
    weekBears_Get_Ready = 0;
    weekBears_Get_Ready_Trend = 0;
    weekBulls_Get_Ready_Trend = 0;
    weekBears_Get_Ready_Trend1 = 0;
    weekBulls_Get_Ready_Trend1 = 0;
    weekBull_Pullbacks = 0;
    weekBear_Pullbacks = 0;
    weekTrend_Bearish_Invalid = 0;
    weekTrend_Bullish_Invalid = 0;
    weekTrend_Bearish = 0;
    weekTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if weekAcceleration
    then "W"
    else if weekDistribution
    then "W"
    else if weekBulls_Get_Ready
    then "W"
    else if weekBears_Get_Ready
    then "W"
    else if weekBears_Get_Ready_Trend
    then "W"
    else if weekBulls_Get_Ready_Trend
    then "W"
    else if weekBears_Get_Ready_Trend1
    then "W"
    else if weekBulls_Get_Ready_Trend1
    then "W"
    else if weekBull_Pullbacks
    then "W"
    else if weekBear_Pullbacks
    then "W"
    else if weekTrend_Bearish_Invalid
    then "W"
    else if weekTrend_Bullish_Invalid
    then "W"
    else if weekTrend_Bearish
    then "W"
    else if weekTrend_Bullish
    then "W"
    else ""
,
    if weekAccumulation
    then GlobalColor("Accum")
    else if weekDistribution
    then GlobalColor("Dist")
    else if weekBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if weekBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if weekBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if weekBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if weekBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if weekBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if weekBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if weekBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if weekTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if weekTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if weekTrend_Bearish
    then GlobalColor("Bearish")
    else if weekTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## day Aggregation Period Variables
def dayAcceleration;
def dayDeceleration;
def dayDistribution;
def dayAccumulation;
def dayBulls_Get_Ready;
def dayBears_Get_Ready;
def dayBears_Get_Ready_Trend;
def dayBulls_Get_Ready_Trend;
def dayBears_Get_Ready_Trend1;
def dayBulls_Get_Ready_Trend1;
def dayBull_Pullbacks;
def dayBear_Pullbacks;
def dayTrend_Bearish_Invalid;
def dayTrend_Bullish_Invalid;
def dayTrend_Bearish;
def dayTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.DAY {
    dayAcceleration = acceleration;
    dayDeceleration = deceleration;
    dayDistribution = distribution;
    dayAccumulation = accumulation;
    dayBulls_Get_Ready = Bulls_Get_Ready;
    dayBears_Get_Ready = Bears_Get_Ready;
    dayBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    dayBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    dayBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    dayBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    dayBull_Pullbacks = Bull_Pullbacks;
    dayBear_Pullbacks = Bear_Pullbacks;
    dayTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    dayTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    dayTrend_Bearish = Trend_Bearish;
    dayTrend_Bullish = Trend_Bullish;

}
else {
    dayAcceleration = 0;
    dayDeceleration = 0;
    dayDistribution = 0;
    dayAccumulation = 0;
    dayBulls_Get_Ready = 0;
    dayBears_Get_Ready = 0;
    dayBears_Get_Ready_Trend = 0;
    dayBulls_Get_Ready_Trend = 0;
    dayBears_Get_Ready_Trend1 = 0;
    dayBulls_Get_Ready_Trend1 = 0;
    dayBull_Pullbacks = 0;
    dayBear_Pullbacks = 0;
    dayTrend_Bearish_Invalid = 0;
    dayTrend_Bullish_Invalid = 0;
    dayTrend_Bearish = 0;
    dayTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if dayAcceleration
    then "D"
    else if dayDistribution
    then "D"
    else if dayBulls_Get_Ready
    then "D"
    else if dayBears_Get_Ready
    then "D"
    else if dayBears_Get_Ready_Trend
    then "D"
    else if dayBulls_Get_Ready_Trend
    then "D"
    else if dayBears_Get_Ready_Trend1
    then "D"
    else if dayBulls_Get_Ready_Trend1
    then "D"
    else if dayBull_Pullbacks
    then "D"
    else if dayBear_Pullbacks
    then "D"
    else if dayTrend_Bearish_Invalid
    then "D"
    else if dayTrend_Bullish_Invalid
    then "D"
    else if dayTrend_Bearish
    then "D"
    else if dayTrend_Bullish
    then "D"
    else ""
,
    if dayAccumulation
    then GlobalColor("Accum")
    else if dayDistribution
    then GlobalColor("Dist")
    else if dayBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if dayBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if dayBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if dayBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if dayBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if dayBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if dayBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if dayBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if dayTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if dayTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if dayTrend_Bearish
    then GlobalColor("Bearish")
    else if dayTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Four_hours Aggregation Period Variables
def Four_hoursAcceleration;
def Four_hoursDeceleration;
def Four_hoursDistribution;
def Four_hoursAccumulation;
def Four_hoursBulls_Get_Ready;
def Four_hoursBears_Get_Ready;
def Four_hoursBears_Get_Ready_Trend;
def Four_hoursBulls_Get_Ready_Trend;
def Four_hoursBears_Get_Ready_Trend1;
def Four_hoursBulls_Get_Ready_Trend1;
def Four_hoursBull_Pullbacks;
def Four_hoursBear_Pullbacks;
def Four_hoursTrend_Bearish_Invalid;
def Four_hoursTrend_Bullish_Invalid;
def Four_hoursTrend_Bearish;
def Four_hoursTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    Four_hoursAcceleration = acceleration;
    Four_hoursDeceleration = deceleration;
    Four_hoursDistribution = distribution;
    Four_hoursAccumulation = accumulation;
    Four_hoursBulls_Get_Ready = Bulls_Get_Ready;
    Four_hoursBears_Get_Ready = Bears_Get_Ready;
    Four_hoursBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Four_hoursBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Four_hoursBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Four_hoursBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Four_hoursBull_Pullbacks = Bull_Pullbacks;
    Four_hoursBear_Pullbacks = Bear_Pullbacks;
    Four_hoursTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Four_hoursTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Four_hoursTrend_Bearish = Trend_Bearish;
    Four_hoursTrend_Bullish = Trend_Bullish;

}
else {
    Four_hoursAcceleration = 0;
    Four_hoursDeceleration = 0;
    Four_hoursDistribution = 0;
    Four_hoursAccumulation = 0;
    Four_hoursBulls_Get_Ready = 0;
    Four_hoursBears_Get_Ready = 0;
    Four_hoursBears_Get_Ready_Trend = 0;
    Four_hoursBulls_Get_Ready_Trend = 0;
    Four_hoursBears_Get_Ready_Trend1 = 0;
    Four_hoursBulls_Get_Ready_Trend1 = 0;
    Four_hoursBull_Pullbacks = 0;
    Four_hoursBear_Pullbacks = 0;
    Four_hoursTrend_Bearish_Invalid = 0;
    Four_hoursTrend_Bullish_Invalid = 0;
    Four_hoursTrend_Bearish = 0;
    Four_hoursTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Four_hoursAcceleration
    then "4H"
    else if Four_hoursDistribution
    then "4H"
    else if Four_hoursBulls_Get_Ready
    then "4H"
    else if Four_hoursBears_Get_Ready
    then "4H"
    else if Four_hoursBears_Get_Ready_Trend
    then "4H"
    else if Four_hoursBulls_Get_Ready_Trend
    then "4H"
    else if Four_hoursBears_Get_Ready_Trend1
    then "4H"
    else if Four_hoursBulls_Get_Ready_Trend1
    then "4H"
    else if Four_hoursBull_Pullbacks
    then "4H"
    else if Four_hoursBear_Pullbacks
    then "4H"
    else if Four_hoursTrend_Bearish_Invalid
    then "4H"
    else if Four_hoursTrend_Bullish_Invalid
    then "4H"
    else if Four_hoursTrend_Bearish
    then "4H"
    else if Four_hoursTrend_Bullish
    then "4H"
    else ""
,
    if Four_hoursAccumulation
    then GlobalColor("Accum")
    else if Four_hoursDistribution
    then GlobalColor("Dist")
    else if Four_hoursBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Four_hoursBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Four_hoursTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Four_hoursTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Four_hoursTrend_Bearish
    then GlobalColor("Bearish")
    else if Four_hoursTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);




## hour Aggregation Period Variables
def hourAcceleration;
def hourDeceleration;
def hourDistribution;
def hourAccumulation;
def hourBulls_Get_Ready;
def hourBears_Get_Ready;
def hourBears_Get_Ready_Trend;
def hourBulls_Get_Ready_Trend;
def hourBears_Get_Ready_Trend1;
def hourBulls_Get_Ready_Trend1;
def hourBull_Pullbacks;
def hourBear_Pullbacks;
def hourTrend_Bearish_Invalid;
def hourTrend_Bullish_Invalid;
def hourTrend_Bearish;
def hourTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    hourAcceleration = acceleration;
    hourDeceleration = deceleration;
    hourDistribution = distribution;
    hourAccumulation = accumulation;
    hourBulls_Get_Ready = Bulls_Get_Ready;
    hourBears_Get_Ready = Bears_Get_Ready;
    hourBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    hourBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    hourBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    hourBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    hourBull_Pullbacks = Bull_Pullbacks;
    hourBear_Pullbacks = Bear_Pullbacks;
    hourTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    hourTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    hourTrend_Bearish = Trend_Bearish;
    hourTrend_Bullish = Trend_Bullish;

}
else {
    hourAcceleration = 0;
    hourDeceleration = 0;
    hourDistribution = 0;
    hourAccumulation = 0;
    hourBulls_Get_Ready = 0;
    hourBears_Get_Ready = 0;
    hourBears_Get_Ready_Trend = 0;
    hourBulls_Get_Ready_Trend = 0;
    hourBears_Get_Ready_Trend1 = 0;
    hourBulls_Get_Ready_Trend1 = 0;
    hourBull_Pullbacks = 0;
    hourBear_Pullbacks = 0;
    hourTrend_Bearish_Invalid = 0;
    hourTrend_Bullish_Invalid = 0;
    hourTrend_Bearish = 0;
    hourTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if hourAcceleration
    then "H"
    else if hourDistribution
    then "H"
    else if hourBulls_Get_Ready
    then "H"
    else if hourBears_Get_Ready
    then "H"
    else if hourBears_Get_Ready_Trend
    then "H"
    else if hourBulls_Get_Ready_Trend
    then "H"
    else if hourBears_Get_Ready_Trend1
    then "H"
    else if hourBulls_Get_Ready_Trend1
    then "H"
    else if hourBull_Pullbacks
    then "H"
    else if hourBear_Pullbacks
    then "H"
    else if hourTrend_Bearish_Invalid
    then "H"
    else if hourTrend_Bullish_Invalid
    then "H"
    else if hourTrend_Bearish
    then "H"
    else if hourTrend_Bullish
    then "H"
    else ""
,
    if hourAccumulation
    then GlobalColor("Accum")
    else if hourDistribution
    then GlobalColor("Dist")
    else if hourBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if hourBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if hourBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if hourBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if hourBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if hourBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if hourBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if hourBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if hourTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if hourTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if hourTrend_Bearish
    then GlobalColor("Bearish")
    else if hourTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Fifteen_Min Aggregation Period Variables
def Fifteen_MinAcceleration;
def Fifteen_MinDeceleration;
def Fifteen_MinDistribution;
def Fifteen_MinAccumulation;
def Fifteen_MinBulls_Get_Ready;
def Fifteen_MinBears_Get_Ready;
def Fifteen_MinBears_Get_Ready_Trend;
def Fifteen_MinBulls_Get_Ready_Trend;
def Fifteen_MinBears_Get_Ready_Trend1;
def Fifteen_MinBulls_Get_Ready_Trend1;
def Fifteen_MinBull_Pullbacks;
def Fifteen_MinBear_Pullbacks;
def Fifteen_MinTrend_Bearish_Invalid;
def Fifteen_MinTrend_Bullish_Invalid;
def Fifteen_MinTrend_Bearish;
def Fifteen_MinTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    Fifteen_MinAcceleration = acceleration;
    Fifteen_MinDeceleration = deceleration;
    Fifteen_MinDistribution = distribution;
    Fifteen_MinAccumulation = accumulation;
    Fifteen_MinBulls_Get_Ready = Bulls_Get_Ready;
    Fifteen_MinBears_Get_Ready = Bears_Get_Ready;
    Fifteen_MinBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Fifteen_MinBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Fifteen_MinBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Fifteen_MinBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Fifteen_MinBull_Pullbacks = Bull_Pullbacks;
    Fifteen_MinBear_Pullbacks = Bear_Pullbacks;
    Fifteen_MinTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Fifteen_MinTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Fifteen_MinTrend_Bearish = Trend_Bearish;
    Fifteen_MinTrend_Bullish = Trend_Bullish;

}
else {
    Fifteen_MinAcceleration = 0;
    Fifteen_MinDeceleration = 0;
    Fifteen_MinDistribution = 0;
    Fifteen_MinAccumulation = 0;
    Fifteen_MinBulls_Get_Ready = 0;
    Fifteen_MinBears_Get_Ready = 0;
    Fifteen_MinBears_Get_Ready_Trend = 0;
    Fifteen_MinBulls_Get_Ready_Trend = 0;
    Fifteen_MinBears_Get_Ready_Trend1 = 0;
    Fifteen_MinBulls_Get_Ready_Trend1 = 0;
    Fifteen_MinBull_Pullbacks = 0;
    Fifteen_MinBear_Pullbacks = 0;
    Fifteen_MinTrend_Bearish_Invalid = 0;
    Fifteen_MinTrend_Bullish_Invalid = 0;
    Fifteen_MinTrend_Bearish = 0;
    Fifteen_MinTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Fifteen_MinAcceleration
    then "15M"
    else if Fifteen_MinDistribution
    then "15M"
    else if Fifteen_MinBulls_Get_Ready
    then "15M"
    else if Fifteen_MinBears_Get_Ready
    then "15M"
    else if Fifteen_MinBears_Get_Ready_Trend
    then "15M"
    else if Fifteen_MinBulls_Get_Ready_Trend
    then "15M"
    else if Fifteen_MinBears_Get_Ready_Trend1
    then "15M"
    else if Fifteen_MinBulls_Get_Ready_Trend1
    then "15M"
    else if Fifteen_MinBull_Pullbacks
    then "15M"
    else if Fifteen_MinBear_Pullbacks
    then "15M"
    else if Fifteen_MinTrend_Bearish_Invalid
    then "15M"
    else if Fifteen_MinTrend_Bullish_Invalid
    then "15M"
    else if Fifteen_MinTrend_Bearish
    then "15M"
    else if Fifteen_MinTrend_Bullish
    then "15M"
    else ""
,
    if Fifteen_MinAccumulation
    then GlobalColor("Accum")
    else if Fifteen_MinDistribution
    then GlobalColor("Dist")
    else if Fifteen_MinBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Fifteen_MinBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Fifteen_MinTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Fifteen_MinTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Fifteen_MinTrend_Bearish
    then GlobalColor("Bearish")
    else if Fifteen_MinTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Five_Min Aggregation Period Variables
def Five_MinAcceleration;
def Five_MinDeceleration;
def Five_MinDistribution;
def Five_MinAccumulation;
def Five_MinBulls_Get_Ready;
def Five_MinBears_Get_Ready;
def Five_MinBears_Get_Ready_Trend;
def Five_MinBulls_Get_Ready_Trend;
def Five_MinBears_Get_Ready_Trend1;
def Five_MinBulls_Get_Ready_Trend1;
def Five_MinBull_Pullbacks;
def Five_MinBear_Pullbacks;
def Five_MinTrend_Bearish_Invalid;
def Five_MinTrend_Bullish_Invalid;
def Five_MinTrend_Bearish;
def Five_MinTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
    Five_MinAcceleration = acceleration;
    Five_MinDeceleration = deceleration;
    Five_MinDistribution = distribution;
    Five_MinAccumulation = accumulation;
    Five_MinBulls_Get_Ready = Bulls_Get_Ready;
    Five_MinBears_Get_Ready = Bears_Get_Ready;
    Five_MinBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Five_MinBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Five_MinBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Five_MinBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Five_MinBull_Pullbacks = Bull_Pullbacks;
    Five_MinBear_Pullbacks = Bear_Pullbacks;
    Five_MinTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Five_MinTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Five_MinTrend_Bearish = Trend_Bearish;
    Five_MinTrend_Bullish = Trend_Bullish;

}
else {
    Five_MinAcceleration = 0;
    Five_MinDeceleration = 0;
    Five_MinDistribution = 0;
    Five_MinAccumulation = 0;
    Five_MinBulls_Get_Ready = 0;
    Five_MinBears_Get_Ready = 0;
    Five_MinBears_Get_Ready_Trend = 0;
    Five_MinBulls_Get_Ready_Trend = 0;
    Five_MinBears_Get_Ready_Trend1 = 0;
    Five_MinBulls_Get_Ready_Trend1 = 0;
    Five_MinBull_Pullbacks = 0;
    Five_MinBear_Pullbacks = 0;
    Five_MinTrend_Bearish_Invalid = 0;
    Five_MinTrend_Bullish_Invalid = 0;
    Five_MinTrend_Bearish = 0;
    Five_MinTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Five_MinAcceleration
    then "5M"
    else if Five_MinDistribution
    then "5M"
    else if Five_MinBulls_Get_Ready
    then "5M"
    else if Five_MinBears_Get_Ready
    then "5M"
    else if Five_MinBears_Get_Ready_Trend
    then "5M"
    else if Five_MinBulls_Get_Ready_Trend
    then "5M"
    else if Five_MinBears_Get_Ready_Trend1
    then "5M"
    else if Five_MinBulls_Get_Ready_Trend1
    then "5M"
    else if Five_MinBull_Pullbacks
    then "5M"
    else if Five_MinBear_Pullbacks
    then "5M"
    else if Five_MinTrend_Bearish_Invalid
    then "5M"
    else if Five_MinTrend_Bullish_Invalid
    then "5M"
    else if Five_MinTrend_Bearish
    then "5M"
    else if Five_MinTrend_Bullish
    then "5M"
    else ""
,
    if Five_MinAccumulation
    then GlobalColor("Accum")
    else if Five_MinDistribution
    then GlobalColor("Dist")
    else if Five_MinBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Five_MinBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Five_MinBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Five_MinBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Five_MinBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Five_MinTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Five_MinTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Five_MinTrend_Bearish
    then GlobalColor("Bearish")
    else if Five_MinTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);

you posted incomplete code, so there is nothing anyone can do

these 6 variables ( on the right) are not defined, they don't exist.
. so we have no idea what are supposed to be the signals.

monthBull_Pullbacks = Bull_Pullbacks;
monthBear_Pullbacks = Bear_Pullbacks;
monthTrend_Bearish_Invalid = Trend_Bearish_Invalid;
monthTrend_Bullish_Invalid = Trend_Bullish_Invalid;
monthTrend_Bearish = Trend_Bearish;
monthTrend_Bullish = Trend_Bullish;


edit post #1, and delete the code
then paste in complete code


------------------

code lines like this seem like overkill.
checking for 8 values, then setting all of them to the same thing....
might be easier to check for a non desired condition , to set one value, or set this value.

maybe using > , if an agg time is greater than day, then this else that....


def Time_Frame_HMA_50 = if timeFrame == AggregationPeriod.TWO_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FIVE_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FIFTEEN_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.THIRTY_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.HOUR
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FOUR_HOURS
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.DAY
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else Double.NaN;
 
you posted incomplete code, so there is nothing anyone can do

these 6 variables ( on the right) are not defined, they don't exist.
. so we have no idea what are supposed to be the signals.

monthBull_Pullbacks = Bull_Pullbacks;
monthBear_Pullbacks = Bear_Pullbacks;
monthTrend_Bearish_Invalid = Trend_Bearish_Invalid;
monthTrend_Bullish_Invalid = Trend_Bullish_Invalid;
monthTrend_Bearish = Trend_Bearish;
monthTrend_Bullish = Trend_Bullish;


edit post #1, and delete the code
then paste in complete code


------------------

code lines like this seem like overkill.
checking for 8 values, then setting all of them to the same thing....
might be easier to check for a non desired condition , to set one value, or set this value.

maybe using > , if an agg time is greater than day, then this else that....
Ruby:
def Time_Frame_HMA_50 = if timeFrame == AggregationPeriod.TWO_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FIVE_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FIFTEEN_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.THIRTY_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.HOUR
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FOUR_HOURS
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.DAY
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else Double.NaN;

Hi, thanks for the reply.
I edited the code above to reflect the variables that were undefined. I also mentioned that im trying to understand the overkill message with the aggregation portion of the code. Please let me know if the updated code is helpful.
 
Last edited by a moderator:
you posted incomplete code, so there is nothing anyone can do

these 6 variables ( on the right) are not defined, they don't exist.
. so we have no idea what are supposed to be the signals.

monthBull_Pullbacks = Bull_Pullbacks;
monthBear_Pullbacks = Bear_Pullbacks;
monthTrend_Bearish_Invalid = Trend_Bearish_Invalid;
monthTrend_Bullish_Invalid = Trend_Bullish_Invalid;
monthTrend_Bearish = Trend_Bearish;
monthTrend_Bullish = Trend_Bullish;


edit post #1, and delete the code
then paste in complete code


------------------

code lines like this seem like overkill.
checking for 8 values, then setting all of them to the same thing....
might be easier to check for a non desired condition , to set one value, or set this value.

maybe using > , if an agg time is greater than day, then this else that....


def Time_Frame_HMA_50 = if timeFrame == AggregationPeriod.TWO_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FIVE_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FIFTEEN_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.THIRTY_MIN
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.HOUR
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.FOUR_HOURS
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else if timeFrame == AggregationPeriod.DAY
then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)
else Double.NaN;
I finally figured out what you meant about the aggregation period and altered the code to search for timeframe above two mins then applied the input variable .. it was actually quite easy once I really sat down to think about it .. this reduced the lines of code while still accomplishing the same thing.

Hi Ben, does the updated thread explains my goal a little better? I think the hard part is that there is an input function that lets the user choose the 2nd aggregated moving average on any given chart time.. the trick will be telling the current timeframe (say the 5m) what the input aggregation moving average is for the the 15m chart. I think I might have to hard code the time frame dynamic then maybe the MTF will be able to know what the candle color is based on those parameters
 
Last edited by a moderator:
im trying to understand the overkill message with the aggregation portion of the code. Please let me know if the updated code is helpful.

reply to #4

no, you just repeated the same thing.
you completely missed my point.

you have 7 branches in an if then, all calculating the exact same thing?? why?



how about testing for the na condition first. then if it isn't an na timeframe, greater than a day, then calc an average.

def Time_Frame_HMA_50 = if timeFrame > AggregationPeriod.day then double.nan else MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length);
 
reply to #4

no, you just repeated the same thing.
you completely missed my point.

you have 7 branches in an if then, all calculating the exact same thing?? why?



how about testing for the na condition first. then if it isn't an na timeframe, greater than a day, then calc an average.

def Time_Frame_HMA_50 = if timeFrame > AggregationPeriod.day then double.nan else MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length);
Hey bud, im not sure how I didn't post the edited version after your suggestion but this was the alteration that I made and thought I pasted when I responded to your suggestion. I see that you replied with an example using > the day. This was definitely a better way and reduced the lines of code so thanks ALOT for that catch.
Code:
def Time_Frame_HMA_50 = if timeFrame >= AggregationPeriod.MIN 
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)   
    else Double.NaN;

Basically describes that if the selected timeframe is >= min then add the user input timeframe (period = MA_AggPeriod) or do nothing (Double.NaN). I see that you put Double.NaN first; is there a specific reason for that or is it all the same.
 
Usethinkscript main thread:
https://usethinkscript.com/threads/rob-smiths-the-strat-indicator-for-thinkorswim.3312/post-126193

Please watch this 10 minute tutorial for how to configure and use this study:

TOS code:
https://tos.mx/JZROQzW

This may work for you.
Hey Bob, thanks for this link. I finally took a good look at his code and think I might be on to something. Looks like I would have to that script for every time frame and add it to every chart. I'll let you know how it turns out.
 
hey maybe this new code helps?

Code:
# MTF Candle Colors (Its based on where price closes in relation to the moving averages *Pictures does NOT show the moving averages)


# Input the aggregation period desired for the 50HMA
def timeFrame = GetAggregationPeriod();

def M2_AggPeriod = AggregationPeriod.FIFTEEN_MIN;
def M5_AggPeriod = AggregationPeriod.FIFTEEN_MIN;
def M15_AggPeriod = AggregationPeriod.HOUR;
def M30_AggPeriod = AggregationPeriod.HOUR;
def H1_AggPeriod = AggregationPeriod.FOUR_HOURS;
def H4_AggPeriod = AggregationPeriod.DAY;
def D_AggPeriod = AggregationPeriod.WEEK;

def MA_AggPeriod = if M2_AggPeriod then M2_AggPeriod
    else if M5_AggPeriod then M5_AggPeriod
    else if M15_AggPeriod then M15_AggPeriod
    else if M30_AggPeriod then M30_AggPeriod
    else if H1_AggPeriod then H1_AggPeriod
    else if H4_AggPeriod then H4_AggPeriod
    else  D_AggPeriod;

# General length
input GlobalLength = 18;

# -- Pulse Inputs ----------
#input length = 8; # 3-8 is key range.
input pulseLength = 8; # 8 is a key Pulse Level!!


# -- General MA Inputs -------
input ShortMaLenght = 10; #10 is a key Level!!
#input VHMALength1 = 10; #10 is a key Level!!
input HMA50Length = 50; #50 is a key Level!!
input smalength = 200;


# Price inputs
input price = close;
input priceLow = low;
input priceHgh = High;

# -- Moving average types
input averageTypeHull = AverageType.HULL;


# --------------- END Spark's Super Trend Inputs ---------------












#---------------------------------  PULSE MA  -------------------------------

# Variable Moving Average (VMA) is an exponential moving average that adjusts its smoothing constant on the basis of market volatility.

# Lets define variables that track the movement of px.
def pxUp = if price > price[1] then price - price[1] else 0;
def pxDown = if price < price[1] then price + price[1] else 0;

# Lets define some variables that tracks the movement of price between a number of bars.
def sumPXUpBars = Sum(pxUp, pulseLength);
def sumPXDownBars = Sum(pxDown, pulseLength);

def sumPXBars = sumPXUpBars + sumPXDownBars == 0;

def ad3 = if sumPXBars then 0 else (sumPXUpBars - sumPXDownBars) / (sumPXUpBars + sumPXDownBars) * 100;

def coeff = 2 / (pulseLength + 1) * AbsValue(ad3) / 100;

def asd = CompoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);




#---------------------------------  END PULSE MA  -------------------------------







# --------------- Volume & HULL Weighted Moving Avg (VHMA & VWMA) ------------------------------

# Lets create 4 MAs.
def HMA10Hgh = MovingAverage(averageTypeHull, priceHgh, ShortMaLenght); #White/Gray


def VWMA10Low = Sum(volume * priceLow, ShortMaLenght) / Sum(volume, ShortMaLenght); #White/Gray

def HMA_50 = MovingAverage(averageTypeHull, price, HMA50Length);

def Time_Frame_HMA_50 = if timeFrame >= AggregationPeriod.MIN 
    then MovingAverage(averageTypeHull, close (period = MA_AggPeriod), HMA50Length)   
    else Double.NaN;



def SMA200 = Average(price, smalength);

#------- END Volume & HULL Weighted Moving Avg (VHMA & VWMA) ------------------------------








#  --------------------------------- Plot the MAs to the Chart ------------------------------

def VMA = asd; # Pulse  (Multi Colors)
#def Multi_TF_VMA = Time_frame_asd; # Pulse  (Multi Colors)
plot HMA50 = HMA_50;
plot Time_Frame_HMA50 = Time_Frame_HMA_50;
def VWMA10 = VWMA10Low; #White/Gray
def HMA10 = HMA10Hgh; #White/Gray
plot SMA = SMA200; #Gold/Grey

#  ---  END Plot the MAs to the Chart ----------





# -------------- BB & KC Channel -------------------


input BBCloudsOn = yes;
input BBBandsOn = yes;
input KCBandsOn = yes;
#input KCFactor = 1.0;


# ----------- Plot Mid Upper and Lower BB Line ------------

def BB_Midline = BollingerBands().MidLine;
plot BBM = if BBBandsOn then BB_Midline else Double.NaN;
# Upper BB Line
def BB_Upperband = BollingerBands().UpperBand;
plot BBH = if BBBandsOn and priceHgh >= BB_Upperband then BB_Upperband else Double.NaN;
# Lower Bb Line
def BB_Lowerband = BollingerBands().LowerBand;
plot BBL = if BBBandsOn and priceLow <= BB_Lowerband then BB_Lowerband else Double.NaN;

# Assign direction to the BB bands
def BB_Midline_Up = BB_Midline > BB_Midline[1] and priceLow > BB_Midline;
def BB_Midline_DOWN = BB_Midline < BB_Midline[1] and priceHgh < BB_Midline;
def BB_Bands_UP = (BB_Upperband > BB_Upperband[1]) and (BB_Lowerband > BB_Lowerband[1]);
def BB_Bands_Down = (BB_Upperband < BB_Upperband[1]) and (BB_Lowerband < BB_Lowerband[1]);


BBH.SetLineWeight(3);
BBH.SetStyle(Curve.LONG_DASH);
BBH.AssignValueColor(if BB_Bands_UP
    then Color.LIGHT_GREEN
    else Color.LIGHT_RED);

# Set syle for BB Midline
BBM.SetLineWeight(1);
BBM.SetStyle(Curve.FIRM);
BBM.AssignValueColor(if BB_Midline_Up
    then Color.LIGHT_GREEN
    else Color.LIGHT_RED);


BBL.SetLineWeight(3);
BBL.SetStyle(Curve.LONG_DASH);
BBL.AssignValueColor(if BB_Bands_Down
    then Color.LIGHT_RED
    else Color.LIGHT_GREEN);



#  -------------- Plot Mid upper and lower KC Line --------------

def KC_Midline =   KeltnerChannels().Avg;
plot KCM = if KCBandsOn then KC_Midline else Double.NaN;

# Upper KC Line
def KC_Upperband =   KeltnerChannels().Upper_Band;
plot KCH = if KCBandsOn and priceHgh >= KC_Upperband  then KC_Upperband else Double.NaN;

# Lower KC Line
def KC_lowerband =   KeltnerChannels().Lower_Band;
plot KCL = if KCBandsOn and priceLow <= KC_lowerband then KC_lowerband else Double.NaN;  



# Assign direction to the kc bands
def KC_Midline_Up = KC_Midline > KC_Midline[1] and price > KC_Midline;
def KC_Bands_UP = (KC_Upperband > KC_Upperband[1]) and (KC_lowerband > KC_lowerband[1]);
def KC_Bands_Down = (KC_Upperband < KC_Upperband[1]) and (KC_lowerband < KC_lowerband[1]);


KCH.SetLineWeight(3);
KCH.SetStyle(Curve.SHORT_DASH);
KCH.AssignValueColor(if KC_Bands_UP
   then Color.PLUM
   else Color.BLUE);


# Style the mid line
KCM.SetLineWeight(4);
KCM.SetStyle(Curve.FIRM);
KCM.AssignValueColor(if KC_Midline_Up
   then Color.DARK_GREEN
   else Color.DARK_RED);


KCL.SetLineWeight(3);
KCL.SetStyle(Curve.SHORT_DASH);
KCL.AssignValueColor(if KC_Bands_Down
    then Color.BLUE
    else Color.PLUM);


# ---------------- BB&KC Indicator --------------





# -----------  BB & KC Bands Squeeze Clouds -------------

# When the BB upper and lower bands cross inside the KC's we are in a Squeeze. The code below should activate a certain color to indicate this.

DefineGlobalColor("BB Squeeze", Color.GREEN);
DefineGlobalColor("BB UnSqueezed", Color.CURRENT);

AddCloud(KC_Upperband, BB_Upperband, GlobalColor("BB Squeeze"), GlobalColor("BB UnSqueezed"));
AddCloud(BB_Lowerband, KC_lowerband, GlobalColor("BB Squeeze"), GlobalColor("BB UnSqueezed"));




# ------------ Bull/Bear ATR Trend  ---------------------

# Average True Range Inputs
input ATRlength = 14; # 9-38 Key Level
#input ATRs = 2.5; #1 key Level

# Cacl EMA to be used as a point of reference.
def ATR_EMA = ExpAverage(close, ATRlength);





# ---------------------------- Identify Market Conditions, PX Action & Strategies ---------------------------

# -----------------  Px Action & MKT Structures ----------------

def Bull_Mkt = price > HMA50 and HMA50 >= Time_Frame_HMA_50;

#AddChartBubble (yes and Bull_Mkt and !Bull_Mkt[1], priceLow, "MKT", Color.DARK_GREEN);


def Bear_Mkt = price < HMA50 and HMA50 <= Time_Frame_HMA_50;


#AddChartBubble (yes and Bear_Mkt and !Bear_Mkt[1], priceHgh, "MKT", Color.DARK_RED);








# -------------- Bull/Bear Stacked Ma's -----------------

def Bull_Stack = HMA10 > VMA and VMA >= HMA50 and HMA50 > Time_Frame_HMA_50;

def Bear_Stack = VWMA10 < VMA and VMA < HMA50 and HMA50 < Time_Frame_HMA_50;



# ------- Bullish/Bearish Trend ------------

# Bullish Trend
def Trend_Bullish = VMA > ATR_EMA;

def Trend_Bullish_Invalid =  VMA > ATR_EMA and price < HMA50 and price < Time_Frame_HMA50;

#AddChartBubble (Trend_Buy_Sell_Bubble_On and Trend_Bullish and ! Trend_Bullish[1], priceLow, "B", Color.GREEN);


# Bearish Trend
def Trend_Bearish = VMA < ATR_EMA;

def Trend_Bearish_Invalid =  VMA < ATR_EMA and price > HMA50 and price > Time_Frame_HMA50;

#AddChartBubble (Trend_Buy_Sell_Bubble_On and Trend_Bearish and ! Trend_Bearish[1], priceHgh, "S", Color.RED);





#--------- Bull Pull Backs & Chart Bubbles --------

# Lets define a Bullish Pull back! (ALL GOOD)!!
def Bull_Pullbacks = (Trend_Bullish and priceLow <= priceLow[2] and price > Time_Frame_HMA50) or  (priceLow <= VWMA10 and price > Time_Frame_HMA50);

plot Bull_Pullback = Bull_Pullbacks;

Bull_Pullback.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
Bull_Pullback.SetDefaultColor(Color.GREEN);



# ------------- Bear Pull Backs & Chart Bubbles -----------

# Lets define a Bearish Pull back! (ALL GOOD)!!
def Bear_Pullbacks = (Trend_Bearish and priceHgh > priceHgh[2] and price < Time_Frame_HMA50) or (priceHgh > HMA10 and price < Time_Frame_HMA50);

#(Trend_Bearish and priceHgh >= HMA10 and price < HMA50) or (Trend_Bearish and priceHgh >= VMA and price < HMA50) ;

plot Bear_Pullback = Bear_Pullbacks;

Bear_Pullback.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
Bear_Pullback.SetDefaultColor(Color.RED);












# -------- Bull/Bear Push  ----
def BB_Bullish_Push = HMA10 >= KC_Upperband and priceHgh >= KC_Upperband;

def Bull_PX_Push = priceHgh > HMA10 and price > VMA and priceLow >= HMA50;

#AddChartBubble (PX_Buy_Sell_Bubbles_On and Bull_PX_Push and !Bull_PX_Push[1], priceLow, "B", Color.PLUM);


def BB_Bearish_Flush = VWMA10 < KC_lowerband and priceLow <= KC_lowerband;

def Bear_PX_Flush = priceLow < VWMA10 and price < VMA and priceHgh < HMA50;


#AddChartBubble (PX_Buy_Sell_Bubbles_On and Bear_PX_Flush and !Bear_PX_Flush[1], priceHgh, "S", Color.MAGENTA);




# ------------ Impusle Bar Candle ------------

def Impulse_Bar = high > KC_Upperband  and low < KC_lowerband;



# ---- Define Market Phase -------

# Lets define areas of acceleration!! (ALL GOOD)!!
def acceleration = price >= VMA and priceLow > VWMA10 and VMA > VMA[1] and price > BB_Midline and priceLow >= Time_Frame_HMA50;


# Lets define areas of Deceleration!! (ALL GOOD)!!
def deceleration = price < VMA and priceHgh < HMA10 and VMA < VMA[1] and price < BB_Midline and priceHgh < Time_Frame_HMA50;

# Lets define areas of Accumulation!! (ALL GOOD)!!
def accumulation = priceLow < VMA and priceHgh > HMA10 and VMA > VMA[1] and price > Time_Frame_HMA50 and !acceleration;


# Lets define areas of Distribution!! (ALL GOOD)!!
def distribution = priceHgh > VMA and priceLow < VWMA10 and VMA < VMA[1]  and price < Time_Frame_HMA50 and !deceleration;


def Bulls_Get_Ready = price > Time_Frame_HMA50  and price < HMA50 and !accumulation and !acceleration and !distribution and !deceleration;

def Bulls_Get_Ready_Trend = Trend_Bullish and price > Time_Frame_HMA50  and price < HMA50 and !accumulation and !distribution and !deceleration;

def Bulls_Get_Ready_Trend1 = Trend_Bullish and price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !distribution;


def Bears_Get_Ready = price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !acceleration and !distribution and !deceleration;

def Bears_Get_Ready_Trend = Trend_Bearish and price < Time_Frame_HMA50 and price > HMA50 and !accumulation and !acceleration and !distribution;

def Bears_Get_Ready_Trend1 = Trend_Bearish and price > Time_Frame_HMA50 and price < HMA50 and !accumulation and !distribution;




# ---------------  Global Candle Logic ----------------------


DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bull PullBack", Color.DARK_GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Bear PullBack", Color.DARK_RED);


DefineGlobalColor("Break Out", Color.GREEN);
DefineGlobalColor("Break Down", Color.RED);
DefineGlobalColor("Reject", Color.DARK_RED);
DefineGlobalColor("Bounce", Color.DARK_GREEN);


DefineGlobalColor("Overbought Bar", Color.YELLOW);
DefineGlobalColor("Oversold Bar", Color.YELLOW);
DefineGlobalColor("KC Power UP", Color.DARK_ORANGE);
DefineGlobalColor("KC Power Down", Color.DARK_ORANGE);
DefineGlobalColor("Impulse Bar", Color.PLUM);


DefineGlobalColor("Accel", Color.GREEN);
DefineGlobalColor("Accum", Color.WHITE);
DefineGlobalColor("Dist", Color.BLUE);
DefineGlobalColor("Decel", Color.RED);
DefineGlobalColor("Bulls Get Ready", Color.CYAN);
DefineGlobalColor("Bears Get Ready", Color.VIOLET);





# --------------- END Global Candle Logic ----------------------


def MTF_On = yes;


## Month Aggregation Period Variables
def monthAcceleration;
def monthDeceleration;
def monthDistribution;
def monthAccumulation;
def monthBulls_Get_Ready;
def monthBears_Get_Ready;
def monthBears_Get_Ready_Trend;
def monthBulls_Get_Ready_Trend;
def monthBears_Get_Ready_Trend1;
def monthBulls_Get_Ready_Trend1;
def monthBull_Pullbacks;
def monthBear_Pullbacks;
def monthTrend_Bearish_Invalid;
def monthTrend_Bullish_Invalid;
def monthTrend_Bearish;
def monthTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.MONTH {
    monthAcceleration = acceleration;
    monthDeceleration = deceleration;
    monthDistribution = distribution;
    monthAccumulation = accumulation;
    monthBulls_Get_Ready = Bulls_Get_Ready;
    monthBears_Get_Ready = Bears_Get_Ready;
    monthBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    monthBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    monthBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    monthBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    monthBull_Pullbacks = Bull_Pullbacks;
    monthBear_Pullbacks = Bear_Pullbacks;
    monthTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    monthTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    monthTrend_Bearish = Trend_Bearish;
    monthTrend_Bullish = Trend_Bullish;

}
else {
    monthAcceleration = 0;
    monthDeceleration = 0;
    monthDistribution = 0;
    monthAccumulation = 0;
    monthBulls_Get_Ready = 0;
    monthBears_Get_Ready = 0;
    monthBears_Get_Ready_Trend = 0;
    monthBulls_Get_Ready_Trend = 0;
    monthBears_Get_Ready_Trend1 = 0;
    monthBulls_Get_Ready_Trend1 = 0;
    monthBull_Pullbacks = 0;
    monthBear_Pullbacks = 0;
    monthTrend_Bearish_Invalid = 0;
    monthTrend_Bullish_Invalid = 0;
    monthTrend_Bearish = 0;
    monthTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if monthAcceleration
    then "M"
    else if monthDistribution
    then "M"
    else if monthBulls_Get_Ready
    then "M"
    else if monthBears_Get_Ready
    then "M"
    else if monthBears_Get_Ready_Trend
    then "M"
    else if monthBulls_Get_Ready_Trend
    then "M"
    else if monthBears_Get_Ready_Trend1
    then "M"
    else if monthBulls_Get_Ready_Trend1
    then "M"
    else if monthBull_Pullbacks
    then "M"
    else if monthBear_Pullbacks
    then "M"
    else if monthTrend_Bearish_Invalid
    then "M"
    else if monthTrend_Bullish_Invalid
    then "M"
    else if monthTrend_Bearish
    then "M"
    else if monthTrend_Bullish
    then "M"
    else ""
,
    if monthAccumulation
    then GlobalColor("Accum")
    else if monthDistribution
    then GlobalColor("Dist")
    else if monthBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if monthBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if monthBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if monthBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if monthBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if monthBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if monthBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if monthBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if monthTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if monthTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if monthTrend_Bearish
    then GlobalColor("Bearish")
    else if monthTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## week Aggregation Period Variables
def weekAcceleration;
def weekDeceleration;
def weekDistribution;
def weekAccumulation;
def weekBulls_Get_Ready;
def weekBears_Get_Ready;
def weekBears_Get_Ready_Trend;
def weekBulls_Get_Ready_Trend;
def weekBears_Get_Ready_Trend1;
def weekBulls_Get_Ready_Trend1;
def weekBull_Pullbacks;
def weekBear_Pullbacks;
def weekTrend_Bearish_Invalid;
def weekTrend_Bullish_Invalid;
def weekTrend_Bearish;
def weekTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    weekAcceleration = acceleration;
    weekDeceleration = deceleration;
    weekDistribution = distribution;
    weekAccumulation = accumulation;
    weekBulls_Get_Ready = Bulls_Get_Ready;
    weekBears_Get_Ready = Bears_Get_Ready;
    weekBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    weekBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    weekBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    weekBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    weekBull_Pullbacks = Bull_Pullbacks;
    weekBear_Pullbacks = Bear_Pullbacks;
    weekTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    weekTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    weekTrend_Bearish = Trend_Bearish;
    weekTrend_Bullish = Trend_Bullish;

}
else {
    weekAcceleration = 0;
    weekDeceleration = 0;
    weekDistribution = 0;
    weekAccumulation = 0;
    weekBulls_Get_Ready = 0;
    weekBears_Get_Ready = 0;
    weekBears_Get_Ready_Trend = 0;
    weekBulls_Get_Ready_Trend = 0;
    weekBears_Get_Ready_Trend1 = 0;
    weekBulls_Get_Ready_Trend1 = 0;
    weekBull_Pullbacks = 0;
    weekBear_Pullbacks = 0;
    weekTrend_Bearish_Invalid = 0;
    weekTrend_Bullish_Invalid = 0;
    weekTrend_Bearish = 0;
    weekTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if weekAcceleration
    then "W"
    else if weekDistribution
    then "W"
    else if weekBulls_Get_Ready
    then "W"
    else if weekBears_Get_Ready
    then "W"
    else if weekBears_Get_Ready_Trend
    then "W"
    else if weekBulls_Get_Ready_Trend
    then "W"
    else if weekBears_Get_Ready_Trend1
    then "W"
    else if weekBulls_Get_Ready_Trend1
    then "W"
    else if weekBull_Pullbacks
    then "W"
    else if weekBear_Pullbacks
    then "W"
    else if weekTrend_Bearish_Invalid
    then "W"
    else if weekTrend_Bullish_Invalid
    then "W"
    else if weekTrend_Bearish
    then "W"
    else if weekTrend_Bullish
    then "W"
    else ""
,
    if weekAccumulation
    then GlobalColor("Accum")
    else if weekDistribution
    then GlobalColor("Dist")
    else if weekBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if weekBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if weekBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if weekBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if weekBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if weekBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if weekBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if weekBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if weekTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if weekTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if weekTrend_Bearish
    then GlobalColor("Bearish")
    else if weekTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## day Aggregation Period Variables
def dayAcceleration;
def dayDeceleration;
def dayDistribution;
def dayAccumulation;
def dayBulls_Get_Ready;
def dayBears_Get_Ready;
def dayBears_Get_Ready_Trend;
def dayBulls_Get_Ready_Trend;
def dayBears_Get_Ready_Trend1;
def dayBulls_Get_Ready_Trend1;
def dayBull_Pullbacks;
def dayBear_Pullbacks;
def dayTrend_Bearish_Invalid;
def dayTrend_Bullish_Invalid;
def dayTrend_Bearish;
def dayTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.DAY {
    dayAcceleration = acceleration;
    dayDeceleration = deceleration;
    dayDistribution = distribution;
    dayAccumulation = accumulation;
    dayBulls_Get_Ready = Bulls_Get_Ready;
    dayBears_Get_Ready = Bears_Get_Ready;
    dayBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    dayBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    dayBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    dayBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    dayBull_Pullbacks = Bull_Pullbacks;
    dayBear_Pullbacks = Bear_Pullbacks;
    dayTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    dayTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    dayTrend_Bearish = Trend_Bearish;
    dayTrend_Bullish = Trend_Bullish;

}
else {
    dayAcceleration = 0;
    dayDeceleration = 0;
    dayDistribution = 0;
    dayAccumulation = 0;
    dayBulls_Get_Ready = 0;
    dayBears_Get_Ready = 0;
    dayBears_Get_Ready_Trend = 0;
    dayBulls_Get_Ready_Trend = 0;
    dayBears_Get_Ready_Trend1 = 0;
    dayBulls_Get_Ready_Trend1 = 0;
    dayBull_Pullbacks = 0;
    dayBear_Pullbacks = 0;
    dayTrend_Bearish_Invalid = 0;
    dayTrend_Bullish_Invalid = 0;
    dayTrend_Bearish = 0;
    dayTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if dayAcceleration
    then "D"
    else if dayDistribution
    then "D"
    else if dayBulls_Get_Ready
    then "D"
    else if dayBears_Get_Ready
    then "D"
    else if dayBears_Get_Ready_Trend
    then "D"
    else if dayBulls_Get_Ready_Trend
    then "D"
    else if dayBears_Get_Ready_Trend1
    then "D"
    else if dayBulls_Get_Ready_Trend1
    then "D"
    else if dayBull_Pullbacks
    then "D"
    else if dayBear_Pullbacks
    then "D"
    else if dayTrend_Bearish_Invalid
    then "D"
    else if dayTrend_Bullish_Invalid
    then "D"
    else if dayTrend_Bearish
    then "D"
    else if dayTrend_Bullish
    then "D"
    else ""
,
    if dayAccumulation
    then GlobalColor("Accum")
    else if dayDistribution
    then GlobalColor("Dist")
    else if dayBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if dayBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if dayBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if dayBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if dayBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if dayBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if dayBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if dayBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if dayTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if dayTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if dayTrend_Bearish
    then GlobalColor("Bearish")
    else if dayTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Four_hours Aggregation Period Variables
def Four_hoursAcceleration;
def Four_hoursDeceleration;
def Four_hoursDistribution;
def Four_hoursAccumulation;
def Four_hoursBulls_Get_Ready;
def Four_hoursBears_Get_Ready;
def Four_hoursBears_Get_Ready_Trend;
def Four_hoursBulls_Get_Ready_Trend;
def Four_hoursBears_Get_Ready_Trend1;
def Four_hoursBulls_Get_Ready_Trend1;
def Four_hoursBull_Pullbacks;
def Four_hoursBear_Pullbacks;
def Four_hoursTrend_Bearish_Invalid;
def Four_hoursTrend_Bullish_Invalid;
def Four_hoursTrend_Bearish;
def Four_hoursTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    Four_hoursAcceleration = acceleration;
    Four_hoursDeceleration = deceleration;
    Four_hoursDistribution = distribution;
    Four_hoursAccumulation = accumulation;
    Four_hoursBulls_Get_Ready = Bulls_Get_Ready;
    Four_hoursBears_Get_Ready = Bears_Get_Ready;
    Four_hoursBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Four_hoursBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Four_hoursBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Four_hoursBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Four_hoursBull_Pullbacks = Bull_Pullbacks;
    Four_hoursBear_Pullbacks = Bear_Pullbacks;
    Four_hoursTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Four_hoursTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Four_hoursTrend_Bearish = Trend_Bearish;
    Four_hoursTrend_Bullish = Trend_Bullish;

}
else {
    Four_hoursAcceleration = 0;
    Four_hoursDeceleration = 0;
    Four_hoursDistribution = 0;
    Four_hoursAccumulation = 0;
    Four_hoursBulls_Get_Ready = 0;
    Four_hoursBears_Get_Ready = 0;
    Four_hoursBears_Get_Ready_Trend = 0;
    Four_hoursBulls_Get_Ready_Trend = 0;
    Four_hoursBears_Get_Ready_Trend1 = 0;
    Four_hoursBulls_Get_Ready_Trend1 = 0;
    Four_hoursBull_Pullbacks = 0;
    Four_hoursBear_Pullbacks = 0;
    Four_hoursTrend_Bearish_Invalid = 0;
    Four_hoursTrend_Bullish_Invalid = 0;
    Four_hoursTrend_Bearish = 0;
    Four_hoursTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Four_hoursAcceleration
    then "4H"
    else if Four_hoursDistribution
    then "4H"
    else if Four_hoursBulls_Get_Ready
    then "4H"
    else if Four_hoursBears_Get_Ready
    then "4H"
    else if Four_hoursBears_Get_Ready_Trend
    then "4H"
    else if Four_hoursBulls_Get_Ready_Trend
    then "4H"
    else if Four_hoursBears_Get_Ready_Trend1
    then "4H"
    else if Four_hoursBulls_Get_Ready_Trend1
    then "4H"
    else if Four_hoursBull_Pullbacks
    then "4H"
    else if Four_hoursBear_Pullbacks
    then "4H"
    else if Four_hoursTrend_Bearish_Invalid
    then "4H"
    else if Four_hoursTrend_Bullish_Invalid
    then "4H"
    else if Four_hoursTrend_Bearish
    then "4H"
    else if Four_hoursTrend_Bullish
    then "4H"
    else ""
,
    if Four_hoursAccumulation
    then GlobalColor("Accum")
    else if Four_hoursDistribution
    then GlobalColor("Dist")
    else if Four_hoursBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Four_hoursBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Four_hoursBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Four_hoursBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Four_hoursTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Four_hoursTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Four_hoursTrend_Bearish
    then GlobalColor("Bearish")
    else if Four_hoursTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);




## hour Aggregation Period Variables
def hourAcceleration;
def hourDeceleration;
def hourDistribution;
def hourAccumulation;
def hourBulls_Get_Ready;
def hourBears_Get_Ready;
def hourBears_Get_Ready_Trend;
def hourBulls_Get_Ready_Trend;
def hourBears_Get_Ready_Trend1;
def hourBulls_Get_Ready_Trend1;
def hourBull_Pullbacks;
def hourBear_Pullbacks;
def hourTrend_Bearish_Invalid;
def hourTrend_Bullish_Invalid;
def hourTrend_Bearish;
def hourTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    hourAcceleration = acceleration;
    hourDeceleration = deceleration;
    hourDistribution = distribution;
    hourAccumulation = accumulation;
    hourBulls_Get_Ready = Bulls_Get_Ready;
    hourBears_Get_Ready = Bears_Get_Ready;
    hourBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    hourBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    hourBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    hourBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    hourBull_Pullbacks = Bull_Pullbacks;
    hourBear_Pullbacks = Bear_Pullbacks;
    hourTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    hourTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    hourTrend_Bearish = Trend_Bearish;
    hourTrend_Bullish = Trend_Bullish;

}
else {
    hourAcceleration = 0;
    hourDeceleration = 0;
    hourDistribution = 0;
    hourAccumulation = 0;
    hourBulls_Get_Ready = 0;
    hourBears_Get_Ready = 0;
    hourBears_Get_Ready_Trend = 0;
    hourBulls_Get_Ready_Trend = 0;
    hourBears_Get_Ready_Trend1 = 0;
    hourBulls_Get_Ready_Trend1 = 0;
    hourBull_Pullbacks = 0;
    hourBear_Pullbacks = 0;
    hourTrend_Bearish_Invalid = 0;
    hourTrend_Bullish_Invalid = 0;
    hourTrend_Bearish = 0;
    hourTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if hourAcceleration
    then "H"
    else if hourDistribution
    then "H"
    else if hourBulls_Get_Ready
    then "H"
    else if hourBears_Get_Ready
    then "H"
    else if hourBears_Get_Ready_Trend
    then "H"
    else if hourBulls_Get_Ready_Trend
    then "H"
    else if hourBears_Get_Ready_Trend1
    then "H"
    else if hourBulls_Get_Ready_Trend1
    then "H"
    else if hourBull_Pullbacks
    then "H"
    else if hourBear_Pullbacks
    then "H"
    else if hourTrend_Bearish_Invalid
    then "H"
    else if hourTrend_Bullish_Invalid
    then "H"
    else if hourTrend_Bearish
    then "H"
    else if hourTrend_Bullish
    then "H"
    else ""
,
    if hourAccumulation
    then GlobalColor("Accum")
    else if hourDistribution
    then GlobalColor("Dist")
    else if hourBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if hourBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if hourBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if hourBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if hourBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if hourBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if hourBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if hourBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if hourTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if hourTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if hourTrend_Bearish
    then GlobalColor("Bearish")
    else if hourTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Fifteen_Min Aggregation Period Variables
def Fifteen_MinAcceleration;
def Fifteen_MinDeceleration;
def Fifteen_MinDistribution;
def Fifteen_MinAccumulation;
def Fifteen_MinBulls_Get_Ready;
def Fifteen_MinBears_Get_Ready;
def Fifteen_MinBears_Get_Ready_Trend;
def Fifteen_MinBulls_Get_Ready_Trend;
def Fifteen_MinBears_Get_Ready_Trend1;
def Fifteen_MinBulls_Get_Ready_Trend1;
def Fifteen_MinBull_Pullbacks;
def Fifteen_MinBear_Pullbacks;
def Fifteen_MinTrend_Bearish_Invalid;
def Fifteen_MinTrend_Bullish_Invalid;
def Fifteen_MinTrend_Bearish;
def Fifteen_MinTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    Fifteen_MinAcceleration = acceleration;
    Fifteen_MinDeceleration = deceleration;
    Fifteen_MinDistribution = distribution;
    Fifteen_MinAccumulation = accumulation;
    Fifteen_MinBulls_Get_Ready = Bulls_Get_Ready;
    Fifteen_MinBears_Get_Ready = Bears_Get_Ready;
    Fifteen_MinBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Fifteen_MinBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Fifteen_MinBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Fifteen_MinBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Fifteen_MinBull_Pullbacks = Bull_Pullbacks;
    Fifteen_MinBear_Pullbacks = Bear_Pullbacks;
    Fifteen_MinTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Fifteen_MinTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Fifteen_MinTrend_Bearish = Trend_Bearish;
    Fifteen_MinTrend_Bullish = Trend_Bullish;

}
else {
    Fifteen_MinAcceleration = 0;
    Fifteen_MinDeceleration = 0;
    Fifteen_MinDistribution = 0;
    Fifteen_MinAccumulation = 0;
    Fifteen_MinBulls_Get_Ready = 0;
    Fifteen_MinBears_Get_Ready = 0;
    Fifteen_MinBears_Get_Ready_Trend = 0;
    Fifteen_MinBulls_Get_Ready_Trend = 0;
    Fifteen_MinBears_Get_Ready_Trend1 = 0;
    Fifteen_MinBulls_Get_Ready_Trend1 = 0;
    Fifteen_MinBull_Pullbacks = 0;
    Fifteen_MinBear_Pullbacks = 0;
    Fifteen_MinTrend_Bearish_Invalid = 0;
    Fifteen_MinTrend_Bullish_Invalid = 0;
    Fifteen_MinTrend_Bearish = 0;
    Fifteen_MinTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Fifteen_MinAcceleration
    then "15M"
    else if Fifteen_MinDistribution
    then "15M"
    else if Fifteen_MinBulls_Get_Ready
    then "15M"
    else if Fifteen_MinBears_Get_Ready
    then "15M"
    else if Fifteen_MinBears_Get_Ready_Trend
    then "15M"
    else if Fifteen_MinBulls_Get_Ready_Trend
    then "15M"
    else if Fifteen_MinBears_Get_Ready_Trend1
    then "15M"
    else if Fifteen_MinBulls_Get_Ready_Trend1
    then "15M"
    else if Fifteen_MinBull_Pullbacks
    then "15M"
    else if Fifteen_MinBear_Pullbacks
    then "15M"
    else if Fifteen_MinTrend_Bearish_Invalid
    then "15M"
    else if Fifteen_MinTrend_Bullish_Invalid
    then "15M"
    else if Fifteen_MinTrend_Bearish
    then "15M"
    else if Fifteen_MinTrend_Bullish
    then "15M"
    else ""
,
    if Fifteen_MinAccumulation
    then GlobalColor("Accum")
    else if Fifteen_MinDistribution
    then GlobalColor("Dist")
    else if Fifteen_MinBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Fifteen_MinBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Fifteen_MinBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Fifteen_MinBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Fifteen_MinTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Fifteen_MinTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Fifteen_MinTrend_Bearish
    then GlobalColor("Bearish")
    else if Fifteen_MinTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);



## Five_Min Aggregation Period Variables
def Five_MinAcceleration;
def Five_MinDeceleration;
def Five_MinDistribution;
def Five_MinAccumulation;
def Five_MinBulls_Get_Ready;
def Five_MinBears_Get_Ready;
def Five_MinBears_Get_Ready_Trend;
def Five_MinBulls_Get_Ready_Trend;
def Five_MinBears_Get_Ready_Trend1;
def Five_MinBulls_Get_Ready_Trend1;
def Five_MinBull_Pullbacks;
def Five_MinBear_Pullbacks;
def Five_MinTrend_Bearish_Invalid;
def Five_MinTrend_Bullish_Invalid;
def Five_MinTrend_Bearish;
def Five_MinTrend_Bullish;




if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
    Five_MinAcceleration = acceleration;
    Five_MinDeceleration = deceleration;
    Five_MinDistribution = distribution;
    Five_MinAccumulation = accumulation;
    Five_MinBulls_Get_Ready = Bulls_Get_Ready;
    Five_MinBears_Get_Ready = Bears_Get_Ready;
    Five_MinBears_Get_Ready_Trend = Bears_Get_Ready_Trend;
    Five_MinBulls_Get_Ready_Trend = Bulls_Get_Ready_Trend;
    Five_MinBears_Get_Ready_Trend1 = Bears_Get_Ready_Trend1;
    Five_MinBulls_Get_Ready_Trend1 = Bulls_Get_Ready_Trend1;
    Five_MinBull_Pullbacks = Bull_Pullbacks;
    Five_MinBear_Pullbacks = Bear_Pullbacks;
    Five_MinTrend_Bearish_Invalid = Trend_Bearish_Invalid;
    Five_MinTrend_Bullish_Invalid = Trend_Bullish_Invalid;
    Five_MinTrend_Bearish = Trend_Bearish;
    Five_MinTrend_Bullish = Trend_Bullish;

}
else {
    Five_MinAcceleration = 0;
    Five_MinDeceleration = 0;
    Five_MinDistribution = 0;
    Five_MinAccumulation = 0;
    Five_MinBulls_Get_Ready = 0;
    Five_MinBears_Get_Ready = 0;
    Five_MinBears_Get_Ready_Trend = 0;
    Five_MinBulls_Get_Ready_Trend = 0;
    Five_MinBears_Get_Ready_Trend1 = 0;
    Five_MinBulls_Get_Ready_Trend1 = 0;
    Five_MinBull_Pullbacks = 0;
    Five_MinBear_Pullbacks = 0;
    Five_MinTrend_Bearish_Invalid = 0;
    Five_MinTrend_Bullish_Invalid = 0;
    Five_MinTrend_Bearish = 0;
    Five_MinTrend_Bullish = 0;
}

AddLabel(MTF_On,
    if Five_MinAcceleration
    then "5M"
    else if Five_MinDistribution
    then "5M"
    else if Five_MinBulls_Get_Ready
    then "5M"
    else if Five_MinBears_Get_Ready
    then "5M"
    else if Five_MinBears_Get_Ready_Trend
    then "5M"
    else if Five_MinBulls_Get_Ready_Trend
    then "5M"
    else if Five_MinBears_Get_Ready_Trend1
    then "5M"
    else if Five_MinBulls_Get_Ready_Trend1
    then "5M"
    else if Five_MinBull_Pullbacks
    then "5M"
    else if Five_MinBear_Pullbacks
    then "5M"
    else if Five_MinTrend_Bearish_Invalid
    then "5M"
    else if Five_MinTrend_Bullish_Invalid
    then "5M"
    else if Five_MinTrend_Bearish
    then "5M"
    else if Five_MinTrend_Bullish
    then "5M"
    else ""
,
    if Five_MinAccumulation
    then GlobalColor("Accum")
    else if Five_MinDistribution
    then GlobalColor("Dist")
    else if Five_MinBulls_Get_Ready
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBears_Get_Ready
    then GlobalColor("Bears Get Ready")
    else if Five_MinBears_Get_Ready_Trend
    then GlobalColor("Bears Get Ready")
    else if Five_MinBulls_Get_Ready_Trend
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBears_Get_Ready_Trend1
    then GlobalColor("Bulls Get Ready")
    else if Five_MinBulls_Get_Ready_Trend1
    then GlobalColor("Bears Get Ready")
    else if Five_MinBull_Pullbacks
    then GlobalColor("Bull PullBack")
    else if Five_MinBear_Pullbacks
    then GlobalColor("Bear PullBack")
    else if Five_MinTrend_Bearish_Invalid
    then GlobalColor("Bullish")
    else if Five_MinTrend_Bullish_Invalid
    then GlobalColor("Bearish")
    else if Five_MinTrend_Bearish
    then GlobalColor("Bearish")
    else if Five_MinTrend_Bullish
    then GlobalColor("Bullish")
    else Color.WHITE
);
 
Last edited by a moderator:

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

Thread starter Similar threads Forum Replies Date
C MTF Moving average cross candle color Questions 3
R MTF Previous Candle Questions 3
E MTF Stacked Moving Averages Questions 1
M MTF AMA Questions 2
C MTF EMA cloud Questions 1

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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