Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retreiving Candle duration / Chart timeframe

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

    Retreiving Candle duration / Chart timeframe

    Simple question, how do you retrieve the current chart candle duration setting (i.e. 1 minute, 5 minute, 10 minute, etc.) within a script? I want to be able to adjust strategy parameters dynamically in the script if I change the candle duration of the chart manually in real time.

    Thank you.

    #2
    Hello Dr Kerry,

    The values of the barstype can be accessed while the script is running but cannot be used for the purpose of controlling user inputs in the earlier states of the script. In your OnBarUpdate logic you could certainly use those values to deleage what the strategy is doing.

    To access the bars type values you can use the following values:

    Code:
    Print(Bars.BarsPeriod.Value + " " + Bars.BarsPeriod.BarsPeriodTypeName);
    
    if(Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Minute && Bars.BarsPeriod.Value > 5)

    Comment


      #3
      Jesse,

      Thank you very much for your quick reply. I think that what you suggest will work because the strategy restarts whenever the candle time scale is changed manually. So it will be able to get the current chart setting and use that in combination with the "if" statements to set the parameter values accordingly.

      Regards,

      Kerry

      Comment


        #4
        Hello Dr Kerry,

        Correct, each time you change the timeframe the strategy will restart so those will match the series that the strategy is applied to. The only time those values won't be available is during the early states of the strategy before State.DataLoaded. You can see some examples on the following page, that usage is the same as what I provided, Bars.BarsPeriod, the Bars property just refers to the primary bar series being used.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        73 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        39 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
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X