Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I need to know what instrument I am using at runtime.

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

    I need to know what instrument I am using at runtime.

    Hi, I am building a strategy for the Forex market and I need to know what instrument I am using at runtime / initialize. I can check what type of trade I've have gone into with IOrder -> order.Instrument.ToString() but I need to know what currency I'm using, before any logic takes place, so I can set the appropriate variables.

    This is needed because of the differences that take place when using JPY in either of your currency pair. So if I'm using JPY in a pair I will set the leverage and decimal location differently than if I'm not using a pair with JPY.

    It is possible to use many different pairs in a single strategy, I am not, but I imagine there is a way to get a list of all pairs that have been loaded?

    Thanks,
    4D
    Last edited by 4dplane; 08-25-2015, 12:47 PM.

    #2
    Hello 4dplane,

    Thank you for writing in. Here is a sample code that I have used in some of my scripts to get the base currency and the quote currency:
    Code:
    if(Instrument.FullName.Substring(0, 1) == "$")
    {
        string baseCurrency = Instrument.FullName.Substring(1, 3);
        string quoteCurrency = Instrument.FullName.Substring(4);
    }
    It is possible to use multiple currency pairs in a single strategy but because you need to add the additional currency pairs via your strategy code, you already know what those pairs are.
    Please see this help guide document for more information on working with multi time frame and multi instrument strategies: http://ninjatrader.com/support/helpG...nstruments.htm

    Please let me know if this does answer your question or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Thanks MichaelM,

      this is exactly what I was looking for! Looking over "Instrument" in the NT library I found this clause:
      "NOTE: The properties in this class should NOT be accessed within the Initialize() method."

      Ok, I moved it to the OnBarUpdate method, it works the same in both places but by putting it in the OnBarUpdate method I'm asking the same question over and over again for no reason. So why can't I use the "Instrument" property in the Initialize() method?

      Comment


        #4
        The Initialize() method is for UI and some configuration properties before the script starts processing data of any kind, because of this the Instrument class may not fully exist at that time of the call for the indicator. If you want to get it before OnBarUpdate but after the Initialize() call use OnStartUp()

        Ref. http://ninjatrader.com/support/helpG...?onstartup.htm

        Comment


          #5
          Hello 4dplane,

          Calonious is correct and while this code rarely will cause issues when used in the Initialize method(), there is the possibility for issues to arise so we do not recommend checking these variables until the method is finished running.

          In addition to what Calonious mentioned (using the OnStartUp() method instead) I have provided an example of how to check the variables once in the OnBarUpdate() method for your convenience:
          Code:
          private string baseCurrency, quoteCurrency;
          protected override void OnBarUpdate()
          {
              if(CurrentBar == 0)
              {
                  if(Instrument.FullName.Substring(0, 1) == "$")
                  {
                      baseCurrency = Instrument.FullName.Substring(1, 3);
                      quoteCurrency = Instrument.FullName.Substring(4);
                  }
              }
              if(baseCurrency != null && quoteCurrency != null)
              {
                  //Do something
              }
          }
          Please let me know if I may be of further assistance.
          Michael M.NinjaTrader Quality Assurance

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          942 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          9 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          4 views
          0 likes
          Last Post rocketman7  
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          28 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          33 views
          0 likes
          Last Post wzgy0920  
          Working...
          X