Repaints Heiken Ashi High/Low with Smoothed HA for ThinkOrSwim

Repaints

samer800

Moderator - Expert
VIP
Lifetime
9CiDLSW.png


It uses Heiken Ashi candles to detect recent swing high and low. It can be used as a stop-loss or support/resistance indicator.

I added Multi timeframe support, smoothed HA, Bar color option and show/hide wicks

CODE:
CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input SmoothedHeikenAshi = yes;
input type = {Default "High/Low", "HA Open/Close"};#"Which levels to use for upper and lower?")
input wick = yes;
input PaintHeikenAshiBars = no;
input ha_smooth_ma_type = {default EMA, SMA, WMA, McGinley, HMA};
input ha_smooth_length = 10; # "Smooth Length"
input ha_after_smooth_ma_type = {default EMA, SMA, WMA, VWMA, McGinley, HMA};
input ha_after_smooth_length = 10;#

def na = Double.NaN;
def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [

# mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 , mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), src);
    plot return = mg;
}

#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then WildersAverage(source, length) else
        if type == "WMA"    then WMA(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input smooth_length = 1;
 input smooth_ma_type = 1;
 input after_smooth_length = 1;
 input after_smooth_ma_type = 1;
 input wick = yes;
 input agg = AggregationPeriod.FIFTEEN_MIN;
    def src_open = open(period=agg);
    def src_high = high(period=agg);
    def src_low  = low(period=agg);
    def src_close = close(period=agg);
    def haopen;
    def haclose;
    def hahigh;
    def halow;
    def o = anyma(src_open, smooth_length, smooth_ma_type);
    def h = anyma(src_high, smooth_length, smooth_ma_type);
    def l = anyma(src_low, smooth_length, smooth_ma_type);
    def c = anyma(src_close, smooth_length, smooth_ma_type);

    haclose = (o + h + l + c) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(h,Max(haopen, haclose));
    halow  = Min(l,Min(haopen, haclose));
    def SmoothO = anyma(haopen, after_smooth_length, smooth_ma_type);
    def SmoothH = anyma(if(wick,hahigh,haclose), after_smooth_length,smooth_ma_type);
    def SmoothL = anyma(if(wick,halow,haclose), after_smooth_length, smooth_ma_type);
    def SmoothC = anyma(haclose, after_smooth_length, smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def o = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def h = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def l = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def c = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(type==type."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(type==type."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;    # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;    # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart

def HAo = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def HAh = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def HAl = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def HAc = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;
def dir = HAo>HAc;
AddChart(high = if SmoothedHeikenAshi and !dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAc,HAo),  close = if(PaintHeikenAshiBars,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if SmoothedHeikenAshi and dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAo,HAc),  close = if(PaintHeikenAshiBars,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#---- Bar Color---
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

#---END CODE

Update: some code improvements and added different candle calc options and HA style options (Candle and parapolice)

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else {
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
 
Last edited:

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

Cool indicator and thank you for sharing. Is there something that can be added to the code to hide the regular candlesticks and only show the HA candlesticks?
 
Cool indicator and thank you for sharing. Is there something that can be added to the code to hide the regular candlesticks and only show the HA candlesticks?
add this at the of the code. You can change the setting yes/no to show the candles
CSS:
input showPricePlot = yes;
hidePricePlot(!showPricePlot);
 
add this at the of the code. You can change the setting yes/no to show the candles
CSS:
input showPricePlot = yes;
hidePricePlot(!showPricePlot);
Brilliant! Thank you! Is it possible to add TEMA as an additional ha smooth ma type and ha after smooth ma type?
 
Brilliant! Thank you! Is it possible to add TEMA as an additional ha smooth ma type and ha after smooth ma type?
added below.

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input SmoothedHeikenAshi = yes;
input type = {Default "High/Low", "HA Open/Close"};#"Which levels to use for upper and lower?")
input wick = yes;
input PaintHeikenAshiBars = no;
input ha_smooth_ma_type = {default EMA, SMA, WMA, TEMA, McGinley, HMA};
input ha_smooth_length = 10; # "Smooth Length"
input ha_after_smooth_ma_type = {default EMA, SMA, WMA, TEMA, McGinley, HMA};
input ha_after_smooth_length = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
# mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 , mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), src);
    plot return = mg;
}

#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then WildersAverage(source, length) else
        if type == "WMA"    then WMA(source, length) else
        if type == "TEMA"   then TEMA(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input smooth_length = 1;
 input smooth_ma_type = 1;
 input after_smooth_length = 1;
 input after_smooth_ma_type = 1;
 input wick = yes;
 input agg = AggregationPeriod.FIFTEEN_MIN;
    def src_open = open(period=agg);
    def src_high = high(period=agg);
    def src_low  = low(period=agg);
    def src_close = close(period=agg);
    def haopen;
    def haclose;
    def hahigh;
    def halow;
    def o = anyma(src_open, smooth_length, smooth_ma_type);
    def h = anyma(src_high, smooth_length, smooth_ma_type);
    def l = anyma(src_low, smooth_length, smooth_ma_type);
    def c = anyma(src_close, smooth_length, smooth_ma_type);
    haclose = (o + h + l + c) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(h,Max(haopen, haclose));
    halow  = Min(l,Min(haopen, haclose));
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haclose);
    def SmoothO = anyma(haopen, after_smooth_length, smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length,smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, smooth_ma_type);
    def SmoothC = anyma(haclose, after_smooth_length, smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def o = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def h = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def l = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def c = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(type==type."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(type==type."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;    # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;    # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart

def HAo = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def HAh = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def HAl = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def HAc = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;
def dir = HAo>HAc;
AddChart(high = if SmoothedHeikenAshi and !dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAc,HAo),  close = if(PaintHeikenAshiBars,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if SmoothedHeikenAshi and dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAo,HAc),  close = if(PaintHeikenAshiBars,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#---- Bar Color---
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

#---END CODE
 
added below.

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input SmoothedHeikenAshi = yes;
input type = {Default "High/Low", "HA Open/Close"};#"Which levels to use for upper and lower?")
input wick = yes;
input PaintHeikenAshiBars = no;
input ha_smooth_ma_type = {default EMA, SMA, WMA, TEMA, McGinley, HMA};
input ha_smooth_length = 10; # "Smooth Length"
input ha_after_smooth_ma_type = {default EMA, SMA, WMA, TEMA, McGinley, HMA};
input ha_after_smooth_length = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
# mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 , mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), src);
    plot return = mg;
}

#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then WildersAverage(source, length) else
        if type == "WMA"    then WMA(source, length) else
        if type == "TEMA"   then TEMA(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input smooth_length = 1;
 input smooth_ma_type = 1;
 input after_smooth_length = 1;
 input after_smooth_ma_type = 1;
 input wick = yes;
 input agg = AggregationPeriod.FIFTEEN_MIN;
    def src_open = open(period=agg);
    def src_high = high(period=agg);
    def src_low  = low(period=agg);
    def src_close = close(period=agg);
    def haopen;
    def haclose;
    def hahigh;
    def halow;
    def o = anyma(src_open, smooth_length, smooth_ma_type);
    def h = anyma(src_high, smooth_length, smooth_ma_type);
    def l = anyma(src_low, smooth_length, smooth_ma_type);
    def c = anyma(src_close, smooth_length, smooth_ma_type);
    haclose = (o + h + l + c) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(h,Max(haopen, haclose));
    halow  = Min(l,Min(haopen, haclose));
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haclose);
    def SmoothO = anyma(haopen, after_smooth_length, smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length,smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, smooth_ma_type);
    def SmoothC = anyma(haclose, after_smooth_length, smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def o = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def h = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def l = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def c = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(type==type."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(type==type."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;    # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;    # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart

def HAo = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def HAh = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def HAl = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def HAc = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;
def dir = HAo>HAc;
AddChart(high = if SmoothedHeikenAshi and !dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAc,HAo),  close = if(PaintHeikenAshiBars,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if SmoothedHeikenAshi and dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAo,HAc),  close = if(PaintHeikenAshiBars,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#---- Bar Color---
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

#---END CODE
Is it possible to add valcu and vervoot candle smoothing to this indicator? I'm really liking this one. I'm not sure if this can somehow be incorporated in.

input candleSmoothing = {default Valcu, Vervoort};
switch(candleSmoothing) {
case Valcu:
haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;
case Vervoort:
haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
haClose = ((((OpenMA + HighMA + LowMA + CloseMA)/4.0) + haOpen + Max(HighMA, haOpen) + Min(LowMA, haOpen))/4.0);
}
 
Last edited:
Is it possible to add valcu and vervoot candle smoothing to this indicator? I'm really liking this one. I'm not sure if this can somehow be incorporated in.

input candleSmoothing = {default Valcu, Vervoort};
switch(candleSmoothing) {
case Valcu:
haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;
case Vervoort:
haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
haClose = ((((OpenMA + HighMA + LowMA + CloseMA)/4.0) + haOpen + Max(HighMA, haOpen) + Min(LowMA, haOpen))/4.0);
}
added. I don't see much difference . Try the parapolice option i just added, Looks good.

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else { 
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
 
Last edited:
added. I don't see much difference . Try the parapolice option i just added, Looks good.

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else {
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
Thank you. I am kind of familiar with this setup, it looks good for the ES.
 
added. I don't see much difference . Try the parapolice option i just added, Looks good.

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else {
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
Absolutely brilliant! The parabolic option is very cool and one that I have never heard of. You have an amazing mind my friend. Thank you so much!
 
Last edited:
9CiDLSW.png

It uses Heiken Ashi candles to detect recent swing high and low. It can be used as a stop-loss or support/resistance indicator.
I added Multi timeframe support, smoothed HA, Bar color option and show/hide wicks

CODE:
CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input SmoothedHeikenAshi = yes;
input type = {Default "High/Low", "HA Open/Close"};#"Which levels to use for upper and lower?")
input wick = yes;
input PaintHeikenAshiBars = no;
input ha_smooth_ma_type = {default EMA, SMA, WMA, McGinley, HMA};
input ha_smooth_length = 10; # "Smooth Length"
input ha_after_smooth_ma_type = {default EMA, SMA, WMA, VWMA, McGinley, HMA};
input ha_after_smooth_length = 10;#

def na = Double.NaN;
def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [

# mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 , mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), src);
    plot return = mg;
}

#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then WildersAverage(source, length) else
        if type == "WMA"    then WMA(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input smooth_length = 1;
 input smooth_ma_type = 1;
 input after_smooth_length = 1;
 input after_smooth_ma_type = 1;
 input wick = yes;
 input agg = AggregationPeriod.FIFTEEN_MIN;
    def src_open = open(period=agg);
    def src_high = high(period=agg);
    def src_low  = low(period=agg);
    def src_close = close(period=agg);
    def haopen;
    def haclose;
    def hahigh;
    def halow;
    def o = anyma(src_open, smooth_length, smooth_ma_type);
    def h = anyma(src_high, smooth_length, smooth_ma_type);
    def l = anyma(src_low, smooth_length, smooth_ma_type);
    def c = anyma(src_close, smooth_length, smooth_ma_type);

    haclose = (o + h + l + c) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(h,Max(haopen, haclose));
    halow  = Min(l,Min(haopen, haclose));
    def SmoothO = anyma(haopen, after_smooth_length, smooth_ma_type);
    def SmoothH = anyma(if(wick,hahigh,haclose), after_smooth_length,smooth_ma_type);
    def SmoothL = anyma(if(wick,halow,haclose), after_smooth_length, smooth_ma_type);
    def SmoothC = anyma(haclose, after_smooth_length, smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def o = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def h = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def l = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def c = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(type==type."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(type==type."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;    # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;    # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart

def HAo = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def HAh = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def HAl = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def HAc = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;
def dir = HAo>HAc;
AddChart(high = if SmoothedHeikenAshi and !dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAc,HAo),  close = if(PaintHeikenAshiBars,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if SmoothedHeikenAshi and dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAo,HAc),  close = if(PaintHeikenAshiBars,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#---- Bar Color---
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

#---END CODE

Update: some code improvements and added different candle calc options and HA style options (Candle and parapolice)

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else {
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
Thank you so very much for this study. Love it, It helps so much with my vision issue, much appreciated... Question, is this limited to a high of 15min time frame? Anything over 15min won't show study? TIA...
 
Thank you so very much for this study. Love it, It helps so much with my vision issue, much appreciated... Question, is this limited to a high of 15min time frame? Anything over 15min won't show study? TIA...
you can change the the time frame after setting "useChartTime " to no. make sure your chart time frame is less than the selected aggregation period.
 
9CiDLSW.png

It uses Heiken Ashi candles to detect recent swing high and low. It can be used as a stop-loss or support/resistance indicator.
I added Multi timeframe support, smoothed HA, Bar color option and show/hide wicks

CODE:
CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input SmoothedHeikenAshi = yes;
input type = {Default "High/Low", "HA Open/Close"};#"Which levels to use for upper and lower?")
input wick = yes;
input PaintHeikenAshiBars = no;
input ha_smooth_ma_type = {default EMA, SMA, WMA, McGinley, HMA};
input ha_smooth_length = 10; # "Smooth Length"
input ha_after_smooth_ma_type = {default EMA, SMA, WMA, VWMA, McGinley, HMA};
input ha_after_smooth_length = 10;#

def na = Double.NaN;
def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [

# mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 , mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), src);
    plot return = mg;
}

#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then WildersAverage(source, length) else
        if type == "WMA"    then WMA(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input smooth_length = 1;
 input smooth_ma_type = 1;
 input after_smooth_length = 1;
 input after_smooth_ma_type = 1;
 input wick = yes;
 input agg = AggregationPeriod.FIFTEEN_MIN;
    def src_open = open(period=agg);
    def src_high = high(period=agg);
    def src_low  = low(period=agg);
    def src_close = close(period=agg);
    def haopen;
    def haclose;
    def hahigh;
    def halow;
    def o = anyma(src_open, smooth_length, smooth_ma_type);
    def h = anyma(src_high, smooth_length, smooth_ma_type);
    def l = anyma(src_low, smooth_length, smooth_ma_type);
    def c = anyma(src_close, smooth_length, smooth_ma_type);

    haclose = (o + h + l + c) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(h,Max(haopen, haclose));
    halow  = Min(l,Min(haopen, haclose));
    def SmoothO = anyma(haopen, after_smooth_length, smooth_ma_type);
    def SmoothH = anyma(if(wick,hahigh,haclose), after_smooth_length,smooth_ma_type);
    def SmoothL = anyma(if(wick,halow,haclose), after_smooth_length, smooth_ma_type);
    def SmoothC = anyma(haclose, after_smooth_length, smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def o = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def h = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def l = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def c = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(type==type."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(type==type."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;    # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;    # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart

def HAo = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def HAh = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def HAl = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def HAc = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;
def dir = HAo>HAc;
AddChart(high = if SmoothedHeikenAshi and !dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAc,HAo),  close = if(PaintHeikenAshiBars,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if SmoothedHeikenAshi and dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAo,HAc),  close = if(PaintHeikenAshiBars,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#---- Bar Color---
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

#---END CODE

Update: some code improvements and added different candle calc options and HA style options (Candle and parapolice)

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else {
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
@samer800 Would it be possible to add McGinley to the version of the CODE under:
Update: some code improvements and added different candle calc options and HA style options (Candle and parapolice)
Thank you!
 
9CiDLSW.png

It uses Heiken Ashi candles to detect recent swing high and low. It can be used as a stop-loss or support/resistance indicator.
I added Multi timeframe support, smoothed HA, Bar color option and show/hide wicks

CODE:
CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input SmoothedHeikenAshi = yes;
input type = {Default "High/Low", "HA Open/Close"};#"Which levels to use for upper and lower?")
input wick = yes;
input PaintHeikenAshiBars = no;
input ha_smooth_ma_type = {default EMA, SMA, WMA, McGinley, HMA};
input ha_smooth_length = 10; # "Smooth Length"
input ha_after_smooth_ma_type = {default EMA, SMA, WMA, VWMA, McGinley, HMA};
input ha_after_smooth_length = 10;#

def na = Double.NaN;
def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [

# mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 , mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), src);
    plot return = mg;
}

#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then WildersAverage(source, length) else
        if type == "WMA"    then WMA(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input smooth_length = 1;
 input smooth_ma_type = 1;
 input after_smooth_length = 1;
 input after_smooth_ma_type = 1;
 input wick = yes;
 input agg = AggregationPeriod.FIFTEEN_MIN;
    def src_open = open(period=agg);
    def src_high = high(period=agg);
    def src_low  = low(period=agg);
    def src_close = close(period=agg);
    def haopen;
    def haclose;
    def hahigh;
    def halow;
    def o = anyma(src_open, smooth_length, smooth_ma_type);
    def h = anyma(src_high, smooth_length, smooth_ma_type);
    def l = anyma(src_low, smooth_length, smooth_ma_type);
    def c = anyma(src_close, smooth_length, smooth_ma_type);

    haclose = (o + h + l + c) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(h,Max(haopen, haclose));
    halow  = Min(l,Min(haopen, haclose));
    def SmoothO = anyma(haopen, after_smooth_length, smooth_ma_type);
    def SmoothH = anyma(if(wick,hahigh,haclose), after_smooth_length,smooth_ma_type);
    def SmoothL = anyma(if(wick,halow,haclose), after_smooth_length, smooth_ma_type);
    def SmoothC = anyma(haclose, after_smooth_length, smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def o = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def h = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def l = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def c = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(type==type."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(type==type."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;    # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;    # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart

def HAo = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def HAh = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def HAl = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def HAc = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;
def dir = HAo>HAc;
AddChart(high = if SmoothedHeikenAshi and !dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAc,HAo),  close = if(PaintHeikenAshiBars,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if SmoothedHeikenAshi and dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAo,HAc),  close = if(PaintHeikenAshiBars,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#---- Bar Color---
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

#---END CODE

Update: some code improvements and added different candle calc options and HA style options (Candle and parapolice)

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else {
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
I don't see the upper and lowe line.
9CiDLSW.png

It uses Heiken Ashi candles to detect recent swing high and low. It can be used as a stop-loss or support/resistance indicator.
I added Multi timeframe support, smoothed HA, Bar color option and show/hide wicks

CODE:
CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input SmoothedHeikenAshi = yes;
input type = {Default "High/Low", "HA Open/Close"};#"Which levels to use for upper and lower?")
input wick = yes;
input PaintHeikenAshiBars = no;
input ha_smooth_ma_type = {default EMA, SMA, WMA, McGinley, HMA};
input ha_smooth_length = 10; # "Smooth Length"
input ha_after_smooth_ma_type = {default EMA, SMA, WMA, VWMA, McGinley, HMA};
input ha_after_smooth_length = 10;#

def na = Double.NaN;
def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [

# mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 , mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)), src);
    plot return = mg;
}

#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then WildersAverage(source, length) else
        if type == "WMA"    then WMA(source, length) else
        if type == "McGinley" then mcginley(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input smooth_length = 1;
 input smooth_ma_type = 1;
 input after_smooth_length = 1;
 input after_smooth_ma_type = 1;
 input wick = yes;
 input agg = AggregationPeriod.FIFTEEN_MIN;
    def src_open = open(period=agg);
    def src_high = high(period=agg);
    def src_low  = low(period=agg);
    def src_close = close(period=agg);
    def haopen;
    def haclose;
    def hahigh;
    def halow;
    def o = anyma(src_open, smooth_length, smooth_ma_type);
    def h = anyma(src_high, smooth_length, smooth_ma_type);
    def l = anyma(src_low, smooth_length, smooth_ma_type);
    def c = anyma(src_close, smooth_length, smooth_ma_type);

    haclose = (o + h + l + c) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(h,Max(haopen, haclose));
    halow  = Min(l,Min(haopen, haclose));
    def SmoothO = anyma(haopen, after_smooth_length, smooth_ma_type);
    def SmoothH = anyma(if(wick,hahigh,haclose), after_smooth_length,smooth_ma_type);
    def SmoothL = anyma(if(wick,halow,haclose), after_smooth_length, smooth_ma_type);
    def SmoothC = anyma(haclose, after_smooth_length, smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def o = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def h = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def l = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def c = heiken_ashi(1,ha_smooth_ma_type,1,ha_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(type==type."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(type==type."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;    # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;    # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart

def HAo = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).OpenHA;
def HAh = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).HighHA;
def HAl = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).LowHA;
def HAc = heiken_ashi(ha_smooth_length,ha_smooth_ma_type,ha_after_smooth_length,ha_after_smooth_ma_type,wick,if(useChartTime,chartTime,Aggregation)).CloseHA;
def dir = HAo>HAc;
AddChart(high = if SmoothedHeikenAshi and !dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAc,HAo),  close = if(PaintHeikenAshiBars,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if SmoothedHeikenAshi and dir then HAh else na , low = HAl ,
         open = if(PaintHeikenAshiBars,HAo,HAc),  close = if(PaintHeikenAshiBars,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#---- Bar Color---
AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

#---END CODE

Update: some code improvements and added different candle calc options and HA style options (Candle and parapolice)

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
input afterSmoothLength = 10;#

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#export tema(float src, simple int len)=>
script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot;
if dir {
    crossPlot = HAh;
    } else {
        crossPlot = HAl; }
def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
i don't see the upper and lower line (band). Can you let me know what I am doing wrong?
 
@samer800 Would it be possible to add McGinley to the version of the CODE under:
Update: some code improvements and added different candle calc options and HA style options (Candle and parapolice)
Thank you!
McGinley MA added

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {"Don't Show", "Candle",Default "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA, McGinley};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA, McGinley};
input afterSmoothLength = 10;#
input ShowLine = no;

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#McGinley(src, len)
script mg {
    input src = close;
    input len = 0;
#    def McGinley = McGinley[1] + (src - McGinley[1]) / (len * Power(src / McGinley[1], 4));
#    def MDI = ExpAverage(src, len)[1];
    def Mcg = if IsNaN(Mcg[1]) then ExpAverage(src, len) else
  CompoundValue(1, Mcg[1] + ((src - Mcg[1]) / (len * Power(src / Mcg[1], 4))), src);
#    def mg = if IsNaN(MDI) then ExpAverage(src, len) else
#                 MDI[1] + (src - MDI[1]) / (len * Power(src / MDI[1], 4));
    plot result = Mcg;
}
#export tema(float src, simple int len)=>
#script tema {
#    input src = close;
#    input len = 14;
#    def ema1 = ExpAverage(src, len);
#    def ema2 = ExpAverage(ema1, len);
#    def ema3 = ExpAverage(ema2, len);
#    def tema = 3 * (ema1 - ema2) + ema3;
#    plot return = tema;
#}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "McGinley" then mg(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot; def state;
if dir {
    crossPlot = HAh;
    state     = 1;
    } else { 
        crossPlot = HAl;
        state     = -1;}
#def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
#def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

def trBull = if state==1 then trBull[1]+1 else 0;
def trBear = if state==-1 then trBear[1]+1 else 0;

def transitionBarBull = if trBull==1 then crossPlot else transitionBarBull[1];
def transitionBarBear = if trBear==1 then crossPlot else transitionBarBear[1];

def transitionPriceBull = if trBull  then transitionBarBull[1] else transitionPriceBull[1];
def transitionPriceBear = if trBear and c>transitionBarBear  then transitionBarBear[1] else transitionPriceBear[1];

def hlineBull = transitionPriceBull;
def hlineBear = transitionPriceBear;


plot horizLineBull = if !ShowLine then na else hlineBull;
horizLineBull.SetLineWeight(2);
horizLineBull.SetDefaultColor(Color.LIME);
horizLineBull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot horizLineBear = if !ShowLine then na else hlineBear;
horizLineBear.SetLineWeight(2);
horizLineBear.SetDefaultColor(Color.PINK);
horizLineBear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
 
McGinley MA added

CSS:
#// © wallneradam
#indicator("Heiken Ashi Swing High/Low with Smoothed HA"
# Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
# Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
input showPricePlot = yes;
input ColorBars = no;
input useChartTime = yes;
input Aggregation = AggregationPeriod.FIFTEEN_MIN;
input ShowBand = yes;
input HeikenAshiStyle = {"Don't Show", "Candle",Default "Parabolic"};
input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
input candleCalcType  = {Default "Default", "Valcu", "Vervoort"};
input SourceCalcMethod = {Default "High/Low", "Candle Close"};
input ShowWick = yes;
input PaintHaCandle = no;
input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA, McGinley};
input MaSmoothLength = 1;
input smoothLength = 10; # "Smooth Length"
input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA, McGinley};
input afterSmoothLength = 10;#
input ShowLine = no;

hidePricePlot(!showPricePlot);
def na = Double.NaN;
def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
                if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
#def chartTime = GetAggregationPeriod();
def mtfc = if(useChartTime,close,close(Period=Aggregation));
def mtfh = if(useChartTime,high,high(Period=Aggregation));
def mtfl = if(useChartTime,low,low(Period=Aggregation));
def mtfo = if(useChartTime,open,open(Period=Aggregation));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
#McGinley(src, len)
script mg {
    input src = close;
    input len = 0;
#    def McGinley = McGinley[1] + (src - McGinley[1]) / (len * Power(src / McGinley[1], 4));
#    def MDI = ExpAverage(src, len)[1];
    def Mcg = if IsNaN(Mcg[1]) then ExpAverage(src, len) else
  CompoundValue(1, Mcg[1] + ((src - Mcg[1]) / (len * Power(src / Mcg[1], 4))), src);
#    def mg = if IsNaN(MDI) then ExpAverage(src, len) else
#                 MDI[1] + (src - MDI[1]) / (len * Power(src / MDI[1], 4));
    plot result = Mcg;
}
#export tema(float src, simple int len)=>
#script tema {
#    input src = close;
#    input len = 14;
#    def ema1 = ExpAverage(src, len);
#    def ema2 = ExpAverage(ema1, len);
#    def ema3 = ExpAverage(ema2, len);
#    def tema = 3 * (ema1 - ema2) + ema3;
#    plot return = tema;
#}
#vwma(source, length)
script VWMA {
    input x = close;
    input y = 15;
def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
}
script ALMA {
  input Data = close;
  input Window = 9;
  input Sigma = 6;
  input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
         WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
         CW + Exp(-(sqr(z-m))/(2*sqr(s)));
 plot ALMA = SumVectorData / SumVector;
}
#export multiMa(float source, simple int length, string type) =>
script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
        if type == "SMA"  then SimpleMovingAvg(source, length) else
        if type == "EMA"  then ExpAverage(source, length) else
        if type == "SMMA" then WildersAverage(source, length) else
        if type == "WMA"  then WMA(source, length) else
        if type == "TEMA" then TEMA(source, length) else
        if type == "LSMA" then Inertia(source, length) else
        if type == "ALMA" then ALMA(source, length) else
        if type == "VWMA" then VWMA(source, length) else
        if type == "McGinley" then mg(source, length) else
        if type == "HMA"  then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
script heiken_ashi {
 input src_open  = open;
 input src_close = close;
 input src_high  = high;
 input src_low   = low;
 input after_smooth_length = 10;
 input after_smooth_ma_type = yes;
 input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow  = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA  = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
}
def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
switch(candleCalcType) {
case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow  = Min(mal,Min(haopen, haclose));
}
def o = haOpen;
def h = hahigh;
def l = halow;
def c = haClose;

def upper;
def lower;

if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
 if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
}}

plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper;  # "Upper"
plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower;  # "Lower"
UpBand.SetDefaultColor(Color.CYAN);
LoBand.SetDefaultColor(Color.MAGENTA);

#--- Smoothed
# Plot the new Chart
def smO = anyma(o, smoothLength, smoothMaType);;
def smH = anyma(h, smoothLength, smoothMaType);;
def smL = anyma(l, smoothLength, smoothMaType);;
def smC = anyma(c, smoothLength, smoothMaType);;

def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).OpenHA;
def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).HighHA;
def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).LowHA;
def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afterSmoothMaType,ShowWick).CloseHA;

def dir = HAo>HAc;
AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAc,HAo),  close = if(PaintHaCandle,HAo,HAc),
         type = ChartType.CANDLE, growcolor =  CreateColor(4,127,145));

AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
         open = if(PaintHaCandle,HAo,HAc),  close = if(PaintHaCandle,HAc,HAo),
         type = ChartType.CANDLE, growcolor =  CreateColor(123,3,143));

#--- Par Calc

def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

def crossPlot; def state;
if dir {
    crossPlot = HAh;
    state     = 1;
    } else {
        crossPlot = HAl;
        state     = -1;}
#def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
#def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

def plotColor =  if high_squeeze then -1 else
                 if low_squeeze then 1 else
                 if !dir then 2 else -2;

plot haLine = if(HeikStyle!=1, na, crossPlot);
haLine.SetStyle(Curve.POINTS);
haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
                        if plotColor==1 then Color.DARK_GREEN else
                        if plotColor==2 then Color.GREEN else Color.RED);

def trBull = if state==1 then trBull[1]+1 else 0;
def trBear = if state==-1 then trBear[1]+1 else 0;

def transitionBarBull = if trBull==1 then crossPlot else transitionBarBull[1];
def transitionBarBear = if trBear==1 then crossPlot else transitionBarBear[1];

def transitionPriceBull = if trBull  then transitionBarBull[1] else transitionPriceBull[1];
def transitionPriceBear = if trBear and c>transitionBarBear  then transitionBarBear[1] else transitionPriceBear[1];

def hlineBull = transitionPriceBull;
def hlineBear = transitionPriceBear;


plot horizLineBull = if !ShowLine then na else hlineBull;
horizLineBull.SetLineWeight(2);
horizLineBull.SetDefaultColor(Color.LIME);
horizLineBull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot horizLineBear = if !ShowLine then na else hlineBear;
horizLineBear.SetLineWeight(2);
horizLineBear.SetDefaultColor(Color.PINK);
horizLineBear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


#---- Bar Color---
AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
                 if mtfc>HAh and !dir then color.GREEN else
                 if mtfc>HAh and dir then color.DARK_GREEN else
                 if mtfc<HAl and dir then Color.RED else
                 if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
                 if plotColor==2 then Color.GREEN else
                 if plotColor==1 then Color.Dark_GREEN else
                 if plotColor==-1 then Color.DARK_RED else Color.RED);

#---END CODE
@samer800 I'm not sure if this is even possible but can the ARMA (autonomous-recursive-moving-average) be added to this indicator as a moving average option? It would be interesting to see how it would plot. Thank you!
https://usethinkscript.com/threads/...ursive-moving-average-arma.13926/#post-115864
 
I like the Smoothed HA indicator and was hoping someone could help me with a scan that will show me when the indicator changes color from purple to blue.

This is a nice indicator!
Does anyone have a TOS Scan that will show a change in color (direction) from purple to blue or vice versa?
 
I like the Smoothed HA indicator and was hoping someone could help me with a scan that will show me when the indicator changes color from purple to blue.

This is a nice indicator!
Does anyone have a TOS Scan that will show a change in color (direction) from purple to blue or vice versa?
Hi, I'm not a coder, but you can look for price to be above the MA34 for blue and below for purple.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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