简体   繁体   中英

Coloring a bar recursively

I am trying write a script which allows a user to detect an inside bar on a higher (user selectable) timeframe. and color all the bars in the current timeframe that fall under the inside bar on the higher timeframe.

This should be a simple task and I believe I have made some progress.

I am not able to color the bars as colorbar() cannot be used in local scope. Any suggestions on how to achieve what I am looking for?

This is the code I tried. Predictably it throws the local scope error.

`//@version=5
indicator("Inside Bar HTF", overlay=true)

chTF = input.timeframe(title="Timeframe", defval="1D")

htf_high = request.security(syminfo.tickerid, chTF, high, gaps=barmerge.gaps_on)
htf_low = request.security(syminfo.tickerid, chTF, low, gaps=barmerge.gaps_on)

if (htf_high < htf_high[1] and htf_low > htf_low[1])
    // Color the corresponding bars on the current time frame
    for i = 0 to bar_index
        if (high[i] < htf_high and low[i] > htf_low)
            barcolor(color. Yellow)
`

Unfortunately, this cannot be done as you said because you cannot call the plotchar() in local scope.

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