0

I am creating an indicator pinescript. And the strategy will exit on the reverse direction. For example : 20:00 : Long (Entry) 20:30 : Short (Exit and Entry Short)

But, I found it's trigger multipler alert on Indicator.

I know we can check the last order position with strategy.position_size but how to id on Indicator mode?

Because I want to avoid it's trigger same direction alert

For example 20:00 Long 20:05 Long

I am a new pinescript developer, I appreciate any kind of help! Thank you

1 Answers1

0

To know the direction of your open order, you can use :

if strategy.opentrades > 0 // There is an open order

    if strategy.position_size > 0 // The open order is a LONG
        na
    else if strategy.position_size < 0 // The open order is a SHORT
        na

and then trigger in the opposite direction.

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
  • Yes, if it's on strategy mode, but we can't use it on indicator mode – Arif Nurdiansyah Dec 14 '22 at 15:59
  • @ArifNurdiansyah of course, in an indicator, you can't use strategy.enter nor strategy.exit. – G.Lebret Dec 15 '22 at 13:44
  • Yes, that's my point, let's say in the indicator mode it's match the long condition and then we send alert for long, then there is another long condition while the previous long is not hit target profit or stop loss. It's gonna send another long alert, but I want it to wait until the previous meet target profit or stop loss. So it's gonna ignore the second long condition – Arif Nurdiansyah Dec 16 '22 at 08:48