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

Code snippet based on Instrument Type

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

    Code snippet based on Instrument Type

    Hello,

    I found out that there is a possibility to code based on the instrument type ie. the Instrument.MasterInstrument.InstrumentType.

    Is there a code snippet available for the following
    If
    InstrumentType is Currency give value 1
    else if
    InstrumentType is Future give value 2
    else
    give value 0


    or would it be possible to have a code snippet sample here as an answer. Thank you
    Last edited by MickeyHR; 01-07-2013, 11:35 AM. Reason: case solved

    #2
    Hello MickeyHR,
    Yes, you can simply cast the InstrumentType to an integer depending on what you are trying to do.

    A sample code will be like:

    Code:
    int i = (int)Instrument.MasterInstrument.InstrumentType;
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by MickeyHR View Post
      Hello,

      I found out that there is a possibility to code based on the instrument type ie. the Instrument.MasterInstrument.InstrumentType.

      Is there a code snippet available for the following
      If
      InstrumentType is Currency give value 1
      else if
      InstrumentType is Future give value 2
      else
      give value 0

      or would it be possible to have a code snippet sample here as an answer. Thank you
      Why not just directly use the enumeration: the code is much more readable that way.

      Comment


        #4
        Originally posted by koganam View Post
        Why not just directly use the enumeration: the code is much more readable that way.
        Sorry, but I haven't the foggiest idea what you are writing about

        Comment


          #5
          Originally posted by NinjaTrader_Joydeep View Post
          Hello MickeyHR,
          Yes, you can simply cast the InstrumentType to an integer depending on what you are trying to do.

          A sample code will be like:

          Code:
          int i = (int)Instrument.MasterInstrument.InstrumentType;
          http://www.ninjatrader.com/support/h...trument_in.htm
          Ok. Saw that one already in the reference... However, the following doesn't at least work (so... Obviously I don't get this):
          Code:
          int instrument = (int)Instrument.MasterInstrument.InstrumentType;
          			double avariable = 0;
          			if
          				(
          				instrument == Currency;
          				)
          			{
          				avariable = earliervariable+1;
          			}
          			 else if	
          				(
          				instrument == Future || instrument == Option || instrument == Stock
          				)
          			{
          				avariable = earliervariable+2;
          			}
          			else	
          				
          				avariable = earliervariable+3;
          Would you (or anyone else fort that matter) care to elaborate what I'm doing wrong here. Thank You again

          Comment


            #6
            Hello MickeyHR,
            You can use the below if else statement to do it.

            Code:
            if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Currency)
            {  //do something }
            else if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Future)
            {  //do something }
            else { //do something }

            Alternatively you can directly assign it as:

            Code:
            int avariable = (int) Instrument.MasterInstrument.InstrumentType + 1;
            JoydeepNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Working...
            X