예스스탁
예스스탁 답변
2021-04-27 15:42:03
안녕하세요
예스스탁입니다.
올리신 내용은 변환에 시간이 많이 소모가 됩니다.
해당수식에 security함수는 특히 변환에 시간이 많이 걸리는 내용입니다.
업무상 많은 시간이 요구되는 수식은 저희가 답변을 해드리기 어렵습니다.
도움을 드리지 못해 죄송합니다.
즐거운 하루되세요
> dandan 님이 쓴 글입니다.
> 제목 : 수식변경 부탁드립니다.
> 아래 TradingView 수식(SuperTrend MTF Heikin Ashi) 변경부탁드립니다.
1. 지표와 전략 두개로 작성 부탁드립니다. 함수로 작성하여 분리해주셔도 감사하겠습니다.
매매기준은 다음과 같습니다.
매수 : TimeFrame이 높은 것이 상승중일때, TimeFrame낮은것이 상승전환 시 매수
매도 : TimeFrame이 높은 것이 하락중일때, TimeFrame낮은것이 하락전환 시 매도
2. 지표에서 지정되는 High TimeFrame 은 굳이 Auto로 안해주셔도 되며, 직접 지정할 수 있었으면 좋겠습니다.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue
//
// Author : LonesomeTheBlue
//
//@version=4
study("Supertrend MTF Heikin Ashi", overlay = true)
mode =input(title = "HTF Method", defval = 'Auto', options=['Auto', 'User Defined'])
//auto higher time frame
HTFo =timeframe.period == '1' ? '5' :
timeframe.period == '3' ? '15' :
timeframe.period == '5' ? '15' :
timeframe.period == '15' ? '60' :
timeframe.period == '30' ? '120' :
timeframe.period == '45' ? '120' :
timeframe.period == '60' ? '240' :
timeframe.period == '120' ? '240' :
timeframe.period == '180' ? '240' :
timeframe.period == '240' ? 'D' :
timeframe.period == 'D' ? 'W' :
'5W'
HTFm = input('5', title = "Time Frame (if HTF Method=User Defined)", type=input.resolution)
HTF = mode == 'Auto' ? HTFo : HTFm
Mult = input(defval = 2.0, title = "ATR Factor", minval = 0.5, maxval = 100, step = 0.1)
Period = input(defval = 7, title = "ATR Period", minval = 1,maxval = 100)
// current time frame
//Heikin Ashi high, low, close
h = security(heikinashi(syminfo.tickerid), timeframe.period, high)
l = security(heikinashi(syminfo.tickerid), timeframe.period, low)
c = security(heikinashi(syminfo.tickerid), timeframe.period, close)
//HeikinAshi atr
Atr = security(heikinashi(syminfo.tickerid), timeframe.period, atr(Period))
Up = (h + l) / 2 - (Mult * Atr)
Dn = (h + l) / 2 + (Mult * Atr)
float TUp = na
float TDown = na
Trend = 0
TUp := c[1] > TUp[1] ? max(Up,TUp[1]) : Up
TDown := c[1] < TDown[1] ? min(Dn,TDown[1]) : Dn
Trend := c > TDown[1] ? 1: c < TUp[1]? -1: nz(Trend[1],1)
Trailingsl = Trend == 1 ? TUp : TDown
linecolor = Trend == 1 and nz(Trend[1]) == 1 ? color.lime : Trend == -1 and nz(Trend[1]) == -1 ? color.red : na
plot(Trailingsl, color = linecolor , linewidth = 2, title = "SuperTrend")
// Higher Time Frame
////// HTF high, low, close
highhtf = security(heikinashi(syminfo.tickerid), HTF, high[1], lookahead = barmerge.lookahead_on)
lowhtf = security(heikinashi(syminfo.tickerid), HTF, low[1], lookahead = barmerge.lookahead_on)
closehtf = security(heikinashi(syminfo.tickerid), HTF, close[1], lookahead = barmerge.lookahead_on)
// ATR for HTF
HTfatr = security(heikinashi(syminfo.tickerid), HTF, atr(Period)[1], lookahead = barmerge.lookahead_on)
Uphtf = abs(highhtf + lowhtf) / 2 - (Mult * HTfatr)
Dnhtf = abs(highhtf + lowhtf) / 2 + (Mult * HTfatr)
float TUphtf = na
float TDownhtf = na
TrendHtf = 0
TUphtf := closehtf[1] > TUphtf[1] ? max(Uphtf, TUphtf[1]) : Uphtf
TDownhtf := closehtf[1] < TDownhtf[1] ? min(Dnhtf,TDownhtf[1]) : Dnhtf
TrendHtf := closehtf > TDownhtf[1] ? 1 : closehtf < TUphtf[1] ? -1: nz(TrendHtf[1], 1)
TrailingslHtf = TrendHtf == 1 ? TUphtf : TDownhtf
linecolorHtf = TrendHtf == 1 and nz(TrendHtf[1]) == 1 ? color.blue : TrendHtf == -1 and nz(TrendHtf[1]) == -1 ? color.red : na
st = plot(TrailingslHtf, color = linecolorHtf , linewidth = 3, title = "Supertrend HTF", transp = 0)
plot(TrendHtf == 1 and TrendHtf[1] == -1 ? TrailingslHtf : na, title="Supertrend HTF Trend Up", linewidth = 4, color=color.blue, transp=0, style = plot.style_circles)
plot(TrendHtf == -1 and TrendHtf[1] == 1 ? TrailingslHtf : na, title="Supertrend HTF Trend Down", linewidth = 4, color=color.red, transp=0, style = plot.style_circles)
//Alerts
alertcondition(Trend == 1 and Trend[1] == -1, title='Supertrend Trend Up', message='Supertrend Trend Up')
alertcondition(Trend == -1 and Trend[1] == 1, title='Supertrend Trend Down', message='Supertrend Trend Down')
alertcondition(TrendHtf == 1 and TrendHtf[1] == -1, title='Supertrend HTF Trend Up', message='Supertrend HTF Trend Upl')
alertcondition(TrendHtf == -1 and TrendHtf[1] == 1, title='Supertrend HTF Trend Down', message='Supertrend HTF Trend Down')