Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by patrickmlee007, Today, 09:33 AM
        2 responses
        15 views
        0 likes
        Last Post patrickmlee007  
        Started by magnatauren, 08-15-2020, 02:12 PM
        5 responses
        206 views
        0 likes
        Last Post RaddiFX
        by RaddiFX
         
        Started by rene69851, 05-02-2024, 03:25 PM
        1 response
        21 views
        0 likes
        Last Post rene69851  
        Started by ETFVoyageur, Yesterday, 07:05 PM
        5 responses
        45 views
        0 likes
        Last Post ETFVoyageur  
        Started by jpeep, 08-16-2020, 08:31 AM
        13 responses
        487 views
        0 likes
        Last Post notenufftime  
        Working...
        X