For the sake of discussion, an example is below:
Let's say it goes "Long", remains in a trade for 60 minutes, then exits that trade and goes "Flat". 45 minutes later, an entry signal is valid again and goes "Short" for 150 minutes, etc.
The trade might "Open" and "Close" multiple times during the trading day.
When the trade transitions from "Long/Short" to "Flat", I would like to reset certain counters to "zero". The issue is the counter can start before the trade is "Long/Short", so having the counter equal "zero" when flat will not work.
I also have a dozen "Exit" possibilities on my trades. (They are in various locations/constructs around the strategy.) I am trying to find a way not to type the following in every location I have "Exit" code:
CounterAA = 0
CounterBB = 0
CounterCC = 0
etc.
Also, the strategy is enabled on hundreds of stocks at the same time.
What NinjaScript code can I use to reset the counters when a trade is completely cycled through and transitions to "flat", but is still available for use?
Please be specific where it would be placed, and how it would be used: OnBarUpdate(), OnStateChange(), OnOrderUpdate(), etc.
Thanks in advance.
Comment