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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        78 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        40 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        63 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        63 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        54 views
        0 likes
        Last Post CarlTrading  
        Working...
        X