1

I want to limit the amount of trades my script can be in at any one time. I can get in and out of positions, but I want to limit total to 5 so I dont have too much risk or draw down. I use below to get in/out of trade.

strategy.entry(id = "Long", long = true, when = minLongMoveTrue, stop = percentMove)

strategy.entry(id = "Short", long = true, when = minShortMoveTrue, stop = percentMove)

strategy.position_size seems only look at total shares active, but cannot discern how many active trades I am in.

Maybe I need to set up a counter since pine script doesnt have inbuilt function?

vitruvius
  • 15,740
  • 3
  • 16
  • 26
bahamutcog
  • 11
  • 2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 03 '22 at 15:17

1 Answers1

1

You can use the built-in variable strategy.opentrades to get the count of open trades.

Number of market position entries, which were not closed and remain opened. If there is no open market position, 0 is returned.

You can also use strategy.risk.max_drawdown as risk management.

The purpose of this rule is to determine maximum drawdown. The rule affects the whole strategy. Once the maximum drawdown value is reached, all pending orders are cancelled, all open positions are closed and no new orders can be placed.

vitruvius
  • 15,740
  • 3
  • 16
  • 26