Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy not opening in strategy analyzer?

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

    Strategy not opening in strategy analyzer?

    Very simple strategy as I'm still learning the coding. However, no matter what I do, I cannot get this strategy to appear in the analyzer. I've tried saving, making a new strat, compiling over and over, and just about everything I can think of. Is there an issue with the code that Ninjascript won't tell me about?

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class test : Strategy
        {
            private SMA fast;
            private SMA slow;
              private int stopLoss = 30;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"test";
                    Name                                        = "test";
                    Calculate                                    = Calculate.OnBarClose;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = false;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 1;
                    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;
                    AddDataSeries(Data.BarsPeriodType.Minute, 1);
                }
                else if (State == State.Configure)
                {
                    Description = "An example of a MA crossover strategy.";
                    Name = "MovingAverageCrossover";
                    fast = SMA(11);
                    slow = SMA(130);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar < slow.Period)
                return;
    
            // For Long Position
            if (CrossAbove(fast, slow, 1))
            {
                if (Position.MarketPosition == MarketPosition.Short)
                    ExitShort(stopLoss, "ExitShort", "Short");
    
                EnterLong(stopLoss, "Long");
            }
    
            // For Short Position
            if (CrossBelow(fast, slow, 1))
            {
                if (Position.MarketPosition == MarketPosition.Long)
                    ExitLong(stopLoss, "ExitLong", "Long");
    
                EnterShort(stopLoss, "Short");
            }//Add your custom strategy logic here.
            }
            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
            public int Fast
            { get; set; }
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
            public int Slow
            { get; set; }
            #endregion
        }
    }
    ​

    #2
    Hello RehmaZ,

    Thank you for your post.

    Do you receive any errors on the Log tab of the Control Center? Are there any errors in the NinjaScript Editor?
    Please right-click on your strategy in the Strategies folder from the right-hand side of the NinjaScript Editor - do you have "Exclude From Compilation" checked? If so, please select this option to uncheck it and include the strategy in compilation, and then close and reopen the Strategy Analyzer to test if it is in the list.

    I look forward to your reply.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    47 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    141 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X