Trend Indicator A-V2 (Smoothed Heikin Ashi Cloud) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
aQ1muxe.png

Author Message:
Trend Indicator A-V2" and "Trend Indicator B-V2" are updated and improved versions of trend indicators. Totally rethinking the code, adding highs and lows in the calculations, including some more customisation through colour schemes.

In practice, this indicator uses EMAs and Heikin Ashi to provide an overall idea of the trend.
  • The "Trend Indicator A-V2" is an overlay showing “Smoothed Heikin Ashi”.
  • The "Trend Indicator B-V2" uses the same values in a different way to measure the momentum of the trend and identify potential trend rejections.

Please, take into account that it is a lagging indicator.

CODE:

CSS:
# https://www.tradingview.com/v/DTDQ3y76/
#// Author | © Dziwne
#study(title="Trend Indicator A-V2.2 [Dziwne]", shorttitle="Trend Indicator A-V2.2 [Dziwne]"
# Converted by Sam4Cok@Samer800        - 04/2023
input ColorBars = no;
input ma_type = {SMA, EMA, SMMA, WMA, default VWMA, RMS, DEMA, TEMA, ZLSMA, ZLDEMA, ZLTEMA, McGinley, HMA, SWMA, Gaussian, KAMA, MAV, LSMA};                         # "MA Type"
input ma_period = 20;               # "MA Period (Length)"
input ma_period_smoothing = 7;      # "MA Period smoothing (Length)"
input Show_Signals = yes;
input show_High_Low_cloud = yes;    # "Show (cloud)"
input show_High_Low_Lines = no;     # "Show (High & Low Lines)"
input show_Open_Close_Lines = no;   # "Show (Open & Close Lines)"

def na = Double.NaN;

#Color
DefineGlobalColor("pos" , CreateColor(42, 182, 169));
DefineGlobalColor("neg" , CreateColor(237, 60, 57));

#rms(source, length)=>
script rms {
    input source = close;
    input length = 14;
    def rms = Sqrt(Sum(Power(source, 2), length) / length);
    plot return = rms;
}
#mav (source, length) =>
script mav {
    input source = close;
    input length = 14;
    def mav = ((SimpleMovingAvg(source, length)[1] * (length - 1)) + source) / length;
    plot return = mav;
}
#kama(xPrice, Length)=>
script kama {
    input xPrice = close;
    input Length = 14;
    def xvnoise = AbsValue(xPrice - xPrice[1]);
    def nfastend = 0.666;
    def nslowend = 0.0645;
    def nsignal = AbsValue(xPrice - xPrice[Length]);
    def nnoise = Sum(xvnoise, Length);
    def nefratio = if nnoise != 0 then nsignal / nnoise else 0;
    def nsmooth = Power(nefratio * (nfastend - nslowend) + nslowend, 2);
    def nAMA;
    nAMA = CompoundValue(1, nAMA[1] + nsmooth * (xPrice - nAMA[1]), xPrice);
    plot returen = nAMA;
}
#Gaussianma(values, length) =>
script Gaussian {
    input values = close;
    input length = 20;
    def stddev = length / 4;
    def indices = length - 1;
    def weights = Exp(-0.5 * (Power((indices - length), 2) / Power(stddev, 2)));
    def sum = Sum(values * weights, length);
    def gMA = sum / Sum(weights, length);
    plot return = gMA;
}
#export zlSma(float src, simple int len) =>
script zlSma {
    input src = close;
    input len = 14;
    def lsma = Inertia(src, len);
    def lsma2 = Inertia(lsma, len);
    def eq = lsma - lsma2;
    def zlsma = lsma + eq;
    plot return = zlsma;
}
#export zlDema(float src, simple int len) =>
script zlDema {
    input src = close;
    input len = 14;
    def zdema1 = ExpAverage(src, len);
    def zdema2 = ExpAverage(zdema1, len);
    def dema1 = 2 * zdema1 - zdema2;
    def zdema12 = ExpAverage(dema1, len);
    def zdema22 = ExpAverage(zdema12, len);
    def zldema = 2 * zdema12 - zdema22;
    plot return = zldema;
}
#export zlTema(float src, simple int len) =>
script zlTema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema1 = 3 * (ema1 - ema2) + ema3;
    def ema1a = ExpAverage(tema1, len);
    def ema2a = ExpAverage(ema1a, len);
    def ema3a = ExpAverage(ema2a, len);
    def zltema = 3 * (ema1a - ema2a) + ema3a;
    plot return = zltema;
}
#export multiMa(float source, simple int length, string type) =>
script f_ma_type {
    input type = "SMA";
    input source = close;
    input length = 14;
    def w = WMA(source, length);
    def swma = source[3] * 1 / 6 + source[2] * 2 / 6 +  source[1] * 2 / 6 + source[0] * 1 / 6;
    def mg;
    def t = ExpAverage(source, length);
    mg = CompoundValue(1 , if IsNaN(mg[1]) then t else mg[1] + (source - mg[1]) / (length * Power(source / mg[1], 4)), t);
    def v = if volume==0 or isNaN(volume) then 1 else volume;
    def VWMA = SimpleMovingAvg(source * v, length) / SimpleMovingAvg(v, length);
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then CompoundValue(1, if IsNaN(w[1]) then Average(source, length) else
                                 (w[1] * (length - 1) + source) / length,  Average(source, length)) else
        if type == "WMA"    then WMA(source, length) else
        if type == "KAMA"   then KAMA(source, length) else
        if type == "MAV"    then MAV(source, length) else
        if type == "VWMA"   then VWMA else
        if type == "DEMA"   then DEMA(source, length) else
        if type == "TEMA"   then TEMA(source, length) else
        if type == "LSMA"   then Inertia(source, length) else
        if type == "RMS"    then RMS(source, length) else
        if type == "ZLSMA"  then zlSma(source, length) else
        if type == "ZLDEMA" then zlDema(source, length) else
        if type == "ZLTEMA" then zlTema(source, length) else
        if type == "McGinley" then mg else
        if type == "SWMA"   then swma else
        if type == "Gaussian"   then Gaussian(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#// II.1. Calculations, MA
def o = f_ma_type(ma_type, open, ma_period);
def c = f_ma_type(ma_type, close, ma_period);
def h = f_ma_type(ma_type, high, ma_period);
def l = f_ma_type(ma_type, low, ma_period);

def ha_C = (o + h + l + c) / 4;
def ha_O = CompoundValue(1, (ha_O[1] + ha_C[1]) / 2, (o[1] + c[1]) / 2);
def ha_H = Max(Max(h, ha_O), ha_C);
def ha_L = Min(Min(l, ha_O), ha_C);

#// II.3. Calculations, MA (Smoothing)

def ha_o_smooth = f_ma_type(ma_type, ha_O, ma_period_smoothing);
def ha_c_smooth = f_ma_type(ma_type, ha_C, ma_period_smoothing);
def ha_h_smooth = f_ma_type(ma_type, ha_H, ma_period_smoothing);
def ha_l_smooth = f_ma_type(ma_type, ha_L, ma_period_smoothing);

#// III.1. Display, Colors

def trend = ha_c_smooth >= ha_o_smooth;
def o_line = ha_o_smooth;        # "Open line"
def c_line = ha_c_smooth;        # "Close line"

def h_line = if show_High_Low_cloud then ha_h_smooth else na;        # "High line"
def l_line = if show_High_Low_cloud then ha_l_smooth else na;        # "Low line"
AddCloud(c_line, o_line, GlobalColor("pos"), GlobalColor("neg"), show_Open_Close_Lines);
AddCloud(h_line, l_line, Color.DARK_GRAY, Color.DARK_GRAY, show_High_Low_Lines);

def crossUp = if (c_line>o_line and close > h_line) then crossUp[1]+1 else 0;
def crossDn = if (c_line<o_line and close < l_line) then crossDn[1]+1 else 0;

plot WedgUp = if Show_Signals and crossUp==2 then low else na;
plot WedgDn = if Show_Signals and crossDn==2 then high else na;
WedgUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
WedgDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
WedgUp.SetDefaultColor(Color.CYAN);
WedgDn.SetDefaultColor(Color.MAGENTA);

AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if trend then Color.GREEN else Color.RED);

#-- Close of CODE
 
Last edited by a moderator:

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

View attachment 18306
Author Message:
Trend Indicator A-V2" and "Trend Indicator B-V2" are updated and improved versions of trend indicators. Totally rethinking the code, adding highs and lows in the calculations, including some more customisation through colour schemes.

In practice, this indicator uses EMAs and Heikin Ashi to provide an overall idea of the trend.
  • The "Trend Indicator A-V2" is an overlay showing “Smoothed Heikin Ashi”.
  • The "Trend Indicator B-V2" uses the same values in a different way to measure the momentum of the trend and identify potential trend rejections.

Please, take into account that it is a lagging indicator.

CODE:

CSS:
# https://www.tradingview.com/v/DTDQ3y76/
#// Author | © Dziwne
#study(title="Trend Indicator A-V2.2 [Dziwne]", shorttitle="Trend Indicator A-V2.2 [Dziwne]"
# Converted by Sam4Cok@Samer800        - 04/2023
input ColorBars = no;
input ma_type = {SMA, EMA, SMMA, WMA, default VWMA, RMS, DEMA, TEMA, ZLSMA, ZLDEMA, ZLTEMA, McGinley, HMA, SWMA, Gaussian, KAMA, MAV, LSMA};                         # "MA Type"
input ma_period = 20;               # "MA Period (Length)"
input ma_period_smoothing = 7;      # "MA Period smoothing (Length)"
input Show_Signals = yes;
input show_High_Low_cloud = yes;    # "Show (cloud)"
input show_High_Low_Lines = no;     # "Show (High & Low Lines)"
input show_Open_Close_Lines = no;   # "Show (Open & Close Lines)"

def na = Double.NaN;

#Color
DefineGlobalColor("pos" , CreateColor(42, 182, 169));
DefineGlobalColor("neg" , CreateColor(237, 60, 57));

#rms(source, length)=>
script rms {
    input source = close;
    input length = 14;
    def rms = Sqrt(Sum(Power(source, 2), length) / length);
    plot return = rms;
}
#mav (source, length) =>
script mav {
    input source = close;
    input length = 14;
    def mav = ((SimpleMovingAvg(source, length)[1] * (length - 1)) + source) / length;
    plot return = mav;
}
#kama(xPrice, Length)=>
script kama {
    input xPrice = close;
    input Length = 14;
    def xvnoise = AbsValue(xPrice - xPrice[1]);
    def nfastend = 0.666;
    def nslowend = 0.0645;
    def nsignal = AbsValue(xPrice - xPrice[Length]);
    def nnoise = Sum(xvnoise, Length);
    def nefratio = if nnoise != 0 then nsignal / nnoise else 0;
    def nsmooth = Power(nefratio * (nfastend - nslowend) + nslowend, 2);
    def nAMA;
    nAMA = CompoundValue(1, nAMA[1] + nsmooth * (xPrice - nAMA[1]), xPrice);
    plot returen = nAMA;
}
#Gaussianma(values, length) =>
script Gaussian {
    input values = close;
    input length = 20;
    def stddev = length / 4;
    def indices = length - 1;
    def weights = Exp(-0.5 * (Power((indices - length), 2) / Power(stddev, 2)));
    def sum = Sum(values * weights, length);
    def gMA = sum / Sum(weights, length);
    plot return = gMA;
}
#export zlSma(float src, simple int len) =>
script zlSma {
    input src = close;
    input len = 14;
    def lsma = Inertia(src, len);
    def lsma2 = Inertia(lsma, len);
    def eq = lsma - lsma2;
    def zlsma = lsma + eq;
    plot return = zlsma;
}
#export zlDema(float src, simple int len) =>
script zlDema {
    input src = close;
    input len = 14;
    def zdema1 = ExpAverage(src, len);
    def zdema2 = ExpAverage(zdema1, len);
    def dema1 = 2 * zdema1 - zdema2;
    def zdema12 = ExpAverage(dema1, len);
    def zdema22 = ExpAverage(zdema12, len);
    def zldema = 2 * zdema12 - zdema22;
    plot return = zldema;
}
#export zlTema(float src, simple int len) =>
script zlTema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema1 = 3 * (ema1 - ema2) + ema3;
    def ema1a = ExpAverage(tema1, len);
    def ema2a = ExpAverage(ema1a, len);
    def ema3a = ExpAverage(ema2a, len);
    def zltema = 3 * (ema1a - ema2a) + ema3a;
    plot return = zltema;
}
#export multiMa(float source, simple int length, string type) =>
script f_ma_type {
    input type = "SMA";
    input source = close;
    input length = 14;
    def w = WMA(source, length);
    def swma = source[3] * 1 / 6 + source[2] * 2 / 6 +  source[1] * 2 / 6 + source[0] * 1 / 6;
    def mg;
    def t = ExpAverage(source, length);
    mg = CompoundValue(1 , if IsNaN(mg[1]) then t else mg[1] + (source - mg[1]) / (length * Power(source / mg[1], 4)), t);
    def v = if volume==0 or isNaN(volume) then 1 else volume;
    def VWMA = SimpleMovingAvg(source * v, length) / SimpleMovingAvg(v, length);
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then CompoundValue(1, if IsNaN(w[1]) then Average(source, length) else
                                 (w[1] * (length - 1) + source) / length,  Average(source, length)) else
        if type == "WMA"    then WMA(source, length) else
        if type == "KAMA"   then KAMA(source, length) else
        if type == "MAV"    then MAV(source, length) else
        if type == "VWMA"   then VWMA else
        if type == "DEMA"   then DEMA(source, length) else
        if type == "TEMA"   then TEMA(source, length) else
        if type == "LSMA"   then Inertia(source, length) else
        if type == "RMS"    then RMS(source, length) else
        if type == "ZLSMA"  then zlSma(source, length) else
        if type == "ZLDEMA" then zlDema(source, length) else
        if type == "ZLTEMA" then zlTema(source, length) else
        if type == "McGinley" then mg else
        if type == "SWMA"   then swma else
        if type == "Gaussian"   then Gaussian(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#// II.1. Calculations, MA
def o = f_ma_type(ma_type, open, ma_period);
def c = f_ma_type(ma_type, close, ma_period);
def h = f_ma_type(ma_type, high, ma_period);
def l = f_ma_type(ma_type, low, ma_period);

def ha_C = (o + h + l + c) / 4;
def ha_O = CompoundValue(1, (ha_O[1] + ha_C[1]) / 2, (o[1] + c[1]) / 2);
def ha_H = Max(Max(h, ha_O), ha_C);
def ha_L = Min(Min(l, ha_O), ha_C);

#// II.3. Calculations, MA (Smoothing)

def ha_o_smooth = f_ma_type(ma_type, ha_O, ma_period_smoothing);
def ha_c_smooth = f_ma_type(ma_type, ha_C, ma_period_smoothing);
def ha_h_smooth = f_ma_type(ma_type, ha_H, ma_period_smoothing);
def ha_l_smooth = f_ma_type(ma_type, ha_L, ma_period_smoothing);

#// III.1. Display, Colors

def trend = ha_c_smooth >= ha_o_smooth;
def o_line = ha_o_smooth;        # "Open line"
def c_line = ha_c_smooth;        # "Close line"

def h_line = if show_High_Low_cloud then ha_h_smooth else na;        # "High line"
def l_line = if show_High_Low_cloud then ha_l_smooth else na;        # "Low line"
AddCloud(c_line, o_line, GlobalColor("pos"), GlobalColor("neg"), show_Open_Close_Lines);
AddCloud(h_line, l_line, Color.DARK_GRAY, Color.DARK_GRAY, show_High_Low_Lines);

def crossUp = if (c_line>o_line and close > h_line) then crossUp[1]+1 else 0;
def crossDn = if (c_line<o_line and close < l_line) then crossDn[1]+1 else 0;

plot WedgUp = if Show_Signals and crossUp==2 then low else na;
plot WedgDn = if Show_Signals and crossDn==2 then high else na;
WedgUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
WedgDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
WedgUp.SetDefaultColor(Color.CYAN);
WedgDn.SetDefaultColor(Color.MAGENTA);

AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if trend then Color.GREEN else Color.RED);

#-- Close of CODE
Thanks for sharing it. I was try to use it in scan for crossUp and crossDN. Any way to do it?
 
Thanks for sharing it. I was try to use it in scan for crossUp and crossDN. Any way to do it?

This script is too complex for the ToS Scan Hacker.
It will not run. Any attempts will result in this error msg:
com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests that it may not be reliable with real-time data.
 
View attachment 18306
Author Message:
Trend Indicator A-V2" and "Trend Indicator B-V2" are updated and improved versions of trend indicators. Totally rethinking the code, adding highs and lows in the calculations, including some more customisation through colour schemes.

In practice, this indicator uses EMAs and Heikin Ashi to provide an overall idea of the trend.
  • The "Trend Indicator A-V2" is an overlay showing “Smoothed Heikin Ashi”.
  • The "Trend Indicator B-V2" uses the same values in a different way to measure the momentum of the trend and identify potential trend rejections.

Please, take into account that it is a lagging indicator.

CODE:

CSS:
# https://www.tradingview.com/v/DTDQ3y76/
#// Author | © Dziwne
#study(title="Trend Indicator A-V2.2 [Dziwne]", shorttitle="Trend Indicator A-V2.2 [Dziwne]"
# Converted by Sam4Cok@Samer800        - 04/2023
input ColorBars = no;
input ma_type = {SMA, EMA, SMMA, WMA, default VWMA, RMS, DEMA, TEMA, ZLSMA, ZLDEMA, ZLTEMA, McGinley, HMA, SWMA, Gaussian, KAMA, MAV, LSMA};                         # "MA Type"
input ma_period = 20;               # "MA Period (Length)"
input ma_period_smoothing = 7;      # "MA Period smoothing (Length)"
input Show_Signals = yes;
input show_High_Low_cloud = yes;    # "Show (cloud)"
input show_High_Low_Lines = no;     # "Show (High & Low Lines)"
input show_Open_Close_Lines = no;   # "Show (Open & Close Lines)"

def na = Double.NaN;

#Color
DefineGlobalColor("pos" , CreateColor(42, 182, 169));
DefineGlobalColor("neg" , CreateColor(237, 60, 57));

#rms(source, length)=>
script rms {
    input source = close;
    input length = 14;
    def rms = Sqrt(Sum(Power(source, 2), length) / length);
    plot return = rms;
}
#mav (source, length) =>
script mav {
    input source = close;
    input length = 14;
    def mav = ((SimpleMovingAvg(source, length)[1] * (length - 1)) + source) / length;
    plot return = mav;
}
#kama(xPrice, Length)=>
script kama {
    input xPrice = close;
    input Length = 14;
    def xvnoise = AbsValue(xPrice - xPrice[1]);
    def nfastend = 0.666;
    def nslowend = 0.0645;
    def nsignal = AbsValue(xPrice - xPrice[Length]);
    def nnoise = Sum(xvnoise, Length);
    def nefratio = if nnoise != 0 then nsignal / nnoise else 0;
    def nsmooth = Power(nefratio * (nfastend - nslowend) + nslowend, 2);
    def nAMA;
    nAMA = CompoundValue(1, nAMA[1] + nsmooth * (xPrice - nAMA[1]), xPrice);
    plot returen = nAMA;
}
#Gaussianma(values, length) =>
script Gaussian {
    input values = close;
    input length = 20;
    def stddev = length / 4;
    def indices = length - 1;
    def weights = Exp(-0.5 * (Power((indices - length), 2) / Power(stddev, 2)));
    def sum = Sum(values * weights, length);
    def gMA = sum / Sum(weights, length);
    plot return = gMA;
}
#export zlSma(float src, simple int len) =>
script zlSma {
    input src = close;
    input len = 14;
    def lsma = Inertia(src, len);
    def lsma2 = Inertia(lsma, len);
    def eq = lsma - lsma2;
    def zlsma = lsma + eq;
    plot return = zlsma;
}
#export zlDema(float src, simple int len) =>
script zlDema {
    input src = close;
    input len = 14;
    def zdema1 = ExpAverage(src, len);
    def zdema2 = ExpAverage(zdema1, len);
    def dema1 = 2 * zdema1 - zdema2;
    def zdema12 = ExpAverage(dema1, len);
    def zdema22 = ExpAverage(zdema12, len);
    def zldema = 2 * zdema12 - zdema22;
    plot return = zldema;
}
#export zlTema(float src, simple int len) =>
script zlTema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema1 = 3 * (ema1 - ema2) + ema3;
    def ema1a = ExpAverage(tema1, len);
    def ema2a = ExpAverage(ema1a, len);
    def ema3a = ExpAverage(ema2a, len);
    def zltema = 3 * (ema1a - ema2a) + ema3a;
    plot return = zltema;
}
#export multiMa(float source, simple int length, string type) =>
script f_ma_type {
    input type = "SMA";
    input source = close;
    input length = 14;
    def w = WMA(source, length);
    def swma = source[3] * 1 / 6 + source[2] * 2 / 6 +  source[1] * 2 / 6 + source[0] * 1 / 6;
    def mg;
    def t = ExpAverage(source, length);
    mg = CompoundValue(1 , if IsNaN(mg[1]) then t else mg[1] + (source - mg[1]) / (length * Power(source / mg[1], 4)), t);
    def v = if volume==0 or isNaN(volume) then 1 else volume;
    def VWMA = SimpleMovingAvg(source * v, length) / SimpleMovingAvg(v, length);
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then CompoundValue(1, if IsNaN(w[1]) then Average(source, length) else
                                 (w[1] * (length - 1) + source) / length,  Average(source, length)) else
        if type == "WMA"    then WMA(source, length) else
        if type == "KAMA"   then KAMA(source, length) else
        if type == "MAV"    then MAV(source, length) else
        if type == "VWMA"   then VWMA else
        if type == "DEMA"   then DEMA(source, length) else
        if type == "TEMA"   then TEMA(source, length) else
        if type == "LSMA"   then Inertia(source, length) else
        if type == "RMS"    then RMS(source, length) else
        if type == "ZLSMA"  then zlSma(source, length) else
        if type == "ZLDEMA" then zlDema(source, length) else
        if type == "ZLTEMA" then zlTema(source, length) else
        if type == "McGinley" then mg else
        if type == "SWMA"   then swma else
        if type == "Gaussian"   then Gaussian(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#// II.1. Calculations, MA
def o = f_ma_type(ma_type, open, ma_period);
def c = f_ma_type(ma_type, close, ma_period);
def h = f_ma_type(ma_type, high, ma_period);
def l = f_ma_type(ma_type, low, ma_period);

def ha_C = (o + h + l + c) / 4;
def ha_O = CompoundValue(1, (ha_O[1] + ha_C[1]) / 2, (o[1] + c[1]) / 2);
def ha_H = Max(Max(h, ha_O), ha_C);
def ha_L = Min(Min(l, ha_O), ha_C);

#// II.3. Calculations, MA (Smoothing)

def ha_o_smooth = f_ma_type(ma_type, ha_O, ma_period_smoothing);
def ha_c_smooth = f_ma_type(ma_type, ha_C, ma_period_smoothing);
def ha_h_smooth = f_ma_type(ma_type, ha_H, ma_period_smoothing);
def ha_l_smooth = f_ma_type(ma_type, ha_L, ma_period_smoothing);

#// III.1. Display, Colors

def trend = ha_c_smooth >= ha_o_smooth;
def o_line = ha_o_smooth;        # "Open line"
def c_line = ha_c_smooth;        # "Close line"

def h_line = if show_High_Low_cloud then ha_h_smooth else na;        # "High line"
def l_line = if show_High_Low_cloud then ha_l_smooth else na;        # "Low line"
AddCloud(c_line, o_line, GlobalColor("pos"), GlobalColor("neg"), show_Open_Close_Lines);
AddCloud(h_line, l_line, Color.DARK_GRAY, Color.DARK_GRAY, show_High_Low_Lines);

def crossUp = if (c_line>o_line and close > h_line) then crossUp[1]+1 else 0;
def crossDn = if (c_line<o_line and close < l_line) then crossDn[1]+1 else 0;

plot WedgUp = if Show_Signals and crossUp==2 then low else na;
plot WedgDn = if Show_Signals and crossDn==2 then high else na;
WedgUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
WedgDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
WedgUp.SetDefaultColor(Color.CYAN);
WedgDn.SetDefaultColor(Color.MAGENTA);

AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if trend then Color.GREEN else Color.RED);

#-- Close of CODE
YA HOO it took a long time for ME to see a Script using these studies combined . i put together a Script using the same studies have been testing it using live Trades . i like what i see.
 
View attachment 18306
Author Message:
Trend Indicator A-V2" and "Trend Indicator B-V2" are updated and improved versions of trend indicators. Totally rethinking the code, adding highs and lows in the calculations, including some more customisation through colour schemes.

In practice, this indicator uses EMAs and Heikin Ashi to provide an overall idea of the trend.
  • The "Trend Indicator A-V2" is an overlay showing “Smoothed Heikin Ashi”.
  • The "Trend Indicator B-V2" uses the same values in a different way to measure the momentum of the trend and identify potential trend rejections.

Please, take into account that it is a lagging indicator.

CODE:

CSS:
# https://www.tradingview.com/v/DTDQ3y76/
#// Author | © Dziwne
#study(title="Trend Indicator A-V2.2 [Dziwne]", shorttitle="Trend Indicator A-V2.2 [Dziwne]"
# Converted by Sam4Cok@Samer800        - 04/2023
input ColorBars = no;
input ma_type = {SMA, EMA, SMMA, WMA, default VWMA, RMS, DEMA, TEMA, ZLSMA, ZLDEMA, ZLTEMA, McGinley, HMA, SWMA, Gaussian, KAMA, MAV, LSMA};                         # "MA Type"
input ma_period = 20;               # "MA Period (Length)"
input ma_period_smoothing = 7;      # "MA Period smoothing (Length)"
input Show_Signals = yes;
input show_High_Low_cloud = yes;    # "Show (cloud)"
input show_High_Low_Lines = no;     # "Show (High & Low Lines)"
input show_Open_Close_Lines = no;   # "Show (Open & Close Lines)"

def na = Double.NaN;

#Color
DefineGlobalColor("pos" , CreateColor(42, 182, 169));
DefineGlobalColor("neg" , CreateColor(237, 60, 57));

#rms(source, length)=>
script rms {
    input source = close;
    input length = 14;
    def rms = Sqrt(Sum(Power(source, 2), length) / length);
    plot return = rms;
}
#mav (source, length) =>
script mav {
    input source = close;
    input length = 14;
    def mav = ((SimpleMovingAvg(source, length)[1] * (length - 1)) + source) / length;
    plot return = mav;
}
#kama(xPrice, Length)=>
script kama {
    input xPrice = close;
    input Length = 14;
    def xvnoise = AbsValue(xPrice - xPrice[1]);
    def nfastend = 0.666;
    def nslowend = 0.0645;
    def nsignal = AbsValue(xPrice - xPrice[Length]);
    def nnoise = Sum(xvnoise, Length);
    def nefratio = if nnoise != 0 then nsignal / nnoise else 0;
    def nsmooth = Power(nefratio * (nfastend - nslowend) + nslowend, 2);
    def nAMA;
    nAMA = CompoundValue(1, nAMA[1] + nsmooth * (xPrice - nAMA[1]), xPrice);
    plot returen = nAMA;
}
#Gaussianma(values, length) =>
script Gaussian {
    input values = close;
    input length = 20;
    def stddev = length / 4;
    def indices = length - 1;
    def weights = Exp(-0.5 * (Power((indices - length), 2) / Power(stddev, 2)));
    def sum = Sum(values * weights, length);
    def gMA = sum / Sum(weights, length);
    plot return = gMA;
}
#export zlSma(float src, simple int len) =>
script zlSma {
    input src = close;
    input len = 14;
    def lsma = Inertia(src, len);
    def lsma2 = Inertia(lsma, len);
    def eq = lsma - lsma2;
    def zlsma = lsma + eq;
    plot return = zlsma;
}
#export zlDema(float src, simple int len) =>
script zlDema {
    input src = close;
    input len = 14;
    def zdema1 = ExpAverage(src, len);
    def zdema2 = ExpAverage(zdema1, len);
    def dema1 = 2 * zdema1 - zdema2;
    def zdema12 = ExpAverage(dema1, len);
    def zdema22 = ExpAverage(zdema12, len);
    def zldema = 2 * zdema12 - zdema22;
    plot return = zldema;
}
#export zlTema(float src, simple int len) =>
script zlTema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema1 = 3 * (ema1 - ema2) + ema3;
    def ema1a = ExpAverage(tema1, len);
    def ema2a = ExpAverage(ema1a, len);
    def ema3a = ExpAverage(ema2a, len);
    def zltema = 3 * (ema1a - ema2a) + ema3a;
    plot return = zltema;
}
#export multiMa(float source, simple int length, string type) =>
script f_ma_type {
    input type = "SMA";
    input source = close;
    input length = 14;
    def w = WMA(source, length);
    def swma = source[3] * 1 / 6 + source[2] * 2 / 6 +  source[1] * 2 / 6 + source[0] * 1 / 6;
    def mg;
    def t = ExpAverage(source, length);
    mg = CompoundValue(1 , if IsNaN(mg[1]) then t else mg[1] + (source - mg[1]) / (length * Power(source / mg[1], 4)), t);
    def v = if volume==0 or isNaN(volume) then 1 else volume;
    def VWMA = SimpleMovingAvg(source * v, length) / SimpleMovingAvg(v, length);
    def multiMa =
        if type == "SMA"    then SimpleMovingAvg(source, length) else
        if type == "EMA"    then ExpAverage(source, length) else
        if type == "SMMA"   then CompoundValue(1, if IsNaN(w[1]) then Average(source, length) else
                                 (w[1] * (length - 1) + source) / length,  Average(source, length)) else
        if type == "WMA"    then WMA(source, length) else
        if type == "KAMA"   then KAMA(source, length) else
        if type == "MAV"    then MAV(source, length) else
        if type == "VWMA"   then VWMA else
        if type == "DEMA"   then DEMA(source, length) else
        if type == "TEMA"   then TEMA(source, length) else
        if type == "LSMA"   then Inertia(source, length) else
        if type == "RMS"    then RMS(source, length) else
        if type == "ZLSMA"  then zlSma(source, length) else
        if type == "ZLDEMA" then zlDema(source, length) else
        if type == "ZLTEMA" then zlTema(source, length) else
        if type == "McGinley" then mg else
        if type == "SWMA"   then swma else
        if type == "Gaussian"   then Gaussian(source, length) else
        if type == "HMA"    then  HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
}
#// II.1. Calculations, MA
def o = f_ma_type(ma_type, open, ma_period);
def c = f_ma_type(ma_type, close, ma_period);
def h = f_ma_type(ma_type, high, ma_period);
def l = f_ma_type(ma_type, low, ma_period);

def ha_C = (o + h + l + c) / 4;
def ha_O = CompoundValue(1, (ha_O[1] + ha_C[1]) / 2, (o[1] + c[1]) / 2);
def ha_H = Max(Max(h, ha_O), ha_C);
def ha_L = Min(Min(l, ha_O), ha_C);

#// II.3. Calculations, MA (Smoothing)

def ha_o_smooth = f_ma_type(ma_type, ha_O, ma_period_smoothing);
def ha_c_smooth = f_ma_type(ma_type, ha_C, ma_period_smoothing);
def ha_h_smooth = f_ma_type(ma_type, ha_H, ma_period_smoothing);
def ha_l_smooth = f_ma_type(ma_type, ha_L, ma_period_smoothing);

#// III.1. Display, Colors

def trend = ha_c_smooth >= ha_o_smooth;
def o_line = ha_o_smooth;        # "Open line"
def c_line = ha_c_smooth;        # "Close line"

def h_line = if show_High_Low_cloud then ha_h_smooth else na;        # "High line"
def l_line = if show_High_Low_cloud then ha_l_smooth else na;        # "Low line"
AddCloud(c_line, o_line, GlobalColor("pos"), GlobalColor("neg"), show_Open_Close_Lines);
AddCloud(h_line, l_line, Color.DARK_GRAY, Color.DARK_GRAY, show_High_Low_Lines);

def crossUp = if (c_line>o_line and close > h_line) then crossUp[1]+1 else 0;
def crossDn = if (c_line<o_line and close < l_line) then crossDn[1]+1 else 0;

plot WedgUp = if Show_Signals and crossUp==2 then low else na;
plot WedgDn = if Show_Signals and crossDn==2 then high else na;
WedgUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
WedgDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
WedgUp.SetDefaultColor(Color.CYAN);
WedgDn.SetDefaultColor(Color.MAGENTA);

AssignPriceColor(if !ColorBars then Color.CURRENT else
                 if trend then Color.GREEN else Color.RED);

#-- Close of CODE
would be nice to have Profit and Loss per trade Report ADDED .
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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