Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CS0246 StateChange Could Not Be Found

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

    CS0246 StateChange Could Not Be Found

    I'm working on an Add On and get this error message. I've received this message on two different computers.
    QuickTrade.cs The type or namespace name 'StateChange' could not be found (are you missing a using directive or an assembly reference?) CS0246 22 47

    I've Repaired NInjaTrader which didn't fix it. I've seen that a .DLL reference could have something to do with it, but I'm not sure where to download it.

    Any help would be much appreciated as this is my first script.

    #2
    Hello AmazonGuy,

    Welcome to the NinjaTrader forums!

    Is the class in the NinjaTrader.NinjaScript.AddOns namespace?

    Does the class inherit from AddonBase?

    Have you removed any of the default using statements after creating the script with the NinjaScript Editor?


    Below I am providing a link to a support article with helpful resources on getting started with C# and NinjaScript.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey Chelsea, I did not remove any of the default using statements. I do use the Addons namespace. It does inherit from AddonBase. Here is the code I have.

      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.Gui.Tools;
      #endregion

      //This namespace holds Mar****rderHotkey scripts
      namespace NinjaTrader.NinjaScript.AddOns// Correct namespace
      {
      public class Mar****rderHotkey : AddOnBase // Inherits from AddOnBase
      {
      protected override void OnStateChange(StateChange state)
      {
      if (state == StateChange.SetDefaults)
      {
      Description = "Places market orders with hotkeys.";
      Name = "Mar****rderHotkey";
      IsOverlaying = true;
      }
      }

      protected override void OnBarUpdate()
      {
      // No need to do anything on bar update unless you have other logic.
      }

      protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
      {
      base.OnKeyDown(e); // Important: Call the base method!

      if (e.Control && !e.Alt) // CTRL key pressed for BUY
      {
      EnterLongMarket();
      Print("CTRL Key Pressed - Market Buy Order Sent");
      }
      else if (!e.Control && e.Alt) // ALT key pressed for SELL
      {
      EnterShortMarket();
      Print("ALT Key Pressed - Market Sell Order Sent");
      }
      }
      }
      }

      Comment


        #4
        "Mar****rderHotKey" Market Order Hot Key. Is what is blanked out *****

        Comment


          #5
          Hello AmazonGuy,

          OnStateChange() does not have any parameters.
          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.


          Change:
          protected override void OnStateChange(StateChange state)

          To:
          protected override void OnStateChange()


          To confirm you are making your own custom addon window and you are not making a strategy or indicator, correct?​

          OnBarUpdate() and OnKeyDown() are not valid override methods for an addon, however I would expect OnStateChange() to compile ok with the parameter removed.

          OnBarUpdate() would be an override method for strategies and indicators, not addons.


          You can use a BarsRequest if you are trying to get data in an addon.
          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.


          IsOverlaying is not a valid property for any NinjaScript type. There is an IsOverlay for indicators specifically.
          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.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thank you for the help, I'm going to take time and study what you've sent and try to fix it. Could you confirm, if I want to make a script that allows me to place a limit or stop order on the chart by holding CTRL and left clicking, should I use a Strategy instead of an Add on?

            Comment


              #7
              Hello AmazonGuy,

              That depends. Do you want a separate addon window or do you want to apply the script to a chart?

              If this is on a chart, I would recommend making an indicator.

              Below are links to an example of placing orders from a button click in an indicator and an example of capturing keypresses in an indicator.

              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thank you, yes I want to apply it to a chart so I will create it as an indicator.

                Comment

                Latest Posts

                Collapse

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