예스스탁
예스스탁 답변
2025-06-16 14:29:01
안녕하세요
예스스탁입니다.
input : rsiPeriod1(14);
input : speed1(1.2);
input : rsiPeriod2(34);
input : speed2(0.8);
input : start(0.01);
input : accel(0.01);
input : finish(0.1);
input : signal_ma(2);#1:DEMA, 2:EMA, 3:RMA, 4:SMA, 5:TEMA, 6:TRIMA, 7:VWMA, 8:WMA
input : signalPer(9);
var : R1(0),_maRSI1(0);
var : R2(0),_maRSI2(0);
var : macdHi(0),macdLo(0),macdMid(0),macdv(0),signal(0),alpha(0);
_maRSI1 = 0.0;
R1 = rsi(rsiPeriod1);
if index < rsiPeriod1 Then
_maRSI1 = c;
else
_maRSI1 = _maRSI1[1] + (speed1 * abs(R1/100.0-0.5)) * (close-_maRSI1[1]);
_maRSI2 = 0.0;
R2 = rsi(rsiPeriod2);
if index < rsiPeriod2 Then
_maRSI2 = c;
else
_maRSI2 = _maRSI2[1] + (speed2 * abs(R2/100.0-0.5)) * (close-_maRSI2[1]);
macdHi = _maRSI1 - _maRSI2;
macdLo = _maRSI1 - _maRSI2;
macdMid = (macdHi + macdLo) * 0.5;
macdv = _maRSI1 - _maRSI2;
if signal_ma == 1 Then
signal = ma(macdv, signalPer);
else if signal_ma == 2 Then
signal = ema(macdv, signalPer);
else if signal_ma == 3 Then
signal = 2 * ema(macdv, signalPer) - ema(ema(macdv, signalPer), signalPer) ;
else if signal_ma == 4 Then
signal = 3 * (ema(macdv, signalPer) - ema(ema(macdv, signalPer), signalPer)) + ema(ema(ema(macdv, signalPer), signalPer), signalPer) ;
else if signal_ma == 5 Then
signal = wma(macdv, signalPer);
else if signal_ma == 6 Then
signal = ma(ma(macdv, Ceiling(signalPer / 2)), floor(signalPer / 2) + 1);
else if signal_ma == 7 Then
{
alpha = 1/signalPer;
signal = iff(Isnan(signal[1]) == true , ma(macdv, signalPer) , alpha * macdv + (1 - alpha) * iff(isnan(signal[1]) == true,0,signal[1]));
}
else if signal_ma == 8 Then
{
signal = ma(macdv * volume, signalPer) / ma(volume, signalPer);
}
var : psar(Nan),maxMin(Nan),acceleration(Nan),isBelow(False);
var : isFirstTrendBar(False);
isFirstTrendBar = false;
if index < max(rsiPeriod2, rsiPeriod1) + max(rsiPeriod2, rsiPeriod1) * 0.2 Then
{
if macdv > macdv[1] Then
{
isBelow = true;
maxMin = macdHi;
psar = macdLo[1];
}
else
{
isBelow = false;
maxMin = macdLo;
psar = 0;
}
isFirstTrendBar = true;
acceleration = start;
}
psar = psar + acceleration * (maxMin - psar);
if isBelow then
{
if psar > macdLo Then
{
isFirstTrendBar = true;
isBelow = false;
psar = max(macdHi, maxMin);
maxMin = macdLo;
acceleration = start;
}
}
else
{
if psar < macdHi Then
{
isFirstTrendBar = true;
isBelow = true;
psar = min(macdLo, maxMin);
maxMin = macdHi;
acceleration = start;
}
}
if isFirstTrendBar == false Then
{
if isBelow Then
{
if macdHi > maxMin Then
{
maxMin = macdHi;
acceleration = min(acceleration + accel, finish);
}
}
else
{
if macdLo < maxMin Then
{
maxMin = macdLo;
acceleration = min(acceleration + accel, finish);
}
}
}
if isBelow Then
{
psar = min(psar, macdLo[1]);
if index > 1 then
{
psar = min(psar, macdLo[2]);
}
}
else
{
psar = max(psar, macdHi[1]);
if index > 1 then
{
psar = max(psar, macdHi[2]);
}
}
plot1(0, "Zero line",Gray);
plot2(macdv, "Historgram of MACD");
plot3(psar, "PSAR",iff(psar > signal , Red , Lime));
plot4(signal,"Signal",Black);
var :tx(0);
if psar < signal and psar[1] > signal Then
{
tx = Text_New_Self(sDate,sTime,psar,"●");
Text_SetColor(tx,Green);
Text_SetStyle(tx,2,2);
}
if psar > signal and psar[1] < signal Then
{
tx = Text_New_Self(sDate,sTime,psar,"●");
Text_SetColor(tx,Red);
Text_SetStyle(tx,2,2);
}
즐거운 하루되세요
> 사노소이 님이 쓴 글입니다.
> 제목 : 수식 부탁드립니다
> 지표식 부탁드립니다.
//@version=5
indicator("Parabolic SAR MARSI, Adaptive MACD [Loxx]", shorttitle ="PSAR_MARSI_A_MACD [Loxx]", overlay = false, timeframe="", timeframe_gaps=true)
_maRSI(src, price, rsiperiod, speed) =>
tprice = ta.sma(src, 1)
workMaRsi = 0.0
rsi = ta.rsi(src, rsiperiod)
if bar_index < rsiperiod
workMaRsi := tprice
else
workMaRsi := workMaRsi[1] + (speed * math.abs(rsi/100.0-0.5)) * (tprice-workMaRsi[1])
workMaRsi
variant(type, src, len) =>
sig = 0.0
if type == "SMA"
sig := ta.sma(src, len)
else if type == "EMA"
sig := ta.ema(src, len)
else if type == "DEMA"
sig := 2 * ta.ema(src, len) - ta.ema(ta.ema(src, len), len)
else if type == "TEMA"
sig := 3 * (ta.ema(src, len) - ta.ema(ta.ema(src, len), len)) + ta.ema(ta.ema(ta.ema(src, len), len), len)
else if type == "WMA"
sig := ta.wma(src, len)
else if type == "TRIMA"
sig := ta.sma(ta.sma(src, math.ceil(len / 2)), math.floor(len / 2) + 1)
else if type == "RMA"
sig := ta.rma(src, len)
else if type == "VWMA"
sig := ta.vwma(src, len)
sig
rsiSource = input.source(close, "RSI Source", group = "MARSI MACD")
rsiPeriod1 = input.int(14, "Fast RSI Period", minval = 0, group = "MARSI MACD")
speed1 = input.float(1.2, "Fast MARSI Speed", minval = 0.0, group = "MARSI MACD")
rsiPeriod2 = input.int(34, "Slow RSI Period", minval = 0, group = "MARSI MACD")
speed2 = input.float(0.8, "Slow MARSI Speed", minval = 0.0, group = "MARSI MACD")
start = input.float(0.01, "Start", minval = 0.0, group = "Parabolic SAR")
accel = input.float(0.01, "Acceleration", minval = 0.0, group = "Parabolic SAR")
finish = input.float(0.1, "Maximum", minval = 0.0, group = "Parabolic SAR")
signal_ma = input.string("EMA", title='Signal MA Type', options=["DEMA", "EMA", "RMA", "SMA", "TEMA", "TRIMA", "VWMA", "WMA"], group='MACD')
signalPer = input.int(9,"Signal Period", minval = 0, group = "MACD")
greencolor = #2DD204
redcolor = #D2042D
lightgreencolor = #96E881
lightredcolor = #DF4F6C
darkGreenColor = #1B7E02
darkRedColor = #93021F
psarUp = input(greencolor, "PSAR Uptrend  ", group="Color Settings", inline="MACD")
psarDown = input(redcolor, "PSAR Downtrend  ", group="Color Settings", inline="MACD")
col_signal = input(color.white, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(color.new(lightgreencolor, 60), "Above   Grow", group="Histogram of MACD", inline="Above")
col_fall_above = input(color.new(darkGreenColor, 60), "Fall", group="Histogram of MACD", inline="Above")
col_grow_below = input(color.new(darkRedColor, 60), "Below Grow", group="Histogram of MACD", inline="Below")
col_fall_below = input(color.new(lightredcolor, 60), "Fall", group="Histogram of MACD", inline="Below")
macdHi = _maRSI(rsiSource, high, rsiPeriod1, speed1) - _maRSI(rsiSource, high, rsiPeriod2, speed2)
macdLo = _maRSI(rsiSource, low, rsiPeriod1, speed1) - _maRSI(rsiSource, low, rsiPeriod2, speed2)
macdMid = (macdHi + macdLo) * 0.5
macd = _maRSI(rsiSource, macdMid, rsiPeriod1, speed1) - _maRSI(rsiSource, macdMid, rsiPeriod2, speed2)
signal= variant(signal_ma, macd, signalPer)
pine_sar(start, inc, max, cutoff, _high, _low, _close) =>
var float result = na
var float maxMin = na
var float acceleration = na
var bool isBelow = na
bool isFirstTrendBar = false
if bar_index < cutoff + cutoff * 0.2
if _close > _close[1]
isBelow := true
maxMin := _high
result := _low[1]
else
isBelow := false
maxMin := _low
result := 0
isFirstTrendBar := true
acceleration := start
result := result + acceleration * (maxMin - result)
if isBelow
if result > _low
isFirstTrendBar := true
isBelow := false
result := math.max(_high, maxMin)
maxMin := _low
acceleration := start
else
if result < _high
isFirstTrendBar := true
isBelow := true
result := math.min(_low, maxMin)
maxMin := _high
acceleration := start
if not isFirstTrendBar
if isBelow
if _high > maxMin
maxMin := _high
acceleration := math.min(acceleration + inc, max)
else
if _low < maxMin
maxMin := _low
acceleration := math.min(acceleration + inc, max)
if isBelow
result := math.min(result, _low[1])
if bar_index > 1
result := math.min(result, _low[2])
else
result := math.max(result, _high[1])
if bar_index > 1
result := math.max(result, _high[2])
result
sar = pine_sar(start, accel, finish, math.max(rsiPeriod2, rsiPeriod1), macdHi, macdLo, macd)
plot(0, "Zero line", style = plot.style_circles, color = color.gray)
plot(macd, "Historgram of MACD", style=plot.style_columns, color=(macd>=0 ? (macd[1] < macd ? col_grow_above : col_fall_above) : (macd[1] < macd ? col_grow_below : col_fall_below)))
plot(sar, "PSAR", style=plot.style_cross, linewidth=1, color = sar > signal ? psarDown : psarUp)
plot(signal,"Signal", linewidth=1, color = col_signal)
plotshape(sar < signal and sar[1] > signal ? sar : na, title='PSAR Long Start', location=location.absolute, style=shape.circle, size=size.tiny, color=greencolor)
plotshape(sar > signal and sar[1] < signal ? sar : na, title='PSAR Long Start', location=location.absolute, style=shape.circle, size=size.tiny, color=redcolor)