So far ChatGPT help me with the code, but the strat doesnt make any entry but the Output log is correct:
region Using declarations
using System;
using NinjaTrader.Cbi;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript.Strategies;
using NinjaTrader.NinjaScript.Indicators;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class VolumeBreakoutScalp : Strategy
{
private EMA ema50;
private bool reentryAllowed = false;
private bool inReentry = false;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "VolumeBreakoutScalp";
Calculate = Calculate.OnBarClose;
IsInstantiatedOnEachOptimizationIteration = false;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IncludeCommission = true;
}
else if (State == State.Configure)
{
SetStopLoss("VolReversalLong", CalculationMode.Ticks, 32, false);
SetStopLoss("VolReversalShort", CalculationMode.Ticks, 32, false);
SetStopLoss("ReentryLong", CalculationMode.Ticks, 32, false);
SetStopLoss("ReentryShort", CalculationMode.Ticks, 32, false);
}
else if (State == State.DataLoaded)
{
ema50 = EMA(Close, 50);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 2)
return;
// Filtro horario opcional
// if (ToTime(Time[0]) < 093500 || ToTime(Time[0]) > 154500)
// return;
double currentVolume = Volume[0];
double prevVolume = Volume[1];
double currentClose = Close[0];
double prevClose = Close[1];
double emaValue = ema50[0];
// Debug
Print("Vol actual: " + currentVolume + " | Vol anterior: " + prevVolume);
Print("Close actual: " + currentClose + " | EMA: " + emaValue);
// Dirección contraria (vela opuesta)
bool bullishBar = Close[0] > Open[0];
bool bearishBar = Close[0] < Open[0];
bool previousBullish = Close[1] > Open[1];
bool previousBearish = Close[1] < Open[1];
// Long setup: vela verde, mayor volumen que anterior, la anterior era roja y estamos sobre la EMA
if (!inReentry && Position.MarketPosition == MarketPosition.Flat)
{
if (currentVolume > prevVolume && bullishBar && previousBearish && Close[0] > emaValue)
{
EnterLong(1, "VolReversalLong");
}
// Short setup: vela roja, mayor volumen, anterior verde, y estamos bajo la EMA
else if (currentVolume > prevVolume && bearishBar && previousBullish && Close[0] < emaValue)
{
EnterShort(1, "VolReversalShort");
}
}
// Reentrada tras stop
if (reentryAllowed && Position.MarketPosition == MarketPosition.Flat)
{
if (currentVolume > prevVolume && bullishBar && previousBearish && Close[0] > emaValue)
{
EnterLong(2, "ReentryLong");
inReentry = true;
reentryAllowed = false;
}
else if (currentVolume > prevVolume && bearishBar && previousBullish && Close[0] < emaValue)
{
EnterShort(2, "ReentryShort");
inReentry = true;
reentryAllowed = false;
}
}
}
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity,
MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order == null || execution.Order.OrderState != OrderState.Filled)
return;
// Si una orden principal fue cerrada y estamos flat → permitir reentrada
if ((execution.Order.Name == "VolReversalLong" || execution.Order.Name == "VolReversalShort") &&
Position.MarketPosition == MarketPosition.Flat)
{
reentryAllowed = true;
Print("Reentrada habilitada");
}
// Si una reentrada fue ejecutada → desactivar flag
if (execution.Order.Name == "ReentryLong" || execution.Order.Name == "ReentryShort")
{
inReentry = false;
Print("Reentrada completada");
}
}
}
}
There is something wrong in this code?
Why entries are not taking?
Thx in advance

Comment