Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I find out what timeframe a strategy use from its code?

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

    Can I find out what timeframe a strategy use from its code?

    Hi Folks,

    I am very new to this topic. I am curious if I can find out the exact time frame a strategy is using from its code? I am studying the simplest "SampleMACrossOver" strategy in the installation package. I cannot find which time frame this strategy is using.

    From the code, it proceeds to add indicators directly. That confused me.

    Code:
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
    Name = NinjaTrader.Custom.Resource.NinjaScriptStrategyNam eSampleMACrossOver;
    Fast = 10;
    Slow = 25;
    // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = false;
    }
    else if (State == State.DataLoaded)
    {
    smaFast = SMA(Fast);
    smaSlow = SMA(Slow);
    
    smaFast.Plots[0].Brush = Brushes.Goldenrod;
    smaSlow.Plots[0].Brush = Brushes.SeaGreen;
    
    AddChartIndicator(smaFast);
    AddChartIndicator(smaSlow);
    }
    }
    Thank you very much for your input.




    Best Regards
    David WANG

    #2
    Hi sinpeople,
    If you just wanted to identify the primary series the strategy is running on, add the following in OnStateChange():

    ...
    else if (State == State.DataLoaded)
    {
    Print(Instrument.FullName + " " + Bars.Period);
    }
    The result will look similar to this example: FDAX 06-21 1 Min Heiken-Ashi
    NT-Roland

    Comment


      #3
      Hello sinpeople,

      Below are supporting links to the help guide on BarsPeriod.BarsPeriodType and BarsPeriod.Value.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      566 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X