Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple S&R indicator NOT Showing up, NOT Working

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

    Simple S&R indicator NOT Showing up, NOT Working

    Hello NT Team,

    I made a small and simple S1R Indicator that each time makes new Support and Resistance levels based on previous candles, but it seemds it doesn't work I dono why

    this is the code :

    Code:
    namespace NinjaTrader.NinjaScript.Indicators.TheGM
    {
        public class TheGMSupportandResistance : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "TheGMSupportandResistance";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (Low[0] < Low[1])
                    Draw.HorizontalLine(this, "Support", Low[0]-TickSize, Brushes.Green);
    
                if (High[0] > High[1])
                    Draw.HorizontalLine(this, "Resistance", High[0]+TickSize, Brushes.Red);
            }
        }
    }​
    can you tell me what is wrong please ? Thank you

    #2
    Look at the “log” tab of the NinjaTrader control center and review the error messages.

    when your indicator loads it executes starting with the first historical bar therefore there is no previous bar Low[1] or High[1]. Check the help guide on how to use CurrentBar to prevent processing until CurrentBar is greater than 1 at least.

    Comment


      #3
      Thank you very much, I added
      Code:
      if (CurrentBar > 0)
      and seems that it works, but sometimes in some indicators I see in code
      Code:
      if (CurrentBar == 0) else ....
      what does it mean ?

      Thank you

      Comment


        #4
        Hi Mohammed, thanks for posting. When a script accesses bars back, the script needs to make sure there are enough bars on the chart before accessing E.g. High[1]. If you access High[1] when CurrentBar == 0, it will fail, so we have code at the top of OnBarUpdate that makes sure there is at least 2 bars on the chart.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X