NQ ATR Multiples

integrale42 · study · 32 行 · 点赞 33 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("NQ ATR Multiples", overlay = true, precision = 2)
 
int    atrPeriod = input.int(14, "ATR period", minval = 1)
string atrTF     = input.timeframe("", "ATR timeframe (empty = chart)")
 
float mult1 = input.float(1.5, "Mult 1", step = 0.1)
float mult2 = input.float(2.5, "Mult 2", step = 0.1)
float mult3 = input.float(3.0, "Mult 3", step = 0.1)
 
float atrPts = atrTF == "" ? ta.atr(atrPeriod) : request.security(syminfo.tickerid, atrTF, ta.atr(atrPeriod), lookahead = barmerge.lookahead_off)
 
float pts1 = atrPts * mult1
float pct1 = pts1 / close * 100.0
 
float pts2 = atrPts * mult2
float pct2 = pts2 / close * 100.0
 
float pts3 = atrPts * mult3
float pct3 = pts3 / close * 100.0
 
var table t = table.new(position.top_right, 2, 3, bgcolor = color.new(#0f0f0f, 8), border_width = 1, border_color = color.new(color.gray, 55), frame_color = color.new(color.gray, 55), frame_width = 1)
 
if barstate.islast
    table.cell(t, 0, 0, str.tostring(mult1, "0.#") + "x ATR", text_color = color.orange, text_halign = text.align_left, text_size = size.normal)
    table.cell(t, 1, 0, na(pts1) ? "-" : str.tostring(pts1, "#.#") + " pts   " + str.tostring(pct1, "0.000") + "%", text_color = color.orange, text_halign = text.align_right, text_size = size.normal)
 
    table.cell(t, 0, 1, str.tostring(mult2, "0.#") + "x ATR", text_color = color.orange, text_halign = text.align_left, text_size = size.normal)
    table.cell(t, 1, 1, na(pts2) ? "-" : str.tostring(pts2, "#.#") + " pts   " + str.tostring(pct2, "0.000") + "%", text_color = color.orange, text_halign = text.align_right, text_size = size.normal)
 
    table.cell(t, 0, 2, str.tostring(mult3, "0.#") + "x ATR", text_color = color.orange, text_halign = text.align_left, text_size = size.normal)
    table.cell(t, 1, 2, na(pts3) ? "-" : str.tostring(pts3, "#.#") + " pts   " + str.tostring(pct3, "0.000") + "%", text_color = color.orange, text_halign = text.align_right, text_size = size.normal)

← 返回列表