Reputation: 7707
I tried the following code:
//@version=5
strategy("BarUpDn Strategy")
var sequenceNumber = 0
var previousPositionSize = strategy.position_size
if (close > open and open > close[1])
strategy.entry("BarUp", strategy.long, alert_message='['+str.tostring(sequenceNumber)+']')
if strategy.position_size != previousPositionSize
sequenceNumber := sequenceNumber + 1
previousPositionSize := strategy.position_size
if (close < open and open < close[1])
strategy.entry("BarDn", strategy.short, alert_message='['+str.tostring(sequenceNumber)+']')
if strategy.position_size != previousPositionSize
sequenceNumber := sequenceNumber + 1
previousPositionSize := strategy.position_size
sequenceNumber
does not work as expected.
I would expect the sequence like: 1,2,3,4
without gaps, instead I find 1,2,2,4,4,6
. Like calculations happened concurrently.
How to properly count entries without gaps?
Upvotes: 0
Views: 377
Reputation: 21111
You can use the built-in variables strategy.opentrades
or strategy.closedtrades
depending on your needs.
Upvotes: 1