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 NullPointStrategies, Today, 05:17 AM
    0 responses
    23 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    120 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    63 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    45 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X