View Full Version : Strategy in simulation mode: immediately closes position
04-12-2007, 11:59 PM
OK, I'm probably overlooking a setting somewhere...
When I attach a strategy to a live chart (simulation mode), the position that was opened a few bars ago is immediately closed on the last bar of the chart when I attach the strategy, instead of acting like the strategy has been running the whole day, a position opened say one hour ago and keeping the position open. The position is not closed by the strategy itself, it is NT doing this for some reason.
What setting am I overlooking?
04-13-2007, 12:49 AM
Do you mean last bar of a session? The only way a strategy is closed outside of your code is if Exit on close is set to true when apply a strategy.
04-13-2007, 01:12 AM
The last bar on the chart (not the end of a session).
So at the moment I put the strategy on the chart the last position entered by the strategy is closed on the last bar of the chart, no matter what.
I'm not using ExitOnClose in my strategy.
I'm sure I'm overlooking something, since it didn't behave like this before... (with the same strategy)
04-13-2007, 01:25 AM
Is there a name on this order that closes the position? Would see it marked on the chart or in the orders tab of the Control Center.
04-13-2007, 01:30 AM
It's just says 'Close position'
I see nothing in the orders tab
04-13-2007, 02:24 AM
I checked our code and this "Close position" is named when a strategy executes an Enter() method when a position already exists.
I suggest adding afew print statements before some of your Enter() methods and see what is being called when that position exits.
Print("EnterLong() called at " + Time);
04-13-2007, 02:25 AM
I just discovered that if I select "wait until flat before executing live" instead of "immediately submit live working historical orders", then this closing order disappears.
However, I still think my strategy is not generating this order. And if it did, wouldn't the order be always at the same place? Now it is always at the last bar of the chart at the moment that I place the strategy on it...
04-13-2007, 02:31 AM
100% that the strategy is generating the order. Since the order name cames from within the strategy class internal PlaceOrder() method which gets called from any Enter() or Exit() method.
There is always a chance that maybe a bug on our end but I can't see it. Running the debug print statements as per my last post will clarify what is happening.
04-13-2007, 03:10 AM
Using the print statement as you suggested, I don't see any order at the moment that the 'close position' appears.
But I wasn't expecting that anyway because the time that the 'close position' statement appears does not depend on my strategy but on the moment that I put the strategy on the chart (like I wrote below).
Does my previous post give any clue?
04-13-2007, 03:13 AM
Unfortunately your previous postdoes not providea clue.
Please send me the following:
Image of the strategy dialogue window with the settings you have to reproduce the problem.
Bar interval you are running on.
ray at ninjatrader dot com
04-13-2007, 03:48 AM
The marketcondition has now changed such that a genuine position closing happened, so right now I cannot generatethe problem anymore.
So I need to waitfor a new live condition or make modifications in the strategy to make this situation happen again.
In the meantime I have discovered that at the same timethe Stoploss seems to get ignored, but only at the last part of the chart.Everywhere else there is no problem.
Maybe the problems are related.
I don't think there is anything wrong with a statement like:
SetStopLoss(LongEntrySignal, CalculationMode.Ticks, stoploss, false);
Anyway, I will keep monitoring this and when it happens again I'll send you the strategy and images that you asked for.
04-13-2007, 04:36 AM