Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Checking for cross over conditions and generating an alert

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

    #16
    Hi Crosscreek,

    Unfortunately we can't assist with just an error code #. Let us know the offending line of code and the descriptive text found under the Error column. You can also attach the indicator file and I'll take a look.
    Ryan M.NinjaTrader Customer Service

    Comment


      #17
      Line 20, column 18
      public class CrossAlert : Indicator

      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      /// <summary>
      ///
      /// </summary>
      [Description("")]
      [Gui.Design.DisplayName("")]
      public class CrossAlert : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int fast = 5; // Default setting for Fast
      private int slow = 15; // Default setting for Slow
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      Fast = 5;
      Slow = 15;
      CalculateOnBarClose = true;
      Overlay = true;
      PriceTypeSupported = false;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if (CrossAbove(EMA(Fast), EMA(Slow), 1))
      {
      // Mark the cross above bar with a green dot
      DrawDot("Dot1 " + CurrentBar, true, 0, High[0] + TickSize, Color.Green);

      // Only generate an alert on real-time data
      if (!Historical)
      Alert(Time[0].ToString(), NinjaTrader.Cbi.Priority.Medium, "Cross Above", Cbi.Core.InstallDir + @"\sounds\Alert1.wav", 0, Color.Black, Color.Yellow);
      }
      else if (CrossBelow(EMA(Fast), EMA(Slow), 1))
      {
      // Mark the cross below bar with a red dot
      DrawDot("Dot2 " + CurrentBar, true, 0, Low[0] - TickSize, Color.Red);

      // Only generate an alert on real-time data
      if (!Historical)
      Alert(Time[0].ToString(), NinjaTrader.Cbi.Priority.Medium, "Cross Below", Cbi.Core.InstallDir + @"\sounds\Alert2.wav", 0, Color.Yellow, Color.Black);
      }
      }

      #region Properties

      [Description("Fast period")]
      [Category("Parameters")]
      public int Fast
      {
      get { return fast; }
      set { fast = Math.Max(1, value); }
      }

      [Description("Slow period")]
      [Category("Parameters")]
      public int Slow
      {
      get { return slow; }
      set { slow = Math.Max(1, value); }
      }
      #endregion
      }
      }

      #region NinjaScript generated code. Neither change nor remove.
      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      public partial class Indicator : IndicatorBase
      {
      private CrossAlert[] cacheCrossAlert = null;

      private static CrossAlert checkCrossAlert = new CrossAlert();

      /// <summary>
      ///
      /// </summary>
      /// <returns></returns>
      public CrossAlert CrossAlert(int fast, int slow)
      {
      return CrossAlert(Input, fast, slow);
      }

      /// <summary>
      ///
      /// </summary>
      /// <returns></returns>
      public CrossAlert CrossAlert(Data.IDataSeries input, int fast, int slow)
      {
      if (cacheCrossAlert != null)
      for (int idx = 0; idx < cacheCrossAlert.Length; idx++)
      if (cacheCrossAlert[idx].Fast == fast && cacheCrossAlert[idx].Slow == slow && cacheCrossAlert[idx].EqualsInput(input))
      return cacheCrossAlert[idx];

      lock (checkCrossAlert)
      {
      checkCrossAlert.Fast = fast;
      fast = checkCrossAlert.Fast;
      checkCrossAlert.Slow = slow;
      slow = checkCrossAlert.Slow;

      if (cacheCrossAlert != null)
      for (int idx = 0; idx < cacheCrossAlert.Length; idx++)
      if (cacheCrossAlert[idx].Fast == fast && cacheCrossAlert[idx].Slow == slow && cacheCrossAlert[idx].EqualsInput(input))
      return cacheCrossAlert[idx];

      CrossAlert indicator = new CrossAlert();
      indicator.BarsRequired = BarsRequired;
      indicator.CalculateOnBarClose = CalculateOnBarClose;
      #if NT7
      indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
      indicator.MaximumBarsLookBack = MaximumBarsLookBack;
      #endif
      indicator.Input = input;
      indicator.Fast = fast;
      indicator.Slow = slow;
      Indicators.Add(indicator);
      indicator.SetUp();

      CrossAlert[] tmp = new CrossAlert[cacheCrossAlert == null ? 1 : cacheCrossAlert.Length + 1];
      if (cacheCrossAlert != null)
      cacheCrossAlert.CopyTo(tmp, 0);
      tmp[tmp.Length - 1] = indicator;
      cacheCrossAlert = tmp;
      return indicator;
      }
      }
      }
      }

      // This namespace holds all market analyzer column definitions and is required. Do not change it.
      namespace NinjaTrader.MarketAnalyzer
      {
      public partial class Column : ColumnBase
      {
      /// <summary>
      ///
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.CrossAlert CrossAlert(int fast, int slow)
      {
      return _indicator.CrossAlert(Input, fast, slow);
      }

      /// <summary>
      ///
      /// </summary>
      /// <returns></returns>
      public Indicator.CrossAlert CrossAlert(Data.IDataSeries input, int fast, int slow)
      {
      return _indicator.CrossAlert(input, fast, slow);
      }
      }
      }

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      public partial class Strategy : StrategyBase
      {
      /// <summary>
      ///
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.CrossAlert CrossAlert(int fast, int slow)
      {
      return _indicator.CrossAlert(Input, fast, slow);
      }

      /// <summary>
      ///
      /// </summary>
      /// <returns></returns>
      public Indicator.CrossAlert CrossAlert(Data.IDataSeries input, int fast, int slow)
      {
      if (InInitialize && input == null)
      throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

      return _indicator.CrossAlert(input, fast, slow);
      }
      }
      }
      #endregion

      Comment


        #18
        What is the error message and what line is causing it?
        Ryan M.NinjaTrader Customer Service

        Comment


          #19
          Getting

          Line 20, column 18
          line 20 is "public class CrossAlert : Indicator"

          error code CS0101, clicked for info then get:

          "Unfortunately we do not have NinjaScript context based Help information on this specific error code. You can check the Microsoft MSDN site section on error codes for futher information."

          Comment


            #20
            Hi Crosscreek,

            Below are not valid statement in the Initialize() method:
            Fast = 5;
            Slow = 15;


            Generally NinjaTrader does not provide debugging or custom coding service. We are glad to guide in the right direction or assist if there is any particular issue, but cannot resolve all types of coding errors.

            If you have further issues with this indicator, please see the link below for a NinjaScript consultant who can be hired to debug for you.

            Ryan M.NinjaTrader Customer Service

            Comment


              #21
              Ok, thanks. It's a little confusing because that is exactly the line of code that is in the original, which works fine. I don't get why changing sma to ema does not work, but I guess there is nothing I can do about this.

              Comment


                #22
                I figured out what was wrong, I did not change the title in the line of code to a new name.

                Comment


                  #23
                  crossareat.zip didn't work on my ninja 7 error

                  when i try to complie it i get error .can u help get it work i use ninja 7


                  // Mark the cross below bar with a red dot
                  DrawDot(Time[0].ToString(), 0, Low[0] - TickSize, Color.Red);

                  Comment


                    #24
                    Julian, there is an extra parameter with all the drawing objects for NinjaTrader 7: the autoscale parameter.

                    Please try this line instead:
                    Code:
                    DrawDot(Time[0].ToString(), true, 0, Low[0] - TickSize, Color.Red)
                    The "true" is the additional parameter needed.
                    AustinNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    596 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    343 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    103 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    556 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    554 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X