I am having several issues which hopefully someone can help me shed light.
1. I have a strategy with various entry criteria.
-Each execution criteria is in an if(Position.MarketPosition == MarketPosition.Flat) - in other words, it shouldn't enter long unless we are already flat.
-During real live execution, however, the strategy will have multiple entries from the same signal
-For example, today the strategy has given the entry single twice in the same second, leaving me with a position twice what I should have.
-To prevent the strategy from overfill, I have all of the OnBarUpdate entry methods pasted inside of an OnExecution procedure so that if I get a flatten and reversal single at the same time, my strategy will not die.
2. I am trying to get my strategy to ExitOnClose on a custom session.
-My session starts Sunday at 5pm and ends Friday at 3pm.
-There is a bug in Ninjatrader such that custom sessions do not calculate close correctly - in other words it flattens every day at 3pm throughout the entire week rather than on Friday
-I have tried to workaround by having the following code execute, but since my session ends at 3pm, no market data is available at this time.
protected override void OnMarketData(MarketDataEventArgs e)
{
//Flatten us at 3 on Friday
if (Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) >= 150000)
{
if (Position.MarketPosition == MarketPosition.Long)
{
ExitLong();
}
if (Position.MarketPosition == MarketPosition.Short)
{
ExitShort();
}
}
}
Comment