Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw a short line above current price error

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

    Draw a short line above current price error

    Hello guys, I have a script that does not want to work. It drives me crazy because I cannot find the answer anywere...
    I begin in scripting.

    My goal is to have a line 16 ticks above the current price and one under the current price.
    I don't want a horizontal line accross the chart, but a short one.
    Right now I'm trying to diplay a line with no success...


    Code:
    #region Using declarations
    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Data;
    using System.Windows.Media;  // Add this namespace for Brushes
    using System.ComponentModel.DataAnnotations; // Add this namespace for DisplayAttribute
    #endregion
    
    // This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class LineAbovePrice : Indicator
        {
            private double tickSize;
    
            [NinjaScriptProperty]
            [Display(Name = "Ticks Above", Order = 1, GroupName = "Parameters")]
            public int TicksAbove { get; set; }
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"An indicator that draws a line 16 ticks above the current price, starting 3 bars before the current bar and extending to the right.";
                    Name = "LineAbovePrice";
                    Calculate = Calculate.OnEachTick;
                    IsOverlay = true;
                    TicksAbove = 16;
                }
                else if (State == State.Configure)
                {
                    tickSize = TickSize;
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 3) return; // Ensure there are enough bars to calculate
    
                double currentPrice = Close[0];
                double linePrice = currentPrice + (TicksAbove * tickSize);
    
                // Draw line starting from 3 bars before the current bar and extending to the right
                Draw.Line(this, "LineAbovePrice", false, 3, linePrice, 0, linePrice, Brushes.Green, DashStyleHelper.Solid, 2);
            }
        }
    }​
    This code generate 2 errors that I cannot solve...

    The name 'Draw' does not exist in the current context
    The name 'DashStyleHelper' does not exist in the current context

    Thanks in advance

    #2
    Hello gezy369,

    The code you provided is missing the default using statements that would be required, you need to regenerate the file and leave the using statements that come with the script at the top of the file.

    In the NinjaScript editor right click on your current file and exclude it from compilation. Then right click on the indicators folder and select new indicator and then generate the file. The new file will have the correct using statements and structure and you can begin working in that file again.

    Comment


      #3
      Thanks for your answer.
      So I just understood that an error can come from another script !ü
      Damn boy, still learning haha.

      It helped, thx !

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      608 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      355 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      560 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      561 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X