Search code examples
pine-scriptpine-script-v5

plotshape not plotting on expected candle


I am trying plot circle above candle when SMA50 falls between candle low and a low threashold of 1%. I am using code below.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//

//@version=5
_close = close
_low = low
_lowerThreshold = _low - _low * 0.01 // threshold value to determine value near 
indicator("SMA Through Candle", overlay = true)
sma = ta.sma(_close, 50)
//sma just below low
smaNearLow = false
if sma >= _lowerThreshold and sma <= _low
    smaNearLow := true
//
plotshape(series = (smaNearLow == true)? close:na, style = shape.circle, location = location.abovebar, offset = 5)
plot(series = _lowerThreshold, style = plot.style_steplinebr)

Below is the result enter image description here

As you can see, I have add stepline below 1% low price, and SMA50 in yellow line. I was expecting circle shape will appear at the right check mark and actual shapes are plotted entirely at wrong candles. What am I doing wrong here?


Solution

  • You have an offsetin your plotshape call set to 5, so your plot shapes are shifted 5 bars forward - remove the offset and the dots will show over the candles you have your check marks for.

    plotshape(series = (smaNearLow == true)? close:na, style = shape.circle, location = location.abovebar)