简体   繁体   中英

please help I dont know how to size box from the start of an contraction zone to the end of the contraction pinescript indicator

I've been trying to make an indicator that finds contraction zones but I am confused I was able to highlight the contraction zones with the white labels but I want a box that is sized from start and ends at the end of the contraction which is from the first white label to the last label I am completely lost at this point since the closest I get to is making a box for each label down but it isn't going to work for what I need it for

How it looks like, (white box isnt part of it) [1]: https://i.stack.imgur.com/5IQC0.png How I want it to look [2]: https://i.stack.imgur.com/Rm1Us.png

//@version=5
indicator(title="ATR Contraction", shorttitle="ATR CONTRACTION FINDER", overlay=true, precision=3, max_lines_count = 500, max_boxes_count = 500)
lenAtr = input(title = "atr length", defval = 1)
atr = ta.atr(lenAtr)
//atr values
avg5 = input.int(title="WMA", defval=5)
avg13 = input.int(title="WMA",  defval=13)
avg22 = input.int(title="WMA",  defval=22)

WMA5 = ta.wma (atr, avg5)
WMA13 = ta.wma (atr, avg13)
WMA22 = ta.wma (atr,avg22)

ifAtr = atr < WMA5 and WMA5 < WMA13 and WMA13 < WMA22

//STD
length = input.int(20, minval=1)
src = input(close, title="Source")
stdev = ta.stdev( src , length)
STDWMA13 = ta.wma (stdev, avg13)
STDWMA22 = ta.wma (stdev,avg22)
ifStd = stdev < STDWMA13 and STDWMA13 < STDWMA22

// volume
VWMA5 = ta.wma ( volume ,5)
VWMA10 = ta.wma ( volume ,10)
VWMA20 = ta.wma ( volume ,20)
ifVMA = VWMA5 < VWMA10 and VWMA10 < VWMA20

lessVolatility = ifAtr and ifStd and ifVMA

string tfInput = input.timeframe("D", "Timeframe")
var hi = float(na)
var lo = float(na)
var line hiLine = na
var line loLine = na
var box hiLoBox = na
// Detect changes in timeframe.
if lessVolatility? 1:na
    // New bar in higher timeframe; reset values and create new lines and box.
    hi := high
    lo := low
    hiLoBox := box.new(bar_index -1 , hi, bar_index+5, lo, border_color = na, bgcolor = color.silver)
    box.set_bgcolor(hiLoBox, color.new(color.blue, 50))
    int(na)



plotshape(lessVolatility? 1:na,style=shape.labeldown, location=location.abovebar, color=color.white, size=size.tiny)

Whenever you get the singal for first time, you can set a variable to true and keep setting it to true until signal continues. And based on that variable you can create a new box when its set for first time, and keep extending it for one bar if it was already true from before. Example

//@version=5
indicator(title="ATR Contraction", shorttitle="ATR CONTRACTION FINDER", overlay=true, precision=3, max_lines_count = 500, max_boxes_count = 500)
lenAtr = input(title = "atr length", defval = 1)
atr = ta.atr(lenAtr)
//atr values
avg5 = input.int(title="WMA", defval=5)
avg13 = input.int(title="WMA",  defval=13)
avg22 = input.int(title="WMA",  defval=22)

WMA5 = ta.wma (atr, avg5)
WMA13 = ta.wma (atr, avg13)
WMA22 = ta.wma (atr,avg22)

ifAtr = atr < WMA5 and WMA5 < WMA13 and WMA13 < WMA22

//STD
length = input.int(20, minval=1)
src = input(close, title="Source")
stdev = ta.stdev( src , length)
STDWMA13 = ta.wma (stdev, avg13)
STDWMA22 = ta.wma (stdev,avg22)
ifStd = stdev < STDWMA13 and STDWMA13 < STDWMA22

// volume
VWMA5 = ta.wma ( volume ,5)
VWMA10 = ta.wma ( volume ,10)
VWMA20 = ta.wma ( volume ,20)
ifVMA = VWMA5 < VWMA10 and VWMA10 < VWMA20

lessVolatility = ifAtr and ifStd and ifVMA

string tfInput = input.timeframe("D", "Timeframe")
var hi = float(na)
var lo = float(na)
var line hiLine = na
var line loLine = na
var box hiLoBox = na
// Detect changes in timeframe.
var continuebox=false

if lessVolatility? 1:na
    // New bar in higher timeframe; reset values and create new lines and box.
    hi := high
    lo := low
    if continuebox
        box.set_right(hiLoBox,bar_index)
    else
        hiLoBox := box.new(bar_index -1 , hi, bar_index, lo, border_color = na, bgcolor = color.silver)
        box.set_bgcolor(hiLoBox, color.new(color.blue, 50))
    int(na)
    continuebox:=true
else
    continuebox:=false



plotshape(lessVolatility? 1:na,style=shape.labeldown, location=location.abovebar, color=color.white, size=size.tiny)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM