The exact error is OnExecutionUpdate(NinjaTrader.Cbi.Execution):no suitable method found to override
I have posted my script below. I've tried 'OnOrderUpdate' as well and get the same error. Maybe I need both? Of course any and all help is greatly appreciated!
Code:
namespace NinjaTrader.NinjaScript.Strategies
{
public class AvgCrossJES : Strategy
{
private double slope;
private bool isBullish;
private bool isBearish;
public bool TheBool;
private EMA ema6;
private EMA ema12;
private EMA ema100;
private EMA ema200;
private double stopLoss;
private double profitTarget;
private const double initialRisk = 100.0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "AvgCrossJES";
Calculate = Calculate.OnPriceChange;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Day;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries("MNQ 09-24", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last); //BarsinProgress = 1
AddDataSeries("MNQ 09-24", Data.BarsPeriodType.Minute, 15, Data.MarketDataType.Last); //BarsinProgress = 2
AddDataSeries("MNQ 09-24", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last); // BarsinProgress = 3
}
}
protected override void OnBarUpdate()
{
//Add your custom strategy logic here.
if (BarsInProgress == 0)
return;
// Add Indicators
ema100 = EMA(BarsArray[2],100); // 15 minute EMA
ema200 = EMA(BarsArray[2],200); // 15 minute EMA
ema6 = EMA(BarsArray[3],6); // 5 minute EMA
ema12 = EMA(BarsArray[3],12); //5 minute EMA
// Ensure we're on the correct bar series
if (BarsInProgress == 1) // 60-minute chart
{
// Calculate the linear regression slope
slope = LinRegSlope(200)[0];
isBullish = slope > 0;
isBearish = slope < 0;
// Print(slope);
}
else if (BarsInProgress == 1) // 15-minute chart
{
// Check price within 100 and 200 EMA range
if(isBullish)
{
if(ema100[1] > ema200[1] && Close[1] <= ema100[1] & Close[1] >= ema200[1])
{
if (BarsInProgress == 2)
{
// Long Condition
if (isBullish && CrossAbove(ema6, ema12, 1))
{
double swingHigh = Highs[2][1]; // Simplified example; use more robust swing detection
double swingLow = Lows[2][1];
stopLoss = isBullish ? swingLow - (2 * TickSize) : swingHigh + (2 * TickSize);
profitTarget = initialRisk / (stopLoss - Close[0]);
EnterLong("LongEntry");
}
}
}
else if (isBearish)
{
if(ema100[1] < ema200[1] && Close[1] >= ema100[1] & Close[1] <= ema200[1])
{
if (BarsInProgress == 2)
// Short Condition
if (isBearish && CrossBelow(ema6, ema12, 1))
{
double swingHigh = Highs[2][1]; // Simplified example; use more robust swing detection
double swingLow = Lows[2][1];
stopLoss = isBearish ? swingHigh + (2 * TickSize) : swingLow - (2 * TickSize);
profitTarget = initialRisk / (stopLoss - Close[0]);
EnterShort("ShortEntry");
}
}
}
}
}
}
protected override void OnExecution(Execution execution)
{
if (Position.MarketPosition == MarketPosition.Long)
{
SetStopLoss("LongEntry", CalculationMode.Price, stopLoss, false);
SetProfitTarget("LongEntry", CalculationMode.Price, Close[0] + profitTarget);
}
else if (Position.MarketPosition == MarketPosition.Short)
{
SetStopLoss("ShortEntry", CalculationMode.Price, stopLoss, false);
SetProfitTarget("ShortEntry", CalculationMode.Price, Close[0] - profitTarget);
}
}
}
}

Comment