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 helpwanted, Today, 03:06 AM
            2 responses
            21 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by DayTradingDEMON, Today, 09:28 AM
            0 responses
            1 view
            0 likes
            Last Post DayTradingDEMON  
            Started by navyguy06, Today, 09:28 AM
            0 responses
            1 view
            0 likes
            Last Post navyguy06  
            Started by rjbtrade1, 11-30-2023, 04:38 PM
            2 responses
            77 views
            0 likes
            Last Post DavidHP
            by DavidHP
             
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            7 responses
            31 views
            0 likes
            Last Post cmtjoancolmenero  
            Working...
            X