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
    Brandon H.NinjaTrader Customer Service

    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:	58
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.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks alot!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Karado58, 11-26-2012, 02:57 PM
          8 responses
          14,826 views
          0 likes
          Last Post Option Whisperer  
          Started by Option Whisperer, Today, 09:05 AM
          0 responses
          1 view
          0 likes
          Last Post Option Whisperer  
          Started by cre8able, Yesterday, 01:16 PM
          3 responses
          11 views
          0 likes
          Last Post cre8able  
          Started by Harry, 05-02-2018, 01:54 PM
          10 responses
          3,204 views
          0 likes
          Last Post tharton3  
          Started by ChartTourist, Today, 08:22 AM
          0 responses
          6 views
          0 likes
          Last Post ChartTourist  
          Working...
          X