input periodsdisplayed = 3;
input MAprice_in_bubble = yes;
input MAtext_in_bubble = yes;
input aggperiod = {current, default manual} ;
input aggregation = AggregationPeriod.HOUR;
input length1 = 50;
input length2 = 200;
input avgtype1 = AverageType.SIMPLE;
input avgtype2 = AverageType.SIMPLE;
input showonexpansion = no;
def bn = BarNumber();
def lastbar = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then bn else Double.NaN);
def aggbars = (if aggperiod == aggperiod.current
then GetAggregationPeriod()
else aggregation) / 60000 / (GetAggregationPeriod() / 60000) * periodsdisplayed;
def MA1_ = if IsNaN(close)
then MA1_[1]
else if if aggperiod == aggperiod.manual and
aggregation == AggregationPeriod.DAY
then Between(GetDay(),
GetLastDay() - periodsdisplayed + 1,
GetLastDay())
else Between(bn, lastbar - aggbars, lastbar)
then MovingAverage (avgtype1, close (period =
if aggperiod == aggperiod.current
then GetAggregationPeriod()
else aggregation), length1)
else Double.NaN ;
plot MA1 = if showonexpansion and !IsNaN(close)
then Double.NaN
else MA1_ ;
MA1.SetStyle(Curve.FIRM);
MA1.HideBubble();
def inertline = InertiaAll(MA1, 2);
def EXT_MA = if !IsNaN(close()) then inertline else EXT_MA[1] + ((EXT_MA[1] - EXT_MA[2]) / (2 - 1));
plot extension = EXT_MA;
extension.SetDefaultColor(CreateColor(0, 255, 255));
extension.SetLineWeight(1);
extension.HideBubble();
def MA2_ = if IsNaN(close)
then MA2_[1]
else if if aggperiod == aggperiod.manual and
aggregation == AggregationPeriod.DAY
then Between(GetDay(),
GetLastDay() - periodsdisplayed + 1,
GetLastDay())
else Between(bn, lastbar - aggbars, lastbar)
then MovingAverage (avgtype2, close (period = if aggperiod == aggperiod.current
then GetAggregationPeriod()
else aggregation), length2)
else Double.NaN ;
plot MA2 = if showonexpansion and !IsNaN(close)
then Double.NaN
else MA2_ ;
MA2.SetStyle(Curve.FIRM);
MA2.HideBubble();
def inertline1 = InertiaAll(MA2, 2);
def EXT_MA1 = if !IsNaN(close()) then inertline1 else EXT_MA1[1] + ((EXT_MA1[1] - EXT_MA1[2]) / (2 - 1));
plot extension1 = EXT_MA1;
extension1.SetDefaultColor(CreateColor(0, 255, 255));
extension1.SetLineWeight(1);
extension1.HideBubble();
#Clouds
input showclouds = yes;
AddCloud(if showclouds then MA1 else Double.NaN, MA2, Color.GREEN, Color.RED);
AddCloud(if showclouds then extension else Double.NaN, extension1, Color.GREEN, Color.RED);
#Bubbles
input bubbles = yes;
input bubblemover = 5;
def bm = bubblemover;
def bm1 = bm + 1;
AddChartBubble(bubbles and !IsNaN(close[bm1]) and IsNaN(close[bm]),
MA1[bm], (if MAtext_in_bubble
then
(if avgtype1 == AverageType.EXPONENTIAL
then "E"
else if avgtype1 == AverageType.HULL
then "H"
else if avgtype1 == AverageType.SIMPLE
then "S"
else if avgtype1 == AverageType.WEIGHTED
then "WGT"
else "W"
) + "MA " + length1 +
(if aggperiod == aggperiod.manual
then if aggregation == AggregationPeriod.DAY
then " D\n"
else if aggregation == AggregationPeriod.HOUR
then " H\n"
else (" " + aggregation / 60000 + "m\n")
else " " )
else "") +
(if MAprice_in_bubble then AsText(MA1[bm]) else ""),
MA1.TakeValueColor(),
if MA1[bm] > MA2[bm] then yes else no);
AddChartBubble(bubbles and !IsNaN(close[bm1]) and IsNaN(close[bm]),
MA2[bm], (if MAtext_in_bubble
then
(if avgtype2 == AverageType.EXPONENTIAL
then "E"
else if avgtype2 == AverageType.HULL
then "H"
else if avgtype2 == AverageType.SIMPLE
then "S"
else if avgtype2 == AverageType.WEIGHTED
then "WGT"
else "W"
) + "MA " + "" + length2 +
(if aggperiod == aggperiod.manual
then if aggregation == AggregationPeriod.DAY
then " D\n"
else if aggregation == AggregationPeriod.HOUR
then " H\n"
else (" " + aggregation / 60000 + "m\n")
else " " )
else " ") +
(if MAprice_in_bubble then AsText(MA2[bm]) else ""),
MA2.TakeValueColor(),
if MA2[bm] > MA1[bm] then yes else no);
;