My strategy considers price levels, looks at current price, determines the closest level above and closest level below and then if certain criteria is met (it just needs to be a minimum distance away from that price) I want it to create a limit short and a limit long above and below at the respective levels.
private void EvaluateAndPlaceOrders()
{
if (CurrentBar < AtrPeriod)
return;
double currentPrice = Close[0];
double atrValue = ATR(AtrPeriod)[0];
double closestSupport, closestResistance;
AnalyzePricePosition(currentPrice, out closestSupport, out closestResistance);
// Clear stale orders
if (longEntryOrder != null && (
longEntryOrder.OrderState == OrderState.Filled ||
longEntryOrder.OrderState == OrderState.Cancelled ||
longEntryOrder.OrderState == OrderState.Rejected))
{
longEntryOrder = null;
}
if (shortEntryOrder != null && (
shortEntryOrder.OrderState == OrderState.Filled ||
shortEntryOrder.OrderState == OrderState.Cancelled ||
shortEntryOrder.OrderState == OrderState.Rejected))
{
shortEntryOrder = null;
}
double minDistance = MinAtrDistanceForReversal * atrValue;
// Place long limit order if price is sufficiently above closest support
if (!double.IsNaN(closestSupport))
{
double distanceFromSupport = currentPrice - closestSupport;
if (distanceFromSupport >= minDistance &&
(longEntryOrder == null || longEntryOrder.OrderState == OrderState.Cancelled))
{
double longLimitPrice = closestSupport - entryOffset;
longEntryOrder = EnterLongLimit(0, true, 1, longLimitPrice, "Dynamic Long");
Print($"Placed Long Limit @ {longLimitPrice} | From Support: {closestSupport}, Distance: {distanceFromSupport:F2}");
}
}
// Place short limit order if price is sufficiently below closest resistance
if (!double.IsNaN(closestResistance))
{
double distanceFromResistance = closestResistance - currentPrice;
if (distanceFromResistance >= minDistance &&
(shortEntryOrder == null || shortEntryOrder.OrderState == OrderState.Cancelled))
{
double shortLimitPrice = closestResistance + entryOffset;
shortEntryOrder = EnterShortLimit(0, true, 1, shortLimitPrice, "Dynamic Short");
Print($"Placed Short Limit @ {shortLimitPrice} | From Resistance: {closestResistance}, Distance: {distanceFromResistance:F2}");
}
}
}
I think i am running into the issue where ninjatrader does not allow for this based on Methods that generate orders to enter a position will be ignored if:
The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
Is there anyway i could achieve this still with a a different method?