Announcement

Collapse
No announcement yet.

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, 10: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;
    http://www.ninjatrader.com/support/h...trument_in.htm
    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 WaveAtElliot, Today, 05:11 PM
            1 response
            7 views
            1 like
            Last Post hdge4u
            by hdge4u
             
            Started by bosajin, Yesterday, 09:15 AM
            5 responses
            36 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by Dolfan, Today, 12:24 PM
            4 responses
            23 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by WeyldFalcon, Today, 11:09 AM
            7 responses
            26 views
            0 likes
            Last Post WeyldFalcon  
            Started by DTSSTS, 08-10-2020, 09:48 AM
            12 responses
            67 views
            0 likes
            Last Post DTSSTS
            by DTSSTS
             
            Working...
            X