Is it possible to plot a shape, on the chart candle, using an indicator script, like found for a 'strategy' scripts?

144 Views Asked by At

I would like to know the exact entry and exit prices for the 'alertconditions' I know this can be done for a 'strategy script, but I can't get it to work for an 'indicator'.

the code below doesn't work.

plotshape(entry, title='Long Enter', color=color.new(#2d9331, 0), style=shape.cross, location=location.absolute, size=size.small, xloc=xloc.bar_index, yloc=entry_price, offset=0)

Error: Cannot use 'plotshape' in local scope

1

There are 1 best solutions below

7
G.Lebret On

You have the error because you try to use plotshape inside a conditional block.

Use plotshape outside your conditional loop and use this condition inside the plotshape fonction on the color variable :

color = MyCondition ? color.new(#2d9331, 0) : na

if MyCondition is true, your plotshape will draw, else the color will be na and nothing will be drawn.

You should modify your code like this :

if MyCondition
    // your code

plotshape(entry, title='Long Enter', color = MyCondition ? color.new(#2d9331, 0) : na, style=shape.cross, location=location.absolute, size=size.small, xloc=xloc.bar_index, yloc=entry_price, offset=0)