0

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

Kansari
  • 1
  • 1

1 Answers1

0

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)
G.Lebret
  • 2,826
  • 2
  • 16
  • 27
  • Thanks for the input, but I still can't get it to work. I get errors for the xloc and yloc – Kansari Mar 25 '23 at 18:43
  • @Kansari do you still have this error 'Error: Cannot use 'plotshape' in local scope' ? – G.Lebret Mar 25 '23 at 18:54
  • Yes I do. I cant get a 'plotshape' to plot on the actual price, it's either above or below bar. So for now, I'm using 'plot'. Not ideal, as it plots a line on the entry price, but continues plotting and till the next entry price. – Kansari Apr 03 '23 at 12:47
  • plotshape(almaBUY, title='Enter bar', color=color.new(#2d9331, 0), style=shape.triangleup, location=location.belowbar, size=size.small, display=display.all) plot(entry_price, title='Enter Price', color=color.new(#2d9331, 0), style=plot.style_circles, linewidth=2, editable = true) – Kansari Apr 03 '23 at 12:58
  • @Kansari please try to modify plot with your condition on the color, as in my answer. – G.Lebret Apr 03 '23 at 14:37
  • My coding skills are limited. Could you send me a link to a script with a similar plotshape? I have not come across one in the TV community. – Kansari Apr 04 '23 at 21:28
  • @Kansari edit your question and paste your entire code. Without it , it is hard to help you. – G.Lebret Apr 05 '23 at 02:30