Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA/ Max Indicator code won't compile

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

    SMA/ Max Indicator code won't compile

    I have code for an indicator using the SMA of the max and min indicators. when I try to compile I get error code 0246 saying that Max and Min cannot be found, are you missing a directive or assembly reference? Max and Min are native indicators to NinjaTrader, I don't know why it can't find it? Comes up on the lines. private Max max; and private Min min:



    namespace MyNamespace

    {

    public class Trend : Indicator

    {

    private int periodSMA = 8;

    private int periodMax = 3;

    private int periodMin = 3;

    private Max max;

    private Min min;

    private SMA smaMax;

    private SMA smaMin;




    protected override void Initialize()

    {

    max = Max(High, periodMax);

    min = Min(Low, periodMin);

    smaMax = SMA(max, periodSMA);

    smaMin = SMA(min, periodSMA);

    }

    #2
    Hello JamieHendrix,

    The code you are showing is for NinjaTrader 7, such as the Initialize() override, but your post is in the NinjaTrader 8 section of the forums.

    May I confirm this code is a NinjaTrader 7 script?

    You have:
    "namespace MyNamespace"

    This is not the indicator namespace. The indicator class tools are in the Indicator namespace. May I confirm that you have generated the indicator from the NinjaScript Editor and that you are not trying to create this outside of the NinjaScript Editor?
    Have you intentionally and incorrectly changed the namespace?

    You mentioned there is a compile error. What is the compile error? May we have a screenshot?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea. I do indeed have Ninjatrader 8. My skills are very rusty and weren't all that great even before they rusted. I am trying to compile an indicator not a strategy although the indicator is part of a strategy that I will create later. I am trading this live right now mostly manual entry and I want to automate as much as I can. its a simple indicator but I definitely need to be coding it for version 8.
      The error code is error code 2046. says I'm missing a directive or assembly reference. I seem to be having trouble with the screenshot. my trading computer is a Dell and it refuses to play well with this Mac.

      The error is referring to the Max and Min indicators. I pasted the rest of the code here. it didn't paste completely accurately as far as spacing but the content is there.




      namespace MyNamespace

      {

      public class Trend : Indicator

      {

      private int periodSMA = 8;

      private int periodMax = 3;

      private int periodMin = 3;

      private Max max;

      private Min min;

      private SMA smaMax;

      private SMA smaMin;




      protected override void Initialize()

      {

      max = Max(High, periodMax);

      min = Min(Low, periodMin);

      smaMax = SMA(max, periodSMA);

      smaMin = SMA(min, periodSMA);

      }




      protected override void OnBarUpdate()

      {

      if (CurrentBar < Math.Max(periodSMA, Math.Max(periodMax, periodMin)))

      {

      return;

      }




      if (smaMax[0] > smaMax[1] && smaMin[0] > smaMin[1])

      {

      Bars[0].Pen.Color = Color.LimeGreen;

      DrawLine("HighRising" + CurrentBar, true, Bars[0].High, Bars[0].High, Color.LimeGreen);

      DrawLine("LowRising" + CurrentBar, true, Bars[0].Low, Bars[0].Low, Color.LimeGreen);




      if (CurrentBar == Bars.Count - 1)

      {

      DrawText("CurrentRising" + CurrentBar, "Current Rising", 0, Bars[0].High, Color.LimeGreen);

      }

      else if (smaMax[1] <= smaMax[2] && smaMin[1] <= smaMin[2])

      {

      DrawText("PreviousRising" + CurrentBar, "Previous Rising", 0, Bars[0].High, Color.LimeGreen);

      }

      }

      else if (smaMax[0] < smaMax[1] && smaMin[0] < smaMin[1])

      {

      Bars[0].Pen.Color = Color.White;

      DrawLine("HighFalling" + CurrentBar, true, Bars[0].High, Bars[0].High, Color.White);

      DrawLine("LowFalling" + CurrentBar, true, Bars[0].Low, Bars[0].Low, Color.White);




      if (CurrentBar == Bars.Count - 1)

      {

      DrawText("CurrentFalling" + CurrentBar, "Current Falling", 0, Bars[0].Low, Color.White);

      }

      else if (smaMax[1] >= smaMax[2] && smaMin[1] >= smaMin[2])

      {

      DrawText("PreviousFalling" + CurrentBar, "Previous Falling", 0, Bars[0].Low, Color.White);

      }

      }

      }

      }

      }


      Comment


        #4
        Hello JamieHendrix,

        I recommend you start this script over and create the script in the NinjaScript Editor. This will automatically create the framework and will use the correct namespace.

        Initialize is not a NinjaTrader 8 method. That is a NinjaTrader 7 method. NinjaTrader 8 uses OnStateChange() and does not have an Initialize() override.


        State.SetDefaults is used for setting defaults.
        State.Configure is where AddDataSeries() can be called.
        State.DataLoaded is when the strategy is able to start (similar to OnStartUp() in NinjaTrader 7).

        MAX() is all capital letters. MIN() is all capital letters.



        These can only be called if the script is in the proper namespace and has the NinjaScript tools available.

        NInjaTrader 8 uses Draw.Text() and not DrawText().


        If this is a NinjaTrader 8 script, please use NinjaTrader 8 methods and properties from the help guide.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Will do. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          559 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          546 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X