wavefollower

following the wave and trading happy
正文

A-V2 Script

(2023-06-11 00:59:06) 下一个
#A-V2  Trading Cloud

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) 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
[ 打印 ]
阅读 ()评论 (0)
评论
目前还没有任何评论
登录后才可评论.