When trying to import the script at the bottom, I get the error this ninjascript archive was made from an older, incompatible version of Ninja trader
Therefore I can't share an exported version, nor test it.
Here's your OnBarUpdate snippet:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((Position.MarketPosition == MarketPosition.Flat)
&& (Close[0] > Open[0]))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
StopLossMode = 0;
}
// Set 2
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 0))
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice + (-10 * TickSize)) , "", "");
}
// Set 3
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 1))
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), Position.AveragePrice, "", "");
}
// Set 4
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 2))
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice + (10 * TickSize)) , "", "");
}
// Set 5
if ((Position.MarketPosition == MarketPosition.Long)
&& (Close[0] >= (Position.AveragePrice + (10 * TickSize)) )
&& (StopLossMode == 0))
{
StopLossMode = 1;
}
// Set 6
if ((Position.MarketPosition == MarketPosition.Long)
&& (Close[0] >= (Position.AveragePrice + (20 * TickSize)) )
&& (StopLossMode == 1))
{
StopLossMode = 2;
}
}
I've replaced all the 'MultiStepBreakeven' instances with 'MultiStepTrailingStop',
and I've completed your code to include the Short logic below:
What's wrong?
How to fix it?
What about the StopLossMode statements for the Short Logic?
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
[B]//LONG ORDERS[/B]
// Set 1
if ((Position.MarketPosition == MarketPosition.Flat)
&& (High[0] > High[1])
&& (High[1] > High[2])
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0))
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0)))
{
EnterLongLimit(Convert.ToInt32(DefaultQuantity), 0, "");
StopLossMode = 0;
}
// Set 2
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 0)
&& (High[1] > High[2])
&& (High[0] > High[1])
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice + (-10 * TickSize)) , "", "");
}
// Set 3
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 1)
&& (High[1] > High[2])
&& (High[0] > High[1])
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), Position.AveragePrice, "", "");
}
// Set 4
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 2)
&& (High[1] > High[2])
&& (High[0] > High[1])
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), (Position.AveragePrice + (10 * TickSize)) , "", "");
}
// Set 5
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 0)
&& (Close[0] >= (Position.AveragePrice + (10 * TickSize)) )
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
StopLossMode = 1;
}
// Set 6
if ((Position.MarketPosition == MarketPosition.Long)
&& (StopLossMode == 1)
&& (Close[0] >= (Position.AveragePrice + (20 * TickSize)) )
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
StopLossMode = 2;
}
[B]//SHORT ORDERS[/B]
// Set 7
if ((Position.MarketPosition == MarketPosition.Flat)
&& (Low[0] < Low[1])
&& (Low[1] < Low[2])
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0))
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0)))
{
EnterShortLimit(Convert.ToInt32(DefaultQuantity), 0, "");
StopLossMode = 0;
}
// Set 8
if ((Position.MarketPosition == MarketPosition.Short)
&& (StopLossMode == 0)
&& (Low[0] < Low[1])
&& (Low[1] < Low[2])
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
ExitShortStopMarket(Convert.ToInt32(DefaultQuantit y), (Position.AveragePrice + (10 * TickSize)) , "", "");
}
// Set 9
if ((Position.MarketPosition == MarketPosition.Short)
&& (StopLossMode == 1)
&& (Low[0] < Low[1])
&& (Low[1] < Low[2])
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
ExitShortStopMarket(Convert.ToInt32(DefaultQuantit y), Position.AveragePrice, "", "");
}
// Set 10
if ((Position.MarketPosition == MarketPosition.Short)
&& (StopLossMode == 2)
&& (Low[0] < Low[1])
&& (Low[1] < Low[2])
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
ExitShortStopMarket(Convert.ToInt32(DefaultQuantit y), (Position.AveragePrice + (-10 * TickSize)) , "", "");
}
// Set 11
if ((Position.MarketPosition == MarketPosition.Short)
&& (StopLossMode == 0)
&& (Close[0] >= (Position.AveragePrice + (-10 * TickSize)) )
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
StopLossMode = 1;
}
// Set 12
if ((Position.MarketPosition == MarketPosition.Short)
&& (StopLossMode == 1)
&& (Close[0] >= (Position.AveragePrice + (-20 * TickSize)) )
&& (Times[0][0].TimeOfDay <= new TimeSpan(11, 50, 0))
&& (Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)))
{
StopLossMode = 2;
}
}
Full unaltered format code:

Comment