Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Strategy not showing on the strategy list.

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

    Custom Strategy not showing on the strategy list.

    Trying to figure why the strategy I just did won't show up on the list. It's compiled correctly and no errors in the log.

    Code:
    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.NinjaScript.StrategyAnalyzer;
    
    namespace NinjaTrader.NinjaScript.StrategyAnalyzer
    {
        public class AIBot : StrategyBase // Change inheritance to StrategyBase
        {
            private int consecutiveBars;
            private double lastClose;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"Enter the description for your new custom Strategy here.";
                    Name = "AIBot"; // Renamed the strategy to AIBot
                    BarsRequiredToTrade = 4;
                    Calculate = Calculate.OnEachTick;
                    IsOverlay = false;
                    EntryHandling = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy = true; // Set to true to exit positions at session close
                    consecutiveBars = 0;
                    lastClose = 0;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar < BarsRequiredToTrade)
                    return;
    
                if (Close[0] > Open[0] && Close[1] > Open[1] && Close[2] > Open[2]) // Bullish condition
                {
                    consecutiveBars++;
                    if (consecutiveBars == 3 && Close[3] > lastClose)
                    {
                        EnterLong();
                    }
                }
                else if (Close[0] < Open[0] && Close[1] < Open[1] && Close[2] < Open[2]) // Bearish condition
                {
                    consecutiveBars++;
                    if (consecutiveBars == 3 && Close[3] < lastClose)
                    {
                        EnterShort();
                    }
                }
                else
                {
                    consecutiveBars = 0;
                }
    
                lastClose = Close[0];
            }
        }
    }
    ​

    #2
    Hello Johndc,

    Thanks for your post.

    The namespace and class are incorrect for a custom NinjaScript strategy.

    The strategy namespace should be changed from namespace.NinjaTrader.NinjaScript.StrategyAnalyzer to the namespace below.

    namespace NinjaTrader.NinjaScript.Strategies

    The class name should be changed from public class AIBot: StrategyBase to the class below.

    public class AIBot : Strategy

    See the SampleMACrossover strategy that comes default with NinjaTrader for an example of what the namespace and class of a custom NinjaScript strategy looks like. To view the script, open a New > NinjaScript Editor window, open the Strategies folder, and double-click on the SampleMACrossover file.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks, that work!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      98 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      160 views
      0 likes
      Last Post loganjarosz123  
      Working...
      X