Have tested it on NQ 09-12, ES 09-12, YM-09-12 with no problems.
When running strategy on FDAX contract - NinjaTrader just freezes. Then ninjaTrader starts rapidly increasing amount of memory and that's all I can get. Having encountered this problem today - I made strategy logging its actions into file. That is when I found out reason for rapid memory increase - when strategy is run through historical data, it gets into 'simulation loop'. Since Log function is used to print information - Ninja's memory increases endlessly, and file, where logs are printed, increases as well.
Strategy is based on unmanaged approach, with CalculateOnbarClose=true. Uses onExecution() callback for decisions. It uses also additional 1 minute timeframe. Here follows entire code of onExecution
protected override void Initialize()
{
CalculateOnBarClose = true;
Unmanaged=true;
ExitOnClose=true;
_startTime =DateTime.Parse(startTime);
_endTime =DateTime.Parse(endTime);
_stopTime =DateTime.Parse(stopTime);
Add(PeriodType.Minute,1);
_bHasStarted=false;
_bEndTimeIsReached=false;
}
protected override void OnExecution(IExecution execution)
{
Log("OnFilled order update at: " + Times[1][0].ToString(),LogLevel.Information);
printLn("OnFilled order update at: " + Time[0].ToString());//tracing to file
int pos =Position.Quantity;
if (Position.MarketPosition==MarketPosition.Short)
pos=-pos;
int lotsAmountForBuy=0,lotsAmountForSell=0;
if (pos>0)
{
if (Math.Abs(pos)* 2> maximumContracts) //maximumContracts=4
lotsAmountForBuy=maximumContracts-Math.Abs(pos);
else
lotsAmountForBuy=Math.Abs(pos);
if (_bEndTimeIsReached)
{
lotsAmountForSell=Math.Abs(pos);
lotsAmountForBuy=0;
cancelLongEntryOrder();
}
else
{
lotsAmountForSell=Math.Abs(pos)+openingPositions; //openingPositions=1
}
}
else if (pos<0)
{
if (Math.Abs(pos) * 2> maximumContracts)
lotsAmountForSell=maximumContracts-Math.Abs(pos);
else
lotsAmountForSell=Math.Abs(pos);
if (_bEndTimeIsReached)
{
lotsAmountForBuy=Math.Abs(pos);
lotsAmountForSell=0;
cancelShortEntryOrder();
}
else
{
lotsAmountForBuy=Math.Abs(pos)+openingPositions;
}
}
else if (pos==0)
{
if (_bEndTimeIsReached)
{
lotsAmountForSell=0;
lotsAmountForBuy=0;
cancelOrders();
}
}
double filledPrice=execution.Price;
double newAvgPrice=Position.AvgPrice;
if (pos==0)
{
newAvgPrice=filledPrice;
}
double buyPrice=newAvgPrice;
double sellPrice=newAvgPrice;
buyPrice= buyPrice - profitTarget* TickSize;//profitTarget=10
sellPrice= sellPrice + profitTarget* TickSize;
Log("Position: " + Position.Quantity.ToString() + "Direction: " + Position.MarketPosition.ToString(),LogLevel.Information);
Log("BuyPrice: " + buyPrice.ToString(),LogLevel.Information);
Log("SellPrice: " + sellPrice.ToString(),LogLevel.Information);
Log("LotsAmountToBuy: " + lotsAmountForBuy.ToString(),LogLevel.Information);
Log("LotsAmountToSell: " + lotsAmountForSell.ToString(),LogLevel.Information);
Log("UnrealizedPnL: " + Position.GetProfitLoss(execution.Price,PerformanceUnit.Currency).ToString(),LogLevel.Information);
printLn("Position: " + Position.Quantity.ToString() + "Direction: " + Position.MarketPosition.ToString());
printLn("BuyPrice: " + buyPrice.ToString());
printLn("SellPrice: " + sellPrice.ToString());
printLn("LotsAmountToBuy: " + lotsAmountForBuy.ToString());
printLn("LotsAmountToSell: " + lotsAmountForSell.ToString());
printLn("UnrealizedPnL: " + Position.GetProfitLoss(execution.Price,PerformanceUnit.Currency).ToString());
if (longEntryOrder != null && longEntryOrder == execution.Order)
{
Log("Buy order is filled at " + execution.Order.AvgFillPrice,LogLevel.Information);
printLn("Buy order is filled at " + execution.Order.AvgFillPrice);
cancelOrders();
if (lotsAmountForBuy!=0)
longEntryOrder=SubmitOrder(0,OrderAction.Buy,OrderType.Limit,lotsAmountForBuy,buyPrice,0,"","");
if (lotsAmountForSell!=0)
shortEntryOrder=SubmitOrder(0,OrderAction.Sell,OrderType.Limit,lotsAmountForSell,sellPrice,0,"","");
}
if (shortEntryOrder != null && shortEntryOrder == execution.Order)
{
Log("Sell order is filled at " + execution.Order.AvgFillPrice,LogLevel.Information);
printLn("Sell order is filled at " + execution.Order.AvgFillPrice);
cancelOrders();
if (lotsAmountForBuy!=0)
longEntryOrder=SubmitOrder(0,OrderAction.Buy,OrderType.Limit,lotsAmountForBuy,buyPrice,0,"","");
if (lotsAmountForSell!=0)
shortEntryOrder=SubmitOrder(0,OrderAction.Sell,OrderType.Limit,lotsAmountForSell,sellPrice,0,"","");
}
if (closePositionOrder!=null && closePositionOrder==execution.Order)
{
Log("Close positoin order is filled at " + execution.Order.AvgFillPrice,LogLevel.Information);
printLn("Close positoin order is filled at " + execution.Order.AvgFillPrice);
}
}
Sending entry orders at : 25.06.2012 9:21:00
Entry BuyPrice: 6265,5
Entry SellPrice: 6267,5
OnFilled order update at: 25.06.2012 9:21:00
Position: 1Direction: Short
BuyPrice: 6262,5
SellPrice: 6272,5
LotsAmountToBuy: 2
LotsAmountToSell: 1
UnrealizedPnL: 0
Sell order is filled at 6267,5
OnFilled order update at: 25.06.2012 9:27:00
Position: 1Direction: Long
BuyPrice: 6257,5
SellPrice: 6267,5
LotsAmountToBuy: 1
LotsAmountToSell: 2
UnrealizedPnL: 0
Buy order is filled at 6262,5
OnFilled order update at: 25.06.2012 9:30:00
Position: 2Direction: Long
BuyPrice: 6255
SellPrice: 6265
LotsAmountToBuy: 2
LotsAmountToSell: 3
UnrealizedPnL: -125
Buy order is filled at 6257,5
OnFilled order update at: 25.06.2012 9:30:00
Position: 4Direction: Long
BuyPrice: 6252,5
SellPrice: 6262,5
LotsAmountToBuy: 0
LotsAmountToSell: 5
UnrealizedPnL: -250
Buy order is filled at 6255
OnFilled order update at: 25.06.2012 9:30:00
Position: 1Direction: Short
BuyPrice: 6257,5
SellPrice: 6267,5
LotsAmountToBuy: 2
LotsAmountToSell: 1
UnrealizedPnL: 0
Sell order is filled at 6262,5
OnFilled order update at: 25.06.2012 9:30:00
Position: 1Direction: Long
BuyPrice: 6252,5
SellPrice: 6262,5
LotsAmountToBuy: 1
LotsAmountToSell: 2
UnrealizedPnL: 0
Buy order is filled at 6257,5
OnFilled order update at: 25.06.2012 9:30:00
Position: 1Direction: Short
BuyPrice: 6257,5
SellPrice: 6267,5
LotsAmountToBuy: 2
LotsAmountToSell: 1
UnrealizedPnL: 0
Sell order is filled at 6262,5
OnFilled order update at: 25.06.2012 9:30:00
Position: 1Direction: Long
BuyPrice: 6252,5
SellPrice: 6262,5
LotsAmountToBuy: 1
LotsAmountToSell: 2
UnrealizedPnL: 0
Buy order is filled at 6257,5
The rest of the log file is filled with the repetition of selected above in bold.
It just keeps executing buy limit at 6257.5 and sell limit order at 6262.5 in the loop.
Both prices are within ranges of 09:30-09:31 bar. I may believe that orders might have played ping pong couple of times during this minute, but not 1000 times.
So from what I gathered - I would assume that it is some kind of simulation system bug. But I do believe that you have tested it extensively, so I am looking for any suggestion or hint as to where might be the problem.

Comment