Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnExecutionUpdate CS0115 Error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    OnExecutionUpdate CS0115 Error

    Hello - I'm trying to code out my strategy and I'm running into the CS0115 error when writing the OnExecutionUpdate part of the script.


    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);
    }
    }
    }
    }​

    #2
    Hello Jschmelz,

    Just as a heads up the error codes you see are general C# error codes which you can search for only to see the reasons. This error code means no suitable method found to override. To use OnExecutionUpdate you need to have the correct parameters, you can see an example of it in the help guide: https://ninjatrader.com/support/help...tionupdate.htm

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    127 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X