예스스탁
예스스탁 답변
2021-04-27 15:44:29
안녕하세요
예스스탁입니다.
올리신 내용은 변환에 시간이 많이 소모가 됩니다.
해당수식에 security함수는 특히 변환에 시간이 많이 걸리는 내용입니다.
업무상 많은 시간이 요구되는 수식은 저희가 답변을 해드리기 어렵습니다.
도움을 드리지 못해 죄송합니다.
즐거운 하루되세요
> dandan 님이 쓴 글입니다.
> 제목 : 수식변경 부탁드립니다.
>
아래 트레이딩뷰 지표(SuperTrend MTF Headtmap) 수식변경 부탁드립니다.
1. 지표와 전략 두개로 작성 부탁드립니다. 함수로 작성하여 분리해주셔도 감사하겠습니다.
총 4개 주기를 각각 지정가능했으면 좋겠고, 긴 주기 2개가 상승추세일때 아래주기 두개가 하락>상승추세로 바뀔경우 매수, 반대의 경우 매도입니다.
2. 추세색상(형광, 빨강) 이외에 추세전환전 옅게 색칠되는 부분이 잘 보였으면 좋겠습니다.
//@version=4
study("Supertrend MTF Heatmap", shorttitle="Supertrend MTF Heatmap", overlay=false, precision=6)
Factor=input(3,title="[SUPERTREND] Factor", minval=1,maxval = 100, type=input.float)
Pd=input(7, title="[SUPERTREND] PD", minval=1,maxval = 100)
res1 = input("60", type=input.resolution, title="First Timeframe")
res2 = input("120", type=input.resolution, title="Second Timeframe")
res3 = input("240", type=input.resolution, title="Third Timeframe")
res4 = input("D", type=input.resolution, title="Fourth Timeframe")
res5 = input("W", type=input.resolution, title="Fifth Timeframe")
Supertrend(Factor, Pd) =>
Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
TrendUp = 0.0
TrendUp := close[1]>TrendUp[1] ? max(Up,TrendUp[1]) : Up
TrendDown = 0.0
TrendDown := close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend = 0.0
Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown
S_Buy = Trend == 1 ? 1 : 0
S_Sell = Trend != 1 ? 1 : 0
[Trend, Tsl]
[Trend,Tsl] = Supertrend(Factor, Pd)
// Security
ST1_Trend_MTF = security(syminfo.tickerid, res1, Trend[1], lookahead=barmerge.lookahead_on)
ST2_Trend_MTF = security(syminfo.tickerid, res2, Trend[1], lookahead=barmerge.lookahead_on)
ST3_Trend_MTF = security(syminfo.tickerid, res3, Trend[1], lookahead=barmerge.lookahead_on)
ST4_Trend_MTF = security(syminfo.tickerid, res4, Trend[1], lookahead=barmerge.lookahead_on)
ST5_Trend_MTF = security(syminfo.tickerid, res5, Trend[1], lookahead=barmerge.lookahead_on)
h0 = hline(1, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h1 = hline(2, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h2 = hline(3, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h3 = hline(4, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h4 = hline(5, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
h5 = hline(6, color=color.new(color.black, 10), linewidth=2, linestyle=hline.style_solid)
get_bars(Trend)=>
since_st_buy = barssince(Trend == 1)
since_st_sell = barssince(Trend == -1)
[since_st_buy, since_st_sell]
[since_st_1_buy, since_st_1_sell] = get_bars(ST1_Trend_MTF)
[since_st_2_buy, since_st_2_sell] = get_bars(ST2_Trend_MTF)
[since_st_3_buy, since_st_3_sell] = get_bars(ST3_Trend_MTF)
[since_st_4_buy, since_st_4_sell] = get_bars(ST4_Trend_MTF)
[since_st_5_buy, since_st_5_sell] = get_bars(ST5_Trend_MTF)
// selec the right heatmsap color
heatmap_color(cond1, cond2) =>
cond1 ? color.new(color.green, 20) : cond2 ? color.new(color.red, 20) : na
lapos_x = timenow + round(change(time)*3)
lapos_y = highest(5)// + (0.15 * highest(20))
// Displays the timeframe labels at the right
f_draw_label(x,y,_text,_textcolor, _size)=>
var label Label = na
label.delete(Label)
Label := label.new(x, y, _text, color=color.new(color.white, 20), textcolor=_textcolor, style=label.style_none, yloc=yloc.price, xloc=xloc.bar_time, size=_size)
// Display the labels in a more readable way
// If timeframe seleced is "Same as symbol" displays the timeframe.period string value
res_to_string(res)=>
str = iff(res == "1", "m1", iff(res == "5", "m5", iff(res == "15", "m15", iff(res == "30", "m30", iff(res == "60", "H1", iff(res == "120", "H2",
iff(res == "240", "H4", iff(res == "480", "H8", iff(res == "D", "Daily", iff(res == "W", "Weekly", iff(res == "360", "H3", timeframe.period)))))))))))
str
// draw the TF labels
f_draw_label(lapos_x, 1, res_to_string(res1), color.black, size.large)
f_draw_label(lapos_x, 2, res_to_string(res2), color.black, size.large)
f_draw_label(lapos_x, 3, res_to_string(res3), color.black, size.large)
f_draw_label(lapos_x, 4, res_to_string(res4), color.black, size.large)
f_draw_label(lapos_x, 5, res_to_string(res5), color.black, size.large)
// Draw the green/red heatmap raws
fill(h0 ,h1, color=heatmap_color(since_st_1_sell>since_st_1_buy, since_st_1_sell<since_st_1_buy))
fill(h1, h2, color=heatmap_color(since_st_2_sell>since_st_2_buy, since_st_2_sell<since_st_2_buy))
fill(h2, h3, color=heatmap_color(since_st_3_sell>since_st_3_buy, since_st_3_sell<since_st_3_buy))
fill(h3, h4, color=heatmap_color(since_st_4_sell>since_st_4_buy, since_st_4_sell<since_st_4_buy))
fill(h4, h5, color=heatmap_color(since_st_5_sell>since_st_5_buy, since_st_5_sell<since_st_5_buy))