I'm running into a situation where I'm getting conflicting signals from a strategy run in the strategy manager vs the signals on a chart.
What it seems like is that the NSF is recognized and honored on the SM - i.e. if a position is already open, the next signal is ignored. On the charts, it shows that both long and short positions can be open at the same time.
How do I ensure NSF positions on the charts are not entered?
What it seems like is that the NSF is recognized and honored on the SM - i.e. if a position is already open, the next signal is ignored. On the charts, it shows that both long and short positions can be open at the same time.
How do I ensure NSF positions on the charts are not entered?
Rename
The Strategy Monitor (and Streaming Strategies) works with "Use Live Positions".
The Strategy Window does not.
1. Is Preferences > Trading > Use Live Positions enabled?
2. Is Strategy Settings > Retain NSF Positions enabled?
Add this statement to the Initialize() section of the Strategy. The it will ignore the "Retain NSF Positions" configuration so that NSF Positions are never retained by the backtest.
That will happen, for example, if you have Buy/Sell and Short/Cover blocks in the same block Strategy.
The Strategy Window does not.
1. Is Preferences > Trading > Use Live Positions enabled?
2. Is Strategy Settings > Retain NSF Positions enabled?
QUOTE:
How do I ensure NSF positions on the charts are not entered?
Add this statement to the Initialize() section of the Strategy. The it will ignore the "Retain NSF Positions" configuration so that NSF Positions are never retained by the backtest.
CODE:
BacktestSettings.RetainNSFPositions = false;
QUOTE:That's because your strategy allow it, and it's a bad idea.
On the charts, it shows that both long and short positions can be open at the same time.
That will happen, for example, if you have Buy/Sell and Short/Cover blocks in the same block Strategy.
Thanks as always, Cone. I should be more clear - I'm using a Dummy account and only having them auto-stage, not placed. I didn't see any overlapping positions in my backtest of the original code, even with the "Retain NSF Postions" selected.
A couple comments/questions:
Live Positions was not selected. Are you saying it should be selected?
Retain NSF positions was selected; I've turned that off now. I also added the code you suggested, but I'm still seeing the entry/exit signals.
Finally, you say having buy/sell and short/covers should not be in the same strategy (I'm using code, not block strategies this time). Is there something inherent in a Long/Short strategy that's an issue, or are you saying that this implementation is where the problem is?
A couple comments/questions:
Live Positions was not selected. Are you saying it should be selected?
Retain NSF positions was selected; I've turned that off now. I also added the code you suggested, but I'm still seeing the entry/exit signals.
CODE:
public override void Initialize(BarHistory bars) { BacktestSettings.RetainNSFPositions = false;
Finally, you say having buy/sell and short/covers should not be in the same strategy (I'm using code, not block strategies this time). Is there something inherent in a Long/Short strategy that's an issue, or are you saying that this implementation is where the problem is?
QUOTE:Live trading (includes dummy broker) uses the same code, so I don't know what to tell you. The data can be different when trading live if you're not using Streaming Bars.
I didn't see any overlapping positions in my backtest of the original code, even with the "Retain NSF Postions" selected.
QUOTE:I was pointing out one of the differences the way a strategy backtest works in a Strategy Window vs. the Strategy Monitor. But if your strategy trades the primary symbol and only holds one position per symbol, I'd recommend "Use Live Positions". But please read the Help about the details for that option.
Live Positions was not selected. Are you saying it should be selected?
QUOTE:You lost me here. I don't have the details. Why wouldn't you expect entry and exit signals? You might have to show us the code to explain it.
but I'm still seeing the entry/exit signals.
QUOTE:A strategy has to manage all the positions separately.
Is there something inherent in a Long/Short strategy that's an issue
QUOTE:Both. If your code does not ensure that only 1 position is open, then any combination is possible in the backtest. Brokers like IB wouldn't allow it because Buy/Cover and Short/Sell mean the same thing - in other words, the strategy might have long and short positions for the same symbol, but IB would only have 1 position or none - the combination of the backtest long and short positions.
, or are you saying that this implementation is where the problem is?
Your Response
Post
Edit Post
Login is required