Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsPeriod of chartControl not available

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

    BarsPeriod of chartControl not available

    Hi all,

    I wish to print certain information in my Output window including the time interval of the current chart I am using my indicator on.

    The below code works fine and prints me "5" when I use the indicator on a 5-minute chart. However, the integer time_interval is not available in OnBarUpdate() where I need it - the error CS0103 says "The name "time_interval" does not exits in the current context".

    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    int time_interval = chartControl.BarsPeriod.Value;
    Print(time_interval);
    }

    Does anybody know how I have to change my code to make that happen?

    Thank you, P




    #2
    Hello P,

    If you declare a variable within the scope of a method, it is only available within that method. You have declared time_interval inside of OnRender() so it can only be used in OnRender().

    Declare the variable within the scope of the class to have the variable to all methods within the class. (Make a strategy with the Strategy builder and add a variable and see where it is declared)


    Also, the BarsPeriod and the ChartControl will already be available once the script is at State.DataLoaded, and you do not have to get these from OnRender().
    https://ninjatrader.com/support/help...barsperiod.htm
    https://ninjatrader.com/support/help...artcontrol.htm
    Last edited by NinjaTrader_ChelseaB; 07-29-2020, 08:46 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, you are absolutely right, I can call BarsPeriod.Value in OnBarUpdate() without any declaration. Thank you.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      601 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      347 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      559 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      558 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X