예스스탁
예스스탁 답변
2023-04-04 11:15:31
안녕하세요
예스스탁입니다.
1
input : length(20),factor(2.0);
var : src(0);
var :maxv(0),minv(0),uptrend(true),stop(0),value(0),atrM(0);
src = close;
atrM = iff(IsNan(atr(length) * factor) == False,atr(length) * factor,TrueRange);
maxv = max(maxv, src);
minv = min(minv, src);
value = IFf(uptrend , max(stop, maxv - atrM) , min(stop, minv + atrM));
stop = iff(IsNan(value) ==False,value, src);
uptrend = src - stop >= 0.0;
if uptrend != uptrend[1] Then
{
maxv = src;
minv = src;
stop = iff(uptrend , maxv - atrM , minv + atrM);
}
plot1(Stop, "Volatility Stop",iff(uptrend , Green,Red));
2
input : Type(1);#0:sma, 1: Ema, 2:dema, 3:tema, 4:WMA, 5:vwma, 6:smma, 7:rma, 8:hma, 9:LRl, 10:Kijun, 11:McGinley
input : Period1(3);
input : Period2(7);
input : Period3(14);
input : PipsMinSepPercent(40);
var : ma01(0),ma02(0),ma03(0);
var : e1(0),e2(0),e3(0),Dif(0),maxv(0),minv(0),filter(0),BraidColor(0);
if type== 0 Then #SMA
{
ma01 = ma(c, Period1);
ma02 = ma(o, Period2);
ma03 = ma(c, Period3);
}
if type== 1 Then #Ema
{
ma01 = ema(c, Period1);
ma02 = ema(o, Period2);
ma03 = ema(c, Period3);
}
if type== 2 Then #DEMA
{
e1 = ema(c, Period1);
ma01 = 2 * e1 - ema(e1, Period1);
e2 = ema(o, Period2);
ma02 = 2 * e2 - ema(e2, Period2);
e3 = ema(c, Period3);
ma03 = 2 * e3 - ema(e3, Period3);
}
if type== 3 Then #"TEMA" // Triple Exponential
{
e1 = ema(c, Period1);
ma01 = 3 * (e1 - ema(e1, Period1)) + ema(ema(e1, Period1), Period1);
e2 = ema(o, Period2);
ma02 = 3 * (e2 - ema(e2, Period2)) + ema(ema(e2, Period2), Period2);
e3 = ema(c, Period3);
ma03 = 3 * (e3 - ema(e3, Period3)) + ema(ema(e3, Period3), Period3);
}
if type== 4 Then #"WMA" // Weighted
{
ma01 = wma(c, Period1);
ma02 = wma(o, Period2);
ma03 = wma(c, Period3);
}
if type== 5 Then #"VWMA" // Volume Weighted
{
ma01 = ma(c * volume, period1) / ma(volume, Period1);
ma02 = ma(o * volume, period2) / ma(volume, Period2);
ma03 = ma(c * volume, period3) / ma(volume, Period3);
}
if type== 6 Then #"SMMA" // Smoothed
{
e1 = wma(c, period1);
e2 = wma(o, period2);
e3 = wma(c, period3);
ma01 = iff(isnan(e1[1]) == true , ma(c, Period1) , (e1[1] * (Period1 - 1) + c) / Period1);
ma02 = iff(isnan(e2[1]) == true , ma(o, Period2) , (e2[1] * (Period2 - 1) + o) / Period2);
ma03 = iff(isnan(e3[1]) == true , ma(c, Period3) , (e3[1] * (Period3 - 1) + c) / Period3);
}
if type == 7 Then # "RMA"
{
e1 = 1/Period1;
e2 = 1/Period2;
e3 = 1/Period3;
ma01 = iff(isnan(ma01[1]) == true, ma(c, Period1) , e1 * c + (1 - e1) * ma01[1]);
ma02 = iff(isnan(ma01[1]) == true, ma(o, Period2) , e2 * o + (1 - e2) * ma02[1]);
ma03 = iff(isnan(ma01[1]) == true, ma(c, Period3) , e3 * c + (1 - e3) * ma03[1]);
}
if type== 8 Then #"HMA" // Hull
{
ma01 = wma(2 * wma(c, period1 / 2) - wma(c, period1), round(sqrt(Period1),0));
ma02 = wma(2 * wma(o, period2 / 2) - wma(o, period2), round(sqrt(Period2),0));
ma03 = wma(2 * wma(c, period3 / 2) - wma(c, period3), round(sqrt(Period3),0));
}
if type== 9 Then #"LRL"
{
ma01 = LRL(c, Period1);
ma02 = LRL(o, Period2);
ma03 = LRL(c, Period3);
}
if type== 10 Then #"Kijun" //Kijun-sen
{
ma01 = Avg(lowest(L,period1),highest(H,period1));
ma01 = Avg(lowest(L,period2),highest(H,period2));
ma01 = Avg(lowest(L,period3),highest(h,period3));
}
if type==11 Then#"McGinley"
{
ma01 = iff(isnan(ma01[1]) == true , ema(c, period1) , ma01[1] + (c - ma01[1]) / (Period1 * pow(c/ma01[1], 4)));
ma02 = iff(isnan(ma02[1]) == true , ema(c, period2) , ma02[1] + (c - ma02[1]) / (Period2 * pow(c/ma02[1], 4)));
ma03 = iff(isnan(ma03[1]) == true , ema(c, period3) , ma03[1] + (c - ma03[1]) / (Period3 * pow(c/ma03[1], 4)));
}
maxv = max(max(ma01, ma02), ma03);
minv = min(min(ma01, ma02), ma03);
dif = maxv - minv;
filter = atr(14) * PipsMinSepPercent / 100;
//-- Plots
BraidColor = iff(ma01 > ma02 and dif > filter ,green ,IFf(ma02 > ma01 and dif > filter , red , gray));
plot1(dif, "Braid", BraidColor);
plot2(filter, "Filter",blue);
즐거운 하루되세요
> seayun1 님이 쓴 글입니다.
> 제목 : 수식 전환 부탁드립니다
> 지표 수식 2개 변환부탁드립니다
감사합니다
study("Volatility Stop", "VStop", overlay=true, resolution="")
length = input(20, "Length", minval = 2)
src = input(close, "Source")
factor = input(2.0, "Multiplier", minval = 0.25, step = 0.25)
Barcolor=input(true)
volStop(src, atrlen, atrfactor) =>
var max = src
var min = src
var uptrend = true
var stop = 0.0
atrM = nz(atr(atrlen) * atrfactor, tr)
max := max(max, src)
min := min(min, src)
stop := nz(uptrend ? max(stop, max - atrM) : min(stop, min + atrM), src)
uptrend := src - stop >= 0.0
if uptrend != nz(uptrend[1], true)
max := src
min := src
stop := uptrend ? max - atrM : min + atrM
[stop, uptrend]
[vStop, uptrend] = volStop(src, length, factor)
plot(vStop, "Volatility Stop", color= uptrend ? #007F0E : #872323,linewidth=2)
colors=iff(close>vStop,#008000,iff(close<vStop,#FF0000,color.black))
barcolor(Barcolor ? colors :na)
Buy=crossover(close,vStop)
Sell=crossunder(close,vStop)
plotshape(Buy,"BUY", shape.labelup, location.belowbar, color.green, text="BUY",textcolor=color.black)
plotshape(Sell,"SELL", shape.labeldown, location.abovebar, color.red, text="SELL",textcolor=color.black)
alertcondition(Buy, "Buy Signal", "Buy ATR Trailing Stop")
alertcondition(Sell, "Sell Signal", "Sell ATR Trailing Stop")
2번째 수식입니다
tudy("Braid Filter")
//-- Inputs
maType = input("EMA", "MA Type", options = ["EMA", "DEMA", "TEMA", "WMA", "VWMA", "SMA", "SMMA", "HMA", "LSMA", "Kijun", "McGinley", "RMA"])
Period1 = input(3, "Period 1")
Period2 = input(7, "Period 2")
Period3 = input(14, "Period 3")
PipsMinSepPercent = input(40)
//-- Moving Average
ma(type, src, len) =>
float result = 0
if type=="SMA" // Simple
result := sma(src, len)
if type=="EMA" // Exponential
result := ema(src, len)
if type=="DEMA" // Double Exponential
e = ema(src, len)
result := 2 * e - ema(e, len)
if type=="TEMA" // Triple Exponential
e = ema(src, len)
result := 3 * (e - ema(e, len)) + ema(ema(e, len), len)
if type=="WMA" // Weighted
result := wma(src, len)
if type=="VWMA" // Volume Weighted
result := vwma(src, len)
if type=="SMMA" // Smoothed
w = wma(src, len)
result := na(w[1]) ? sma(src, len) : (w[1] * (len - 1) + src) / len
if type == "RMA"
result := rma(src, len)
if type=="HMA" // Hull
result := wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))
if type=="LSMA" // Least Squares
result := linreg(src, len, 0)
if type=="Kijun" //Kijun-sen
kijun = avg(lowest(len), highest(len))
result :=kijun
if type=="McGinley"
mg = 0.0
mg := na(mg[1]) ? ema(src, len) : mg[1] + (src - mg[1]) / (len * pow(src/mg[1], 4))
result :=mg
result
//-- Braid Filter
ma01 = ma(maType, close, Period1)
ma02 = ma(maType, open, Period2)
ma03 = ma(maType, close, Period3)
max = max(max(ma01, ma02), ma03)
min = min(min(ma01, ma02), ma03)
dif = max - min
filter = atr(14) * PipsMinSepPercent / 100
//-- Plots
BraidColor = ma01 > ma02 and dif > filter ? color.green : ma02 > ma01 and dif > filter ? color.red : color.gray
plot(dif, "Braid", BraidColor, 5, plot.style_columns)
plot(filter, "Filter", color.blue, 2, plot.style_line)
bgcolor(BraidColor)