Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New Strategy not visible in Strategy Analyzer

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

    New Strategy not visible in Strategy Analyzer

    I have a new Strategy that compiled without any errors reported but it is not available in Strategy Analyzer to backtest. It is visible in NinjaScript Editor Strategies folder and is not dimmed out. Will someone please take a look to assist me? I don't see what is causing the problem. Here is my script.

    region Using declarations
    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies;
    #endregion

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MES355BullishEntry : Strategy
    {
    private bool enteredToday = false;
    private double bullishTicks = 0;
    private int lastTradeDate = -1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "MES355BullishEntry";
    Calculate = Calculate.OnBarClose;
    IsExitOnSessionCloseStrategy = false;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsInstantiatedOnEachOptimizationIteration = false;
    AddDataSeries(Data.BarsPeriodType.Day, 1); // Add daily series
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0) return; // Only process on the primary (intraday) series
    if (CurrentBar < 2 || BarsArray[1].Count < 3) return; // Ensure enough data

    // Reset at new day
    if (ToDay(Time[0]) != lastTradeDate)
    {
    enteredToday = false;
    lastTradeDate = ToDay(Time[0]);
    }

    // Check entry conditions
    if (!enteredToday &&
    ToTime(Time[0]) == 155500 && // 3:55:00 PM ET
    GetBullishTicks() > 40)
    {
    EnterLong();
    enteredToday = true;
    }

    // Exit next day at 9:30 AM
    if (Position.MarketPosition == MarketPosition.Long &&
    ToTime(Time[0]) == 93000)
    {
    ExitLong();
    }
    }

    private double GetBullishTicks()
    {
    // Use daily series to compute bullish ticks from last 2 days
    double day1Change = Closes[1][1] - Opens[1][1]; // Yesterday
    double day2Change = Closes[1][2] - Opens[1][2]; // Day before yesterday

    // Convert to ticks (MES tick size is 0.25)
    bullishTicks = (day1Change + day2Change) / TickSize;

    return bullishTicks;
    }
    }
    }


    #2
    Hello dtrader760,

    AddDataSeries() cannot be called in State.SetDefaults. It is required to call this from State.Configure.

    From the Desktop SDK:
    "Warning
    This method should ONLY be called from the OnStateChange() method during State.Configure.​"
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    Further, anytime a script is not appearing in the Available list or Strategies drop-down, this means there is a run-time error that will appear on the Log tab of the Control Center.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X