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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      47 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X