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 Aviram Y, Today, 05:29 AM
            0 responses
            1 view
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            34 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cls71, Today, 04:45 AM
            0 responses
            6 views
            0 likes
            Last Post cls71
            by cls71
             
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            216 views
            1 like
            Last Post PaulMohn  
            Working...
            X