我正在研究一个指标,该指标使用 Up candle Top Wicks 和 down candle Bottom Wicks 在 HTF 中绘制方框。
现在它会在我想要的地方绘制一个蓝色的 upBox 和一个红色的 downBox ......但是它会在某个地方随机结束,然后下一次情况发生时会开始一个新的
我需要的是它每次都绘制框,不管那里是否已经有 upBox 或 downBox
我真的希望 upBox 在有一个新的 higherhigh 超过 upHiLine 等时停止绘制......但我还没有弄清楚如何做到这一点
有人能帮忙吗?
//@version=5
indicator("Intraday wicks",overlay=true, max_bars_back = 200, max_boxes_count = 200)
//Input
string tfInput = input.timeframe("15", "Timeframe")
// Initialize variables on bar zero only, so they preserve their values across bars.
bool up = close > open
bool down = close < open
var upHi = float(na)
var upCl = float(na)
var upOp = float(na)
var upLo = float(na)
var downLo = float(na)
var downCl = float(na)
var downHi = float(na)
var downOp = float(na)
var line upHiLine = na
var line upLoLine = na
var line downHiLine = na
var line downLoLine = na
var box upBox = na
var box downBox = na
// Detect changes in timeframe.
bool newTF = ta.change(time(tfInput))
if newTF
if up //if new bar in HTF is Bullish var, reset values and create new lines
upHi := high //collect the top of the top wick value
upCl := close //collect the bottom of top wick value
//up high line is the top wick of a bull candle as a line
upHiLine := line.new(bar_index, upHi, bar_index, upHi, color = color.white, width = 1)
//up lo line is the bottom wick of a bull candle as a line
upLoLine := line.new(bar_index, upCl, bar_index, upCl, color = color.white, width = 1)
//up box is a box drawn beteen the top and bottom wicks of a bull candle
upBox := box.new(bar_index, upHi, bar_index,upCl, border_color = na, bgcolor = color.rgb(47, 93, 229))
else
// On other bars, extend the right coordinate of lines and box.
line.set_x2(upHiLine, bar_index)
line.set_x2(upLoLine, bar_index)
box.set_right(upBox, bar_index)
int(na)
if down //if new bar in HTF is Bearish var, reset values and create new lines
downCl := close //collect the top of the top wick value
downLo := low //collect the bottom of top wick value
//up high line is the top wick of a bull candle as a line
downHiLine := line.new(bar_index, downCl, bar_index, downCl, color = color.white, width = 1)
//up lo line is the bottom wick of a bull candle as a line
downLoLine := line.new(bar_index, downLo, bar_index, downLo, color = color.white, width = 1)
//up box is a box drawn beteen the top and bottom wicks of a bull candle
downBox := box.new(bar_index, downCl, bar_index,downLo, border_color = na, bgcolor = color.rgb(234, 70, 125))
else
// On other bars, extend the right coordinate of lines and box.
line.set_x2(downHiLine, bar_index)
line.set_x2(downLoLine, bar_index)
box.set_right(downBox, bar_index)
int(na)
好的所以我在我的代码中发现了一个错误.....
box.set_right(upBox, bar_index)
改为
box.set_extend(id=upBox, extend=extend.right)
[pic of new boxes][1]