예스스탁
예스스탁 답변
2024-05-13 15:35:30
안녕하세요
예스스탁입니다.
올려주신 수식은 타주기(60분봉) MACD를 그리는 식입니다.
시그널값은 기본제공되는 MACD는 지수이평인데 해당식에서는 단순이평이 사용되어 있습니다.
input : resCustom(60);
input : fastLength(12),slowLength(26),signalLength(9);
var : S1(0),D1(0),TM(0),TF(0),ii(0),EP1(0),EP2(0),EP3(0);
var : fastMA(0),fastMA1(0),slowMA(0),slowMA1(0);
var : Signal(0),cnt(0),sum(0),outMacD(0),outSignal(0),outHist(0);
var : histA_IsUp(False),histA_IsDown(False),histB_IsDown(False),histB_IsUp(False);
var : plot_color(0),macd_color(0),signal_color(0);
var : macd_IsAbove(False),macd_IsBelow(False),tx(0);
Array : macdv[100](0);
Ep1 = 2/(fastLength+1);
Ep2 = 2/(slowLength+1);
Ep3 = 2/(signalLength+1);
if Bdate != Bdate[1] Then
{
S1 = TimeToMinutes(stime);
D1 = sdate;
}
if D1 > 0 then
{
if sdate == D1 Then
TM = TimeToMinutes(stime)-S1;
Else
TM = TimeToMinutes(stime)+1440-S1;
TF = TM%resCustom;
if Bdate != Bdate[1] or
(Bdate == Bdate[1] and resCustom > 1 and TF < TF[1]) or
(Bdate == Bdate[1] and resCustom > 1 and TM >= TM[1]+resCustom) or
(Bdate == Bdate[1] and resCustom == 1 and TM > TM[1]) Then
{
ii = ii + 1;
fastMA1 = fastMA[1];
slowMA1 = slowMA[1];
For cnt = 99 downto 1
{
MACDV[cnt] = MACDV[cnt-1];
}
}
if ii <= 1 then
{
fastMA = C;
slowMA = C;
MACDV[0] = fastMA-slowMA;
}
else
{
fastMA = C * EP1 + fastMA1 * (1-EP1);
slowMA = C * EP2 + slowMA1 * (1-EP2);
MACDV[0] = fastMA-slowMA;
}
if ii >= signalLength Then
{
sum = 0;
For cnt = 0 to signalLength-1
{
sum = sum + MACDV[cnt];
}
signal = sum/signalLength;
outMacD = macdv[0];
outSignal = signal;
outHist =outMacD-outSignal;
histA_IsUp = outHist > outHist[1] and outHist > 0;
histA_IsDown = outHist < outHist[1] and outHist > 0;
histB_IsDown = outHist < outHist[1] and outHist <= 0;
histB_IsUp = outHist > outHist[1] and outHist <= 0;
//MacD Color Definitions
macd_IsAbove = outMacD >= outSignal;
macd_IsBelow = outMacD < outSignal;
plot_color = iff(histA_IsUp , Cyan, IFf(histA_IsDown , blue , iff(histB_IsDown , red , iff(histB_IsUp , maroon ,yellow))));
macd_color = iff(macd_IsAbove , lime , red);
signal_color = IFF(macd_IsAbove , yellow , yellow);
plot1(outMacD,"MACD",macd_color);
plot2(outSignal,"Signal Line",signal_color);
plot3(outHist,"Histogram",plot_color);
PlotBaseLine1(0, "0 Line",white);
if CrossUp(outMacD,outSignal) or CrossDown(outMacD,outSignal) Then
tx = text_new(sDate,sTime,outSignal,"Cross");
}
}
즐거운 하루되세요
> cooparoo 님이 쓴 글입니다.
> 제목 : 수식 변환 부탁 드립니다.
> 안녕하세요!
다음 파인스크립트 수식을 예스로 변환 부탁드립니다.
감사합니다.
source = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="60")
smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
sh = input(true, title="Show Histogram?")
macd_colorChange = input(true,title="Change MacD Line Color-Signal Line Cross?")
hist_colorChange = input(true,title="MacD Histogram 4 Colors?")
res = useCurrentRes ? period : resCustom
fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(9,minval=1)
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)
macd = fastMA - slowMA
signal = sma(macd, signalLength)
hist = macd - signal
outMacD = security(tickerid, res, macd)
outSignal = security(tickerid, res, signal)
outHist = security(tickerid, res, hist)
histA_IsUp = outHist > outHist[1] and outHist > 0
histA_IsDown = outHist < outHist[1] and outHist > 0
histB_IsDown = outHist < outHist[1] and outHist <= 0
histB_IsUp = outHist > outHist[1] and outHist <= 0
//MacD Color Definitions
macd_IsAbove = outMacD >= outSignal
macd_IsBelow = outMacD < outSignal
plot_color = hist_colorChange ? histA_IsUp ? aqua : histA_IsDown ? blue : histB_IsDown ? red : histB_IsUp ? maroon :yellow :gray
macd_color = macd_colorChange ? macd_IsAbove ? lime : red : red
signal_color = macd_colorChange ? macd_IsAbove ? yellow : yellow : lime
circleYPosition = outSignal
plot(smd and outMacD ? outMacD : na, title="MACD", color=macd_color, linewidth=4)
plot(smd and outSignal ? outSignal : na, title="Signal Line", color=signal_color, style=line ,linewidth=2)
plot(sh and outHist ? outHist : na, title="Histogram", color=plot_color, style=histogram, linewidth=4)
plot(sd and cross(outMacD, outSignal) ? circleYPosition : na, title="Cross", style=circles, linewidth=4, color=macd_color)
hline(0, '0 Line', linestyle=solid, linewidth=2, color=white)