本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("The Engine Zones", overlay = true, max_boxes_count = 100, max_labels_count = 100)
// Paste the code from the Engine app (Zone Matrix > TradingView). Paste a fresh code whenever the zones update.
code = input.text_area("", "Engine Code", tooltip = "In the Engine app, open Zone Matrix and tap TradingView. Paste the copied code here.")
showB = input.bool(true, "Show B Zones")
showLbl = input.bool(true, "Show Labels")
extBars = input.int(20, "Extend Right (Bars)", minval = 0, maxval = 500)
colShort = input.color(color.new(#E5383B, 80), "Short Zone")
colLong = input.color(color.new(#2F80ED, 80), "Long Zone")
colGold = input.color(color.new(#E0A800, 72), "Gold Zone (A+)")
txtSize = input.string(size.small, "Label Size", options = [size.tiny, size.small, size.normal])
var array<box> boxes = array.new<box>()
var array<label> labels = array.new<label>()
gradeName(g) => g == 3 ? "A+" : g == 2 ? "A" : "B"
if barstate.islast
for b in boxes
b.delete()
for l in labels
l.delete()
boxes.clear()
labels.clear()
body = str.startswith(code, "ENG1|") ? str.substring(code, 5) : ""
if str.length(body) == 0
labels.push(label.new(bar_index, high, "Paste Your Engine Code In The Indicator Settings", style = label.style_label_down, color = color.new(#E5383B, 0), textcolor = color.white, size = size.normal))
else
for item in str.split(body, ";")
f = str.split(item, ",")
if f.size() == 4
lo = str.tonumber(f.get(0))
hi = str.tonumber(f.get(1))
g = int(str.tonumber(f.get(2)))
side = f.get(3)
if not na(lo) and not na(hi) and (showB or g >= 2)
fillC = g == 3 ? colGold : side == "S" ? colShort : colLong
lineC = color.new(fillC, 0)
x1 = bar_index - 300
x2 = bar_index + extBars
boxes.push(box.new(x1, hi, x2, lo, border_color = lineC, border_width = g == 3 ? 2 : 1, bgcolor = fillC, extend = extend.right))
if showLbl
labels.push(label.new(bar_index + 2, hi, gradeName(g) + " " + (side == "S" ? "Short" : "Long") + " " + str.tostring(lo, "#,###.##") + " - " + str.tostring(hi, "#,###.##"), style = label.style_label_lower_left, color = color.new(color.black, 100), textcolor = lineC, size = txtSize))