Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninjascript editor error output

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

    Ninjascript editor error output

    I developed a new drawing tool and wrote the code myself. I've checked it or errors but once I paste it into Ninjascript Editor, it pops up "These errors must be corrected before we can compile" ... Okay, but there are a bunch so, I'm wondering if there is a way to export the errors so that I can list them all on one page for me to go through?

    #2
    Hello dniezby,

    Thank you for your post.

    You can right-click within the area where the compile errors are listed > Export to export it is a .csv file with all the errors listed.

    If you need assistance with resolving the errors, please share your script and the list of compile errors for review.

    Comment


      #3
      Okay, I'm pulling my hair out. So I'm trying to develop a new rectangle drawing tool for drawing supply zones. This is the code I've developed but I'm still getting errors. (Posting the errors at the bottom) What am I missing? Click on the screen, draw your rectangle and once it's set, it also shows the prices on the distal and proximal edges. I did get some AI help and it doesn't fix my problems either.

      Code:
      using System;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Globalization;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.NinjaScript.StrategyAnalyzerColumns;
      
      namespace NinjaTrader.NinjaScript.StrategyAnalyzerColumns.NinjaScriptColumns
      {
          public class SupplyZoneTool : DrawingTool
          {
              #region Properties
              [NinjaScriptProperty]
              [Display(Name = "FillOpacity", Description = "Fill opacity", Order = 1, GroupName = "Parameters")]
              public string FillOpacity { get; set; }
      
              [NinjaScriptProperty]
              [Display(Name = "FillColor", Description = "Fill Color of the zone", Order = 2, GroupName = "Parameters")]
              public string FillColor { get; set; }
      
              [NinjaScriptProperty]
              [Display(Name = "OutlineWeight", Description = "Thickness of the outline", Order = 3, GroupName = "Parameters")]
              public string OutlineWeight { get; set; }
      
              [NinjaScriptProperty]
              [Display(Name = "OutlineColor", Description = "Color of the outline", Order = 4, GroupName = "Parameters")]
              public string OutlineColor { get; set; }
      
              [NinjaScriptProperty]
              [Display(Name = "DistalPrice", Description = "Show prices on the distal edge of the zone", Order = 5, GroupName = "Parameters")]
              public bool DistalPrice { get; set; }
      
              [NinjaScriptProperty]
              [Display(Name = "ProximalPrice", Description = "Show prices on the proximal edge of the zone", Order = 6, GroupName = "Parameters")]
              public bool ProximalPrice { get; set; }
      
              [NinjaScriptProperty]
              [Display(Name = "OutlineOpacity", Description = "Opacity of the outline", Order = 7, GroupName = "Parameters")]
              public string OutlineOpacity { get; set; }
              #endregion
      
              private Point _startPoint;
              private Point _endPoint;
              private bool _drawing;
      
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Tag = "Supply Zone Tool"; // Set the name using Tag property
                      // Set default values for properties
                      FillColor = "Red";
                      FillOpacity = "40";
                      OutlineColor = "Red";
                      OutlineWeight = "3";
                      OutlineOpacity = "100";
                      DistalPrice = true;
                      ProximalPrice = true;
                  }
                  base.OnStateChange();
              }
      
              protected override void OnRender(DrawingContext dc, ChartPanel chartPanel)
              {
                  base.OnRender(dc, chartPanel);
      
                  if (_drawing)
                  {
                      // Calculate the rectangle dimensions
                      double left = Math.Min(_startPoint.X, _endPoint.X);
                      double top = Math.Min(_startPoint.Y, _endPoint.Y);
                      double width = Math.Abs(_endPoint.X - _startPoint.X);
                      double height = Math.Abs(_endPoint.Y - _startPoint.Y);
      
                      // Convert FillColor and OutlineColor strings to Color objects
                      Color fillColor = (Color)ColorConverter.ConvertFromString(FillColor);
                      Color outlineColor = (Color)ColorConverter.ConvertFromString(OutlineColor);
      
                      // Draw the rectangle
                      dc.DrawRectangle(new SolidColorBrush(fillColor), new Pen(new SolidColorBrush(outlineColor), double.Parse(OutlineWeight)), new Rect(left, top, width, height));
      
                      // Calculate proximal and distal price levels
                      double proximalPrice = chartPanel.GetPriceByY(top);
                      double distalPrice = chartPanel.GetPriceByY(top + height);
      
                      // Draw text labels for proximal and distal prices
                      if (ProximalPrice)
                      {
                          FormattedText proximalText = new FormattedText(proximalPrice.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 10, Brushes.Black);
                          dc.DrawText(proximalText, new Point(left, top));
                      }
      
                      if (DistalPrice)
                      {
                          FormattedText distalText = new FormattedText(distalPrice.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 10, Brushes.Black);
                          dc.DrawText(distalText, new Point(left, top + height));
                      }
                  }
              }
      
              protected override void OnMouseMove(MouseEventArgs e)
              {
                  base.OnMouseMove(e);
      
                  if (_drawing)
                  {
                      _endPoint = e.GetPosition(null);
                      RefreshVisual();
                  }
              }
      
              protected override void OnMouseDown(MouseButtonEventArgs e)
              {
                  base.OnMouseDown(e);
      
                  if (!_drawing)
                  {
                      _startPoint = e.GetPosition(null);
                      _drawing = true;
                  }
              }
      
              protected override void OnMouseUp(MouseButtonEventArgs e)
              {
                  base.OnMouseUp(e);
      
                  if (_drawing)
                  {
                      _endPoint = e.GetPosition(null);
                      _drawing = false;
                      RefreshVisual();
                  }
              }
          }
      }
      ​
      Here are the errors:
      NinjaScript File Error Code Line Column
      SupplyZone.cs The type or namespace name 'DrawingTool' could not be found (are you missing a using directive or an assembly reference?) CS0246 14 35
      SupplyZone.cs 'State' is a type, which is not valid in the given context CS0119 52 17
      SupplyZone.cs The name 'Tag' does not exist in the current context CS0103 54 17
      SupplyZone.cs 'ChartPanel' does not contain a definition for 'GetPriceByY' and no accessible extension method 'GetPriceByY' accepting a first argument of type 'ChartPanel' could be found (are you missing a using directive or an assembly reference?) CS1061 87 51
      SupplyZone.cs 'ChartPanel' does not contain a definition for 'GetPriceByY' and no accessible extension method 'GetPriceByY' accepting a first argument of type 'ChartPanel' could be found (are you missing a using directive or an assembly reference?) CS1061 88 49
      SupplyZone.cs The name 'RefreshVisual' does not exist in the current context CS0103 112 17
      SupplyZone.cs The name 'RefreshVisual' does not exist in the current context CS0103 135 17
      Attached Files

      Comment


        #4
        Hello dniezby,

        If this is supposed to be drawing tool script, the namespace is incorrect. Drawing tool scripts should have the DrawingTools namespace.

        Code:
        namespace NinjaTrader.NinjaScript.DrawingTools
        I recommend creating the script by opening the NinjaScript Editor > right clicking on 'DrawingTools' > click 'New DrawingTool' and this will auto-generate the correct and necessary skeleton code for a DrawingTools script.

        RefreshVisual() is also not a NinjaScript method. You may be thinking of ForceRefresh().



        GetPriceByY() is also not a NinjaScript method. You may be thinking of GetValueByY().



        Please let us know if you have any further questions.

        Comment


          #5
          Hmm, I did have AI check the code and I'm wondering if it changed the namespace. The wizard is how I actually started the code process. I didn't even notice it had vanished. Good catch. I'll fix that. Thanks for those catches

          Comment


            #6
            Don't let A.I. near your code.
            eDanny
            NinjaTrader Ecosystem Vendor - Integrity Traders

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            558 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
            545 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