i've been struggling with a snippet for a few days and here i come looking for some clarifications.
I'm not going to show the full code but just the "fun" part.
The first code i'm showing is working and it is this:
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice,
int quantity, Cbi.MarketPosition marketPosition)
{
//... other part above tested working
if (position.MarketPosition == MarketPosition.Flat && trading_time){ //trading is a range of hours
Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
if (lastTrade.ProfitPips > 0){ //if last position was profitable open in the same direction
if (lastentry.Name == "entrylong"){ //lastentry is set in OnOrderUpdate like is shown in all examples of code here XD
EnterLong(1, "entrylong");
}
}
}
Trivial code right?
I wanted to test an opposite situation where "if the last position is profitable then open a reverse short". Well, The platform freezes and i need to kill it with task manager.
The code crashing is this:
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice,
int quantity, Cbi.MarketPosition marketPosition)
{
//... other part above tested working
if (position.MarketPosition == MarketPosition.Flat && trading_time){ //trading is a range of hours
Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
if (lastTrade.ProfitPips > 0){ //if last position was profitable open REVERSED
if (lastentry.Name == "entrylong"){ //lastentry is set in OnOrderUpdate like is shown in all examples of code here XD
EnterShort(1, "entryshort"); //changing the direction here blows up the ninjatrader backtest.
}
}
}
kind regards,
ross94


Comment