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 pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            148 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            5 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            33 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Started by tkaboris, Today, 05:13 PM
            0 responses
            5 views
            0 likes
            Last Post tkaboris  
            Started by GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,282 views
            0 likes
            Last Post Leafcutter  
            Working...
            X