Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The name 'BarsPeriodType' does not exist in the current context | please help

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

    The name 'BarsPeriodType' does not exist in the current context | please help

    Getting error The name 'BarsPeriodType' does not exist in the current context

    region Using declarations

    using System;

    using System.Windows.Media;

    using NinjaTrader.Gui.Chart;

    using NinjaTrader.NinjaScript;

    using NinjaTrader.NinjaScript.DrawingTools;




    #endregion




    namespace NinjaTrader.NinjaScript.Indicators

    {

    public class FirstBarHighLow : Indicator

    {

    private double openingHigh = double.MinValue;

    private double openingLow = double.MaxValue;

    private bool openingRangeIdentified = false;




    protected override void OnStateChange()

    {

    if (State == State.SetDefaults)

    {

    Description = @"Draws horizontal lines for the first 5 minutes opening range high and low.";

    Name = "FirstBarHighLow";

    Calculate = Calculate.OnBarClose;

    IsOverlay = true;

    }

    }




    protected override void OnBarUpdate()

    {

    // If not a 5 minute chart, do not continue.

    if (BarsPeriod.BarsPeriodType != NinjaTrader.Cbi.BarsPeriodType.Minute || BarsPeriod.Value != 5)

    {

    //Log("This indicator only works on a 5-minute chart.", LogLevel.Error);

    return;

    }




    // Reset the opening range for a new day

    if (Bars.IsFirstBarOfSession)

    {

    openingHigh = double.MinValue;

    openingLow = double.MaxValue;

    openingRangeIdentified = false;

    }




    // Identify the first 5-minute range from 9:30 to 9:35

    TimeSpan barTime = Time[0].TimeOfDay;

    if (barTime >= TimeSpan.FromHours(9.5) && barTime < TimeSpan.FromHours(9.58333333))

    {

    openingHigh = Math.Max(openingHigh, High[0]);

    openingLow = Math.Min(openingLow, Low[0]);

    openingRangeIdentified = true;

    }

    else if (openingRangeIdentified && barTime >= TimeSpan.FromHours(9.58333333))

    {

    // Draw the high line if it has not been drawn yet

    if (openingHigh != double.MinValue && DrawObjects["OpeningHigh"] == null)

    {

    Draw.HorizontalLine(this, "OpeningHigh", openingHigh, Brushes.DodgerBlue);

    }




    // Draw the low line if it has not been drawn yet

    if (openingLow != double.MaxValue && DrawObjects["OpeningLow"] == null)

    {

    Draw.HorizontalLine(this, "OpeningLow", openingLow, Brushes.DodgerBlue);

    }




    // Prevent further drawing

    openingRangeIdentified = false;

    }

    }

    }

    }




    region NinjaScript generated code. Neither change nor remove.




    namespace NinjaTrader.NinjaScript.Indicators

    {

    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase

    {

    private FirstBarHighLow[] cacheFirstBarHighLow;

    public FirstBarHighLow FirstBarHighLow()

    {

    return FirstBarHighLow(Input);

    }




    public FirstBarHighLow FirstBarHighLow(ISeries<double> input)

    {

    if (cacheFirstBarHighLow != null)

    for (int idx = 0; idx < cacheFirstBarHighLow.Length; idx++)

    if (cacheFirstBarHighLow[idx] != null && cacheFirstBarHighLow[idx].EqualsInput(input))

    return cacheFirstBarHighLow[idx];

    return CacheIndicator<FirstBarHighLow>(new FirstBarHighLow(), input, ref cacheFirstBarHighLow);

    }

    }

    }




    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns

    {

    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase

    {

    public Indicators.FirstBarHighLow FirstBarHighLow()

    {

    return indicator.FirstBarHighLow(Input);

    }




    public Indicators.FirstBarHighLow FirstBarHighLow(ISeries<double> input )

    {

    return indicator.FirstBarHighLow(input);

    }

    }

    }




    namespace NinjaTrader.NinjaScript.Strategies

    {

    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase

    {

    public Indicators.FirstBarHighLow FirstBarHighLow()

    {

    return indicator.FirstBarHighLow(Input);

    }




    public Indicators.FirstBarHighLow FirstBarHighLow(ISeries<double> input )

    {

    return indicator.FirstBarHighLow(input);

    }

    }

    }




    #endregion


    Purpose of the script is to draw a line of the opening range on the first 5 candles or 5min candle's high and low to mark the opening range.

    #2
    Hello osmanigarces,

    Thanks for your post.

    The error message is being caused by the line of code below that you shared.

    if (BarsPeriod.BarsPeriodType != NinjaTrader.Cbi.BarsPeriodType.Minute || BarsPeriod.Value != 5)
    {
    .
    }


    To resolve the error message you need to remove NinjaTrader.Cbi from your condition as this is not the correct syntax to compare is the BarsPeriodType is not equal to BarsPeriodType.Minute.

    After removing NinjaTrader.Cbi from the code you shared the condition should look something like this.

    if (BarsPeriod.BarsPeriodType != BarsPeriodType.Minute || BarsPeriod.Value != 5)
    {

    }


    See ​​this help guide documentation for more information on BarsPeriodType: https://ninjatrader.com/support/help...barsperiod.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello osmanigarces,

      Thanks for your post.

      The error message is being caused by the line of code below that you shared.

      if (BarsPeriod.BarsPeriodType != NinjaTrader.Cbi.BarsPeriodType.Minute || BarsPeriod.Value != 5)
      {
      .
      }


      To resolve the error message you need to remove NinjaTrader.Cbi from your condition as this is not the correct syntax to compare is the BarsPeriodType is not equal to BarsPeriodType.Minute.

      After removing NinjaTrader.Cbi from the code you shared the condition should look something like this.

      if (BarsPeriod.BarsPeriodType != BarsPeriodType.Minute || BarsPeriod.Value != 5)
      {

      }


      See ​​this help guide documentation for more information on BarsPeriodType: https://ninjatrader.com/support/help...barsperiod.htm
      Thanks I made the change however I am still getting the error

      here is the new script for reference
      region Using declarations

      using System;

      using System.Windows.Media;

      using NinjaTrader.Gui.Chart;

      using NinjaTrader.NinjaScript;

      using NinjaTrader.NinjaScript.DrawingTools;




      #endregion




      namespace NinjaTrader.NinjaScript.Indicators

      {

      public class FirstBarHighLow : Indicator

      {

      private double openingHigh = double.MinValue;

      private double openingLow = double.MaxValue;

      private bool openingRangeIdentified = false;




      protected override void OnStateChange()

      {

      if (State == State.SetDefaults)

      {

      Description = @"Draws horizontal lines for the first 5 minutes opening range high and low.";

      Name = "FirstBarHighLow";

      Calculate = Calculate.OnBarClose;

      IsOverlay = true;

      }

      }




      protected override void OnBarUpdate()

      {

      // If not a 5 minute chart, do not continue.

      if (BarsPeriod.BarsPeriodType != BarsPeriodType.Minute || BarsPeriod.Value != 5)

      {

      //Log("This indicator only works on a 5-minute chart.", LogLevel.Error);

      return;

      }




      // Reset the opening range for a new day

      if (Bars.IsFirstBarOfSession)

      {

      openingHigh = double.MinValue;

      openingLow = double.MaxValue;

      openingRangeIdentified = false;

      }




      // Identify the first 5-minute range from 9:30 to 9:35

      TimeSpan barTime = Time[0].TimeOfDay;

      if (barTime >= TimeSpan.FromHours(9.5) && barTime < TimeSpan.FromHours(9.58333333))

      {

      openingHigh = Math.Max(openingHigh, High[0]);

      openingLow = Math.Min(openingLow, Low[0]);

      openingRangeIdentified = true;

      }

      else if (openingRangeIdentified && barTime >= TimeSpan.FromHours(9.58333333))

      {

      // Draw the high line if it has not been drawn yet

      if (openingHigh != double.MinValue && DrawObjects["OpeningHigh"] == null)

      {

      Draw.HorizontalLine(this, "OpeningHigh", openingHigh, Brushes.DodgerBlue);

      }




      // Draw the low line if it has not been drawn yet

      if (openingLow != double.MaxValue && DrawObjects["OpeningLow"] == null)

      {

      Draw.HorizontalLine(this, "OpeningLow", openingLow, Brushes.DodgerBlue);

      }




      // Prevent further drawing

      openingRangeIdentified = false;

      }

      }

      }

      }




      region NinjaScript generated code. Neither change nor remove.




      namespace NinjaTrader.NinjaScript.Indicators

      {

      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase

      {

      private FirstBarHighLow[] cacheFirstBarHighLow;

      public FirstBarHighLow FirstBarHighLow()

      {

      return FirstBarHighLow(Input);

      }




      public FirstBarHighLow FirstBarHighLow(ISeries<double> input)

      {

      if (cacheFirstBarHighLow != null)

      for (int idx = 0; idx < cacheFirstBarHighLow.Length; idx++)

      if (cacheFirstBarHighLow[idx] != null && cacheFirstBarHighLow[idx].EqualsInput(input))

      return cacheFirstBarHighLow[idx];

      return CacheIndicator<FirstBarHighLow>(new FirstBarHighLow(), input, ref cacheFirstBarHighLow);

      }

      }

      }




      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns

      {

      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase

      {

      public Indicators.FirstBarHighLow FirstBarHighLow()

      {

      return indicator.FirstBarHighLow(Input);

      }




      public Indicators.FirstBarHighLow FirstBarHighLow(ISeries<double> input )

      {

      return indicator.FirstBarHighLow(input);

      }

      }

      }




      namespace NinjaTrader.NinjaScript.Strategies

      {

      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase

      {

      public Indicators.FirstBarHighLow FirstBarHighLow()

      {

      return indicator.FirstBarHighLow(Input);

      }




      public Indicators.FirstBarHighLow FirstBarHighLow(ISeries<double> input )

      {

      return indicator.FirstBarHighLow(input);

      }

      }

      }




      #endregion


      Error-->
      The name 'BarsPeriodType' does not exist in the current context CS0103
      Click image for larger version

Name:	image.png
Views:	325
Size:	3.4 KB
ID:	1294407

      Comment


        #4
        Hello osmanigarces,

        Thanks for your notes.

        It seems that you are missing a Using Statement in your script which would cause the error to persist.

        Please add the Using Statement below to the "Using declarations" section of code in your script and run a compile to check if the error persists.

        using NinjaTrader.Data;

        Please let us know if we may assist further on this matter.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Thanks alot!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          72 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          44 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          25 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          29 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          60 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X