修改设置和实际图标时间周期对应问题,修改字体normal
This commit is contained in:
+88
-23
@@ -4,7 +4,7 @@ indicator("EMA52横线版", overlay=true, max_labels_count=500, max_lines_count=
|
||||
// ============ 输入 ============
|
||||
enableHTF = input.bool(true, "启用长级别", group="显示")
|
||||
enableLTF = input.bool(true, "启用次级别", group="显示")
|
||||
maxHTFInput = input.int(10, "最多显示长级别数量", minval=1, maxval=12, group="显示")
|
||||
maxHTFInput = input.int(10, "最多显示长级别数量", minval=1, maxval=13, group="显示")
|
||||
maxLTFInput = input.int(3, "最多显示次级别数量", minval=1, maxval=4, group="显示")
|
||||
includeSeconds = input.bool(false, "包含秒级别(需高级套餐)", group="显示")
|
||||
protectAutoscale = input.bool(true, "防拉伸: 仅在可视区间内显示", group="显示")
|
||||
@@ -12,7 +12,7 @@ lookbackBars = input.int(300, "可视区间近多少根K线", minval=50,
|
||||
padPercent = input.float(2.0, "可视边界留白(%)", minval=0.0, maxval=20.0, step=0.1, group="显示")
|
||||
|
||||
labelBgAlpha = input.int(85, "标签背景透明(0-100)", minval=0, maxval=100, group="标注")
|
||||
labelSize = input.string("tiny", "标签字号", options=["tiny","small","normal","large","huge"], group="标注")
|
||||
labelSize = input.string("normal", "标签字号", options=["tiny","small","normal","large","huge"], group="标注")
|
||||
labelOffsetBars = input.int(2, "标签右移K线的距离(根数)", minval=0, maxval=50, group="标注")
|
||||
showLegend = input.bool(true, "显示右侧图例(周期映射)", group="标注")
|
||||
|
||||
@@ -68,6 +68,12 @@ hColor12 = input.color(color.new(color.silver, 0), "颜色 1M", group=groupHTF)
|
||||
hWidth12 = input.int(1, "线宽 1M", minval=1, maxval=4, group=groupHTF)
|
||||
hStyle12 = input.string("dotted", "样式 1M", options=["solid","dashed","dotted"], group=groupHTF)
|
||||
|
||||
// 3日线(新增)
|
||||
hShow13 = input.bool(true, "显示 3D", group=groupHTF)
|
||||
hColor13 = input.color(color.new(color.gray, 0), "颜色 3D", group=groupHTF)
|
||||
hWidth13 = input.int(1, "线宽 3D", minval=1, maxval=4, group=groupHTF)
|
||||
hStyle13 = input.string("dotted", "样式 3D", options=["solid","dashed","dotted"], group=groupHTF)
|
||||
|
||||
// 次级别
|
||||
groupLTF = "按线控制 - 次级别"
|
||||
lShow1 = input.bool(true, "显示 1m", group=groupLTF)
|
||||
@@ -87,14 +93,21 @@ lColor4 = input.color(color.new(color.aqua, 30),"颜色 15m", group=groupLTF)
|
||||
lWidth4 = input.int(1, "线宽 15m", minval=1, maxval=4, group=groupLTF)
|
||||
lStyle4 = input.string("dotted", "样式 15m", options=["solid","dashed","dotted"], group=groupLTF)
|
||||
|
||||
// 本级别
|
||||
groupCURR = "按线控制 - 本级别"
|
||||
cShow = input.bool(true, "显示 本级别", group=groupCURR)
|
||||
cColor = input.color(color.new(color.white, 0), "颜色 本级别", group=groupCURR)
|
||||
cWidth = input.int(1, "线宽 本级别", minval=1, maxval=4, group=groupCURR)
|
||||
cStyle = input.string("solid", "样式 本级别", options=["solid","dashed","dotted"], group=groupCURR)
|
||||
|
||||
// 样式字符串到 line.style 的映射
|
||||
f_lineStyle(string s) => s == "solid" ? line.style_solid : s == "dashed" ? line.style_dashed : line.style_dotted
|
||||
|
||||
// 取对应序号的配置
|
||||
f_htfShow(int i) => i == 0 ? hShow1 : i == 1 ? hShow2 : i == 2 ? hShow3 : i == 3 ? hShow4 : i == 4 ? hShow5 : i == 5 ? hShow6 : i == 6 ? hShow7 : i == 7 ? hShow8 : i == 8 ? hShow9 : i == 9 ? hShow10 : i == 10 ? hShow11 : hShow12
|
||||
f_htfColor(int i) => i == 0 ? hColor1 : i == 1 ? hColor2 : i == 2 ? hColor3 : i == 3 ? hColor4 : i == 4 ? hColor5 : i == 5 ? hColor6 : i == 6 ? hColor7 : i == 7 ? hColor8 : i == 8 ? hColor9 : i == 9 ? hColor10 : i == 10 ? hColor11 : hColor12
|
||||
f_htfWidth(int i) => i == 0 ? hWidth1 : i == 1 ? hWidth2 : i == 2 ? hWidth3 : i == 3 ? hWidth4 : i == 4 ? hWidth5 : i == 5 ? hWidth6 : i == 6 ? hWidth7 : i == 7 ? hWidth8 : i == 8 ? hWidth9 : i == 9 ? hWidth10 : i == 10 ? hWidth11 : hWidth12
|
||||
f_htfStyle(int i) => f_lineStyle(i == 0 ? hStyle1 : i == 1 ? hStyle2 : i == 2 ? hStyle3 : i == 3 ? hStyle4 : i == 4 ? hStyle5 : i == 5 ? hStyle6 : i == 6 ? hStyle7 : i == 7 ? hStyle8 : i == 8 ? hStyle9 : i == 9 ? hStyle10 : i == 10 ? hStyle11 : hStyle12)
|
||||
// 按周期键值映射到控件(避免索引与实际周期错位)
|
||||
f_htfShowK(string key) => key == "30" ? hShow1 : key == "45" ? hShow2 : key == "60" ? hShow3 : key == "120" ? hShow4 : key == "240" ? hShow5 : key == "360" ? hShow6 : key == "480" ? hShow7 : key == "720" ? hShow8 : key == "D" ? hShow9 : key == "2D" ? hShow10 : key == "3D" ? hShow13 : key == "W" ? hShow11 : hShow12
|
||||
f_htfColorK(string key) => key == "30" ? hColor1 : key == "45" ? hColor2 : key == "60" ? hColor3 : key == "120" ? hColor4 : key == "240" ? hColor5 : key == "360" ? hColor6 : key == "480" ? hColor7 : key == "720" ? hColor8 : key == "D" ? hColor9 : key == "2D" ? hColor10 : key == "3D" ? hColor13 : key == "W" ? hColor11 : hColor12
|
||||
f_htfWidthK(string key) => key == "30" ? hWidth1 : key == "45" ? hWidth2 : key == "60" ? hWidth3 : key == "120" ? hWidth4 : key == "240" ? hWidth5 : key == "360" ? hWidth6 : key == "480" ? hWidth7 : key == "720" ? hWidth8 : key == "D" ? hWidth9 : key == "2D" ? hWidth10 : key == "3D" ? hWidth13 : key == "W" ? hWidth11 : hWidth12
|
||||
f_htfStyleK(string key) => f_lineStyle(key == "30" ? hStyle1 : key == "45" ? hStyle2 : key == "60" ? hStyle3 : key == "120" ? hStyle4 : key == "240" ? hStyle5 : key == "360" ? hStyle6 : key == "480" ? hStyle7 : key == "720" ? hStyle8 : key == "D" ? hStyle9 : key == "2D" ? hStyle10 : key == "3D" ? hStyle13 : key == "W" ? hStyle11 : hStyle12)
|
||||
|
||||
f_ltfShow(int i) => i == 0 ? lShow1 : i == 1 ? lShow2 : i == 2 ? lShow3 : lShow4
|
||||
f_ltfColor(int i) => i == 0 ? lColor1 : i == 1 ? lColor2 : i == 2 ? lColor3 : lColor4
|
||||
@@ -115,6 +128,7 @@ if barstate.isfirst and array.size(HTF_KEYS) == 0
|
||||
array.push(HTF_KEYS, "720")
|
||||
array.push(HTF_KEYS, "D")
|
||||
array.push(HTF_KEYS, "2D")
|
||||
array.push(HTF_KEYS, "3D")
|
||||
array.push(HTF_KEYS, "W")
|
||||
array.push(HTF_KEYS, "M")
|
||||
array.push(LTF_KEYS, "1")
|
||||
@@ -259,21 +273,22 @@ ltfsz = array.size(ltfRes)
|
||||
if ltfsz > 0
|
||||
take = math.min(maxLTFInput, 4, ltfsz)
|
||||
for k = 0 to take - 1
|
||||
array.push(ltfSel, array.get(ltfRes, ltfsz - 1 - k))
|
||||
array.push(ltfSel, array.get(ltfRes, k))
|
||||
|
||||
htfCountSelected = math.min(array.size(htfRes), maxHTFInput, 12)
|
||||
htfCountSelected = math.min(array.size(htfRes), maxHTFInput, 13)
|
||||
ltfCountSelected = math.min(array.size(ltfSel), 4)
|
||||
|
||||
// ============ 计算最新 EMA52 ============
|
||||
var float[] htfVals = array.new_float()
|
||||
var float[] ltfVals = array.new_float()
|
||||
currVal = ta.ema(close, 52)
|
||||
if barstate.isfirst
|
||||
for _i = 0 to 11
|
||||
for _i = 0 to 12
|
||||
array.push(htfVals, na)
|
||||
for _j = 0 to 3
|
||||
array.push(ltfVals, na)
|
||||
|
||||
for i = 0 to 11
|
||||
for i = 0 to 12
|
||||
float val = na
|
||||
if enableHTF and i < htfCountSelected
|
||||
tfStr = array.get(htfRes, i)
|
||||
@@ -302,11 +317,13 @@ var line[] htfLines = array.new_line()
|
||||
var line[] ltfLines = array.new_line()
|
||||
var label[] htfLabels = array.new_label()
|
||||
var label[] ltfLabels = array.new_label()
|
||||
var line currLine = na
|
||||
var label currLabel = na
|
||||
var string lastTicker = na
|
||||
var string lastTf = na
|
||||
var table legendTbl = na
|
||||
if barstate.isfirst
|
||||
for _i = 0 to 11
|
||||
for _i = 0 to 12
|
||||
array.push(htfLines, na)
|
||||
array.push(htfLabels, na)
|
||||
for _j = 0 to 3
|
||||
@@ -321,7 +338,7 @@ if barstate.isfirst
|
||||
symbolChanged = lastTicker != syminfo.tickerid
|
||||
tfChanged = lastTf != timeframe.period
|
||||
if symbolChanged or tfChanged
|
||||
for i = 0 to 11
|
||||
for i = 0 to 12
|
||||
l = array.get(htfLines, i)
|
||||
if not na(l)
|
||||
line.delete(l)
|
||||
@@ -339,6 +356,12 @@ if symbolChanged or tfChanged
|
||||
if not na(lb)
|
||||
label.delete(lb)
|
||||
array.set(ltfLabels, i, na)
|
||||
if not na(currLine)
|
||||
line.delete(currLine)
|
||||
currLine := na
|
||||
if not na(currLabel)
|
||||
label.delete(currLabel)
|
||||
currLabel := na
|
||||
lastTicker := syminfo.tickerid
|
||||
lastTf := timeframe.period
|
||||
|
||||
@@ -352,11 +375,14 @@ if barstate.islast
|
||||
table.cell(legendTbl, 1, r, "", text_color=color.new(color.white, 0), text_halign=text.align_right, bgcolor=color.new(color.black, 100))
|
||||
row = 0
|
||||
// 长级别
|
||||
for i = 0 to 11
|
||||
for i = 0 to 12
|
||||
v = array.get(htfVals, i)
|
||||
if enableHTF and i < htfCountSelected and f_htfShow(i) and not na(v) and f_inRange(v)
|
||||
if enableHTF and i < htfCountSelected and not na(v) and f_inRange(v)
|
||||
tfStr = array.get(htfRes, i)
|
||||
col = f_htfColor(i)
|
||||
show = f_htfShowK(tfStr)
|
||||
col = f_htfColorK(tfStr)
|
||||
if not show
|
||||
continue
|
||||
table.cell(legendTbl, 0, row, f_prettyTf(tfStr), text_color=col, text_halign=text.align_left)
|
||||
table.cell(legendTbl, 1, row, str.tostring(v, format.mintick), text_color=col, text_halign=text.align_right)
|
||||
row += 1
|
||||
@@ -369,26 +395,32 @@ if barstate.islast
|
||||
table.cell(legendTbl, 0, row, f_prettyTf(tfStr), text_color=col, text_halign=text.align_left)
|
||||
table.cell(legendTbl, 1, row, str.tostring(v, format.mintick), text_color=col, text_halign=text.align_right)
|
||||
row += 1
|
||||
// 本级别
|
||||
if cShow and not na(currVal) and f_inRange(currVal)
|
||||
table.cell(legendTbl, 0, row, f_prettyTf(timeframe.period), text_color=cColor, text_halign=text.align_left)
|
||||
table.cell(legendTbl, 1, row, str.tostring(currVal, format.mintick), text_color=cColor, text_halign=text.align_right)
|
||||
row += 1
|
||||
// 长级别
|
||||
for i = 0 to 11
|
||||
// 颜色/线宽/样式来自按线控制面板
|
||||
col = f_htfColor(i)
|
||||
for i = 0 to 12
|
||||
// 颜色/线宽/样式来自按线控制面板(基于键值)
|
||||
v = array.get(htfVals, i)
|
||||
show = enableHTF and i < htfCountSelected and f_htfShow(i) and not na(v) and f_inRange(v)
|
||||
tfStr = i < array.size(htfRes) ? array.get(htfRes, i) : ""
|
||||
show = enableHTF and i < htfCountSelected and not na(v) and f_inRange(v) and (tfStr != "" and f_htfShowK(tfStr))
|
||||
col = tfStr != "" ? f_htfColorK(tfStr) : color.new(color.gray, 80)
|
||||
ln = array.get(htfLines, i)
|
||||
lb = array.get(htfLabels, i)
|
||||
if show
|
||||
x1 = bar_index - lookbackBars
|
||||
x2 = bar_index + labelOffsetBars
|
||||
if na(ln)
|
||||
ln := line.new(x1, v, x2, v, xloc=xloc.bar_index, extend=extend.none, color=col, width=f_htfWidth(i), style=f_htfStyle(i))
|
||||
ln := line.new(x1, v, x2, v, xloc=xloc.bar_index, extend=extend.none, color=col, width=f_htfWidthK(tfStr), style=f_htfStyleK(tfStr))
|
||||
array.set(htfLines, i, ln)
|
||||
else
|
||||
line.set_xy1(ln, x1, v)
|
||||
line.set_xy2(ln, x2, v)
|
||||
line.set_color(ln, col)
|
||||
line.set_width(ln, f_htfWidth(i))
|
||||
line.set_style(ln, f_htfStyle(i))
|
||||
line.set_width(ln, f_htfWidthK(tfStr))
|
||||
line.set_style(ln, f_htfStyleK(tfStr))
|
||||
txt = f_prettyTf(array.get(htfRes, i)) + ' ' + str.tostring(v, format.mintick)
|
||||
if na(lb)
|
||||
lb := label.new(bar_index + labelOffsetBars, v, txt, xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=col, color=color.new(col, labelBgAlpha), size=f_strToSize(labelSize))
|
||||
@@ -447,4 +479,37 @@ if barstate.islast
|
||||
label.delete(lb)
|
||||
array.set(ltfLabels, i, na)
|
||||
|
||||
// 本级别
|
||||
colC = cColor
|
||||
vC = currVal
|
||||
showC = cShow and not na(vC) and f_inRange(vC)
|
||||
if showC
|
||||
x1 = bar_index - lookbackBars
|
||||
x2 = bar_index + labelOffsetBars
|
||||
if na(currLine)
|
||||
currLine := line.new(x1, vC, x2, vC, xloc=xloc.bar_index, extend=extend.none, color=colC, width=(cWidth), style=f_lineStyle(cStyle))
|
||||
else
|
||||
line.set_xy1(currLine, x1, vC)
|
||||
line.set_xy2(currLine, x2, vC)
|
||||
line.set_color(currLine, colC)
|
||||
line.set_width(currLine, (cWidth))
|
||||
line.set_style(currLine, f_lineStyle(cStyle))
|
||||
txtC = f_prettyTf(timeframe.period) + ' ' + str.tostring(vC, format.mintick)
|
||||
if na(currLabel)
|
||||
currLabel := label.new(bar_index + labelOffsetBars, vC, txtC, xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, textcolor=colC, color=color.new(colC, labelBgAlpha), size=f_strToSize(labelSize))
|
||||
else
|
||||
label.set_xy(currLabel, bar_index + labelOffsetBars, vC)
|
||||
label.set_text(currLabel, txtC)
|
||||
label.set_textcolor(currLabel, colC)
|
||||
label.set_color(currLabel, color.new(colC, labelBgAlpha))
|
||||
label.set_style(currLabel, label.style_label_left)
|
||||
label.set_size(currLabel, f_strToSize(labelSize))
|
||||
else
|
||||
if not na(currLine)
|
||||
line.delete(currLine)
|
||||
currLine := na
|
||||
if not na(currLabel)
|
||||
label.delete(currLabel)
|
||||
currLabel := na
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user