커뮤니티

문의드립니다.

프로필 이미지
로즈버드
2020-04-06 19:40:07
514
글번호 137586
답변완료
//@version=4 study(BB MACD) inp_Source = input(title = "Source", type = input.source, defval = close) inp_Sensitivity = input(title = "Sensitivity", type = input.float, defval = 0.01) inp_HiLo_Lookback = input(title = "Hi/Lo Lookback", type = input.integer, defval = 5) inp_Slow_MA_Period = input(title = "Slow MA: Period", type = input.integer, defval = 26) inp_Slow_MA_Method = input(title = "Slow MA: Type", defval = 'EMA', options = ['SMA', 'EMA', 'LWMA', 'RMA']) inp_Fast_MA_Period = input(title = "Fast MA: Period", type = input.integer, defval = 12) inp_Fast_MA_Method = input(title = "Fast MA: Type", defval = 'EMA', options = ['SMA', 'EMA', 'LWMA', 'RMA']) inp_Signal_MA_Period = input(title = "Signal MA: Period", type = input.integer, defval = 9) inp_Signal_MA_Method = input(title = "Signal MA: Type", defval = 'SMA', options = ['SMA', 'EMA', 'WMA', 'RMA']) f_Get_MA(MA_Type, MA_Source, MA_Period) => MA = 0.0 MA := MA_Type == 'SMA' ? sma(MA_Source, MA_Period) : MA_Type == 'EMA' ? ema(MA_Source, MA_Period) : MA_Type == 'WMA' ? wma(MA_Source, MA_Period) : MA_Type == 'RMA' ? rma(MA_Source, MA_Period) : na MA f_Get_Std_Dev(MA_Type, MA_Source, MA_Period) => MA = 0.0 MA := f_Get_MA(MA_Type, MA_Source, MA_Period) Price = 0.0 Price := sma(MA_Source, 1) Summation = 0.0 for i = 0 to MA_Period - 1 Summation := Summation + (Price[i] - MA) * (Price[i] - MA) Std_Dev = 0.0 Std_Dev := sqrt(Summation / MA_Period) Std_Dev f_Get_TR() => TR = max(high, close[1]) - min(low, close[1]) TR f_Get_ATR(Period) => TR = f_Get_TR() Summation = 0.0 for i = 1 to Period Summation := Summation + TR[i] ATR = 0.0 ATR := Summation / Period ATR MA_Fast = f_Get_MA(inp_Fast_MA_Method, inp_Source, inp_Fast_MA_Period) HiLo_Range = abs(barssince(high == highest(high, inp_HiLo_Lookback)) - barssince(low == lowest(low, inp_HiLo_Lookback))) * syminfo.mintick * 100000 MA_Slow = f_Get_MA(inp_Slow_MA_Method, inp_Source, inp_Slow_MA_Period) MA_Slow_Deviation = f_Get_Std_Dev(inp_Slow_MA_Method, inp_Source, inp_Slow_MA_Period) MA_Slow_ATR = f_Get_ATR(inp_Slow_MA_Period) Histogrm = MA_Slow_Deviation - MA_Slow_ATR Main_Line = Histogrm Signal_Line = f_Get_MA(inp_Signal_MA_Method, Main_Line, inp_Signal_MA_Period) Histogrm_Color = color.green if MA_Fast >= MA_Fast[1] if HiLo_Range >= inp_Sensitivity Histogrm_Color := color.green else Histogrm_Color := color.yellow else if HiLo_Range >= inp_Sensitivity Histogrm_Color := color.red else Histogrm_Color := color.blue plot(Histogrm, title = "BB MACD", color = Histogrm_Color, style = plot.style_histogram) plot(Histogrm, title = "BB MACD", color = color.blue, style = plot.style_line) -------------------------------------------------------------------- Slow MA, Fast MA Method에서 type은 EMA로, Signal MA Method에서 type은 SMA로 부탁드립니다. 그리고 f_Get_MA(MA_Type, MA_Source, MA_Period) => MA = 0.0 MA := MA_Type == 'SMA' ? sma(MA_Source, MA_Period) : MA_Type == 'EMA' ? ema(MA_Source, MA_Period) : MA_Type == 'WMA' ? wma(MA_Source, MA_Period) : MA_Type == 'RMA' ? rma(MA_Source, MA_Period) : na MA 에서 SMA와 EMA만 남겨주실수 있을지 수식에서 적용되는 MA가 SMA와 EMA만 적용될 수 있었으면 좋겠습니다. 항상 감사합니다.
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2020-04-07 09:42:26

안녕하세요 예스스탁입니다. input : inp_Sensitivity(0.01),inp_HiLo_Lookback(5), inp_Slow_MA_Period(26),inp_Slow_MA_Method("EMA"), inp_Fast_MA_Period(12),inp_Fast_MA_Method("EMA"), inp_Signal_MA_Period(9),inp_Signal_MA_Method("EMA"); var : inp_Source(0),Hbarssince(-1),Lbarssince(-1),HiLo_Range(0),MA_Slow_Deviation(0); var : MA_Fast(0),MA_Slow(0),MA_Slow_ATR(0); Var : SumSqrt(0), Avgv(0), cnt(0),Histogrm(0),Main_Line(0),Signal_Line(0),Histogrm_Color(0); inp_Source = close; if inp_Fast_MA_Method == "SMA" Then MA_Fast = ma(inp_Source, inp_Fast_MA_Period); Else MA_Fast = ema(inp_Source, inp_Fast_MA_Period); if High == highest(H,inp_HiLo_Lookback) Then Hbarssince = 0; Else { if Hbarssince >= 0 Then Hbarssince = Hbarssince+1; } if low == Lowest(L,inp_HiLo_Lookback) Then Lbarssince = 0; Else { if Lbarssince >= 0 Then Lbarssince = Lbarssince+1; } HiLo_Range = abs(Hbarssince-Lbarssince) * PriceScale * 100000; if inp_Slow_MA_Method == "SMA" Then MA_Slow = ma(inp_Source, inp_Slow_MA_Period); Else MA_Slow = ema(inp_Source, inp_Slow_MA_Period); If inp_Slow_MA_Period != 0 Then { Avgv = MA_Slow; SumSqrt = 0; For cnt = 0 To inp_Slow_MA_Period - 1 Begin SumSqrt = SumSqrt + (C[cnt] - Avgv) * (C[cnt] - Avgv); End; MA_Slow_Deviation = SquareRoot(SumSqrt / inp_Slow_MA_Period); } Else MA_Slow_Deviation = 0; MA_Slow_ATR = atr(inp_Slow_MA_Period); Histogrm = MA_Slow_Deviation - MA_Slow_ATR; Main_Line = Histogrm; if inp_Signal_MA_Method == "SMA" Then Signal_Line = ma(inp_Source, inp_Signal_MA_Period); Else Signal_Line = ema(inp_Source, inp_Signal_MA_Period); Histogrm_Color = green; if MA_Fast >= MA_Fast[1] then { if HiLo_Range >= inp_Sensitivity then Histogrm_Color = green; else Histogrm_Color = yellow; } else { if HiLo_Range >= inp_Sensitivity Then Histogrm_Color = red; else Histogrm_Color = blue; } plot1(Histogrm,"BBMACD막대", Histogrm_Color);//속성에서 막대 plot2(Histogrm,"BBMACD선", blue); 즐거운 하루되세요 > 로즈버드 님이 쓴 글입니다. > 제목 : 문의드립니다. > //@version=4 study(BB MACD) inp_Source = input(title = "Source", type = input.source, defval = close) inp_Sensitivity = input(title = "Sensitivity", type = input.float, defval = 0.01) inp_HiLo_Lookback = input(title = "Hi/Lo Lookback", type = input.integer, defval = 5) inp_Slow_MA_Period = input(title = "Slow MA: Period", type = input.integer, defval = 26) inp_Slow_MA_Method = input(title = "Slow MA: Type", defval = 'EMA', options = ['SMA', 'EMA', 'LWMA', 'RMA']) inp_Fast_MA_Period = input(title = "Fast MA: Period", type = input.integer, defval = 12) inp_Fast_MA_Method = input(title = "Fast MA: Type", defval = 'EMA', options = ['SMA', 'EMA', 'LWMA', 'RMA']) inp_Signal_MA_Period = input(title = "Signal MA: Period", type = input.integer, defval = 9) inp_Signal_MA_Method = input(title = "Signal MA: Type", defval = 'SMA', options = ['SMA', 'EMA', 'WMA', 'RMA']) f_Get_MA(MA_Type, MA_Source, MA_Period) => MA = 0.0 MA := MA_Type == 'SMA' ? sma(MA_Source, MA_Period) : MA_Type == 'EMA' ? ema(MA_Source, MA_Period) : MA_Type == 'WMA' ? wma(MA_Source, MA_Period) : MA_Type == 'RMA' ? rma(MA_Source, MA_Period) : na MA f_Get_Std_Dev(MA_Type, MA_Source, MA_Period) => MA = 0.0 MA := f_Get_MA(MA_Type, MA_Source, MA_Period) Price = 0.0 Price := sma(MA_Source, 1) Summation = 0.0 for i = 0 to MA_Period - 1 Summation := Summation + (Price[i] - MA) * (Price[i] - MA) Std_Dev = 0.0 Std_Dev := sqrt(Summation / MA_Period) Std_Dev f_Get_TR() => TR = max(high, close[1]) - min(low, close[1]) TR f_Get_ATR(Period) => TR = f_Get_TR() Summation = 0.0 for i = 1 to Period Summation := Summation + TR[i] ATR = 0.0 ATR := Summation / Period ATR MA_Fast = f_Get_MA(inp_Fast_MA_Method, inp_Source, inp_Fast_MA_Period) HiLo_Range = abs(barssince(high == highest(high, inp_HiLo_Lookback)) - barssince(low == lowest(low, inp_HiLo_Lookback))) * syminfo.mintick * 100000 MA_Slow = f_Get_MA(inp_Slow_MA_Method, inp_Source, inp_Slow_MA_Period) MA_Slow_Deviation = f_Get_Std_Dev(inp_Slow_MA_Method, inp_Source, inp_Slow_MA_Period) MA_Slow_ATR = f_Get_ATR(inp_Slow_MA_Period) Histogrm = MA_Slow_Deviation - MA_Slow_ATR Main_Line = Histogrm Signal_Line = f_Get_MA(inp_Signal_MA_Method, Main_Line, inp_Signal_MA_Period) Histogrm_Color = color.green if MA_Fast >= MA_Fast[1] if HiLo_Range >= inp_Sensitivity Histogrm_Color := color.green else Histogrm_Color := color.yellow else if HiLo_Range >= inp_Sensitivity Histogrm_Color := color.red else Histogrm_Color := color.blue plot(Histogrm, title = "BB MACD", color = Histogrm_Color, style = plot.style_histogram) plot(Histogrm, title = "BB MACD", color = color.blue, style = plot.style_line) -------------------------------------------------------------------- Slow MA, Fast MA Method에서 type은 EMA로, Signal MA Method에서 type은 SMA로 부탁드립니다. 그리고 f_Get_MA(MA_Type, MA_Source, MA_Period) => MA = 0.0 MA := MA_Type == 'SMA' ? sma(MA_Source, MA_Period) : MA_Type == 'EMA' ? ema(MA_Source, MA_Period) : MA_Type == 'WMA' ? wma(MA_Source, MA_Period) : MA_Type == 'RMA' ? rma(MA_Source, MA_Period) : na MA 에서 SMA와 EMA만 남겨주실수 있을지 수식에서 적용되는 MA가 SMA와 EMA만 적용될 수 있었으면 좋겠습니다. 항상 감사합니다.