Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Accessing the currently used Instrument and Time frame

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

    Accessing the currently used Instrument and Time frame

    Hello,

    I know that this probably have been answered before, but I searched a lot and I didn't find any answers. So here's my question:

    When testing a strategy withing Strategy Analyzer, we first click on the desired instrument and then we'll set the time frame and then run the test. How can I access the name of instrument and the time frame that I'm currently testing from within my script?
    Last edited by arian_gh; 02-19-2015, 09:12 AM.

    #2
    Hello,

    Thank you for the question.

    While this is technically not supported here are the answers.

    For the Name you would need to get the full name from the instrument or the following:

    Code:
    Instrument.FullName
    There is also Instrument.Name but this does not get the contract for a futures so FullName will get the contract as well.


    For the chart type and time frame you can access the Bars information by doing the following:

    Code:
    Print(Bars.BarsType.Period.Value.ToString() + " " + Bars.BarsType.PeriodType.ToString());
    This would print 1 minute on a 1 minute chart.

    The period type can be used as such as well:

    Code:
    if(Bars.BarsType.PeriodType == PeriodType.Day) 
    {
    	//do something if day bars	
    }
    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you so much for your help Jesse. Your reply fully answered my question.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by bee1943, Today, 09:55 AM
      0 responses
      1 view
      0 likes
      Last Post bee1943
      by bee1943
       
      Started by giulyko00, Yesterday, 11:49 AM
      4 responses
      24 views
      0 likes
      Last Post giulyko00  
      Started by NUVERSA, Today, 09:31 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by rene69851, 05-02-2024, 03:25 PM
      2 responses
      29 views
      0 likes
      Last Post NinjaTrader_Kimberly  
      Started by ttrader23, Yesterday, 09:04 AM
      8 responses
      37 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X