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

Multiple instruments

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

    Multiple instruments

    Recently Bertrand explained method that allows to access last close price:
    protected override void OnBarUpdate()
    {
    if (Closes[0][0]!=0) Print(sec1name+" "+Closes[0][0]);
    if (Closes[1][0]!=0) Print(sec2name+" "+Closes[1][0]);
    }

    Is it possible to specify instrument for SubmitOrder command?

    Is there a possibility to calculate profit/loss for either first or second instrument separately?

    Would this command GetAtmStrategyUnrealizedProfitLoss() show summary results for both instruments?

    If it wouldn't what should i use in case I need summary position?
    Last edited by greed999; 08-02-2011, 05:08 AM.

    #2
    greed999, you can SubmitOrder to another BarsInProgress / instrument as well - first though it needs to be Add()ed to the script in the Initialize().

    For the PNL for several instruments, you can work with Positions - http://www.ninjatrader.com/support/h.../positions.htm

    Thanks,
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you for your assistence again, Bertrand. I have added second instrument in initialize section:
      Add(sec2, PeriodType.Minute, 1);

      Still don't get it, how can I submit order for secong instrument?

      This is link to SubmitOrder syntax. Separate instruments are not mentioned. Could you be so kind to provide an example?

      Comment


        #4
        greed999, the SubmitOrder() overload has a BarsInProgress paramter, if you set this for example 1 : you're submitting to the first added instrument, the secondary series for the script.

        protected override void OnBarUpdate()
        {
        // Entry condition
        if (Close[0] > SMA(20)[0] && entryOrder == null)
        entryOrder = SubmitOrder(1, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "Enter Long");
        }
        BertrandNinjaTrader Customer Service

        Comment


          #5
          So... my entry procedure might look like this:
          private void FirstOrder()
          {
          entOrdInstrument1 = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "Enter Long First Instrument");
          entOrdInstrument2 = SubmitOrder(1, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "Enter Long Second Instrument");
          }

          Considering that first instrument is to be defind during the strategy launch and that second instrument has been defined in initialize section:

          protected override void Initialize()
          {
          CalculateOnBarClose = false;
          TraceOrders=true;
          Unmanaged = true;
          Add(sec2, PeriodType.Minute, 1);
          }

          and sec2 is defined lets say this way:
          sec2="TF 09-11"

          How does it look?

          Comment


            #6
            Looks good to me greed999.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Can you please tell, if it is necessary to somehow define TickSize for each of the additional instruments?

              What should I do to define price range for security 2?
              Will that do?
              MyPrice2=Closes[1][0]+2*TickSize;

              Thanks in advance,
              Alex
              Last edited by greed999; 08-03-2011, 07:37 AM.

              Comment


                #8
                Yes Alex, you would want to store the ticksize of your other BIP's in a variable, so you can add it later in antother BIP context.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  How can I get value of the TickSize for each of my instruments then?
                  It didn't work when I had tried to access it as an array

                  Comment


                    #10
                    Hi greed999,

                    You can access TickSize from other series by defining the BarsInProgress context:
                    Code:
                    #region Variables
                    private double 	myTickSizeInstrument0;
                    private double 	myTickSizeInstrument1;	
                    #endregion
                    
                    protected override void OnBarUpdate()
                    {
                    if(BarsInProgress == 0)
                    	myTickSizeInstrument0 = TickSize;
                    				
                    				
                    if(BarsInProgress == 1)
                    	myTickSizeInstrument1 = TickSize;	
                    }
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      You have helped me a lot, Ryan. Good example and very useful!
                      Yet another question on the subject if I may?
                      What do you think about this code as a condition to close positions
                      (bearing in mind that tProf0 is a predefined profit target in currency)

                      if (Positions[1].GetProfitLoss(Closes[1][0],PerformanceUnit.Currency)+
                      Positions[2].GetProfitLoss(Closes[2][0],PerformanceUnit.Currency) > tProf0)
                      {
                      /// leave market
                      }
                      Last edited by greed999; 08-03-2011, 03:04 PM.

                      Comment


                        #12
                        Looks OK from here, that you're adding together PNL on instruments 1 and 2. You may want to include a market position checks there, so that you're only accessing these values when there is a position.

                        Code:
                        if (Positions[1].MarketPosition != MarketPosition.Flat &&
                         Positions[2].MarketPosition != MarketPosition.Flat) 
                        {
                             if (Positions[1].GetProfitLoss(Closes[1][0],PerformanceUnit.Currency)+
                                Positions[2].GetProfitLoss(Closes[2][0],PerformanceUnit.Currency) > tProf0)
                        	{
                        	/// leave market
                        	}
                        }
                        Last edited by NinjaTrader_RyanM1; 08-03-2011, 04:08 PM.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Dear Customer Support,


                          I have a multi instrument strategy which submits entry order when the Positions[pair_no].MarketPosition for that instrument is Flat.
                          This works fine when I select Entries per direction == 1;

                          But when I select Entries per direction == 2;
                          Entriy Handling == AllEntries;

                          Then the strategy submits entry for the second position despite the Positions[pair_no].MarketPosition for that instrument is not Flat (either Long or Short).

                          Is there anything wrong with my setting on the OrderHandling?


                          Would appreciate your assistance.

                          Comment


                            #14
                            Hi Hana, would you see the same if you switch to EntriesPerDirection = 1 but with Unique entry handling? Then of course please name your entry signals uniquely as well in this context.

                            Thanks,
                            BertrandNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by pibrew, Today, 06:10 PM
                            1 response
                            16 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by actualfacts.2021, 07-25-2021, 03:11 PM
                            8 responses
                            1,182 views
                            0 likes
                            Last Post linkcou
                            by linkcou
                             
                            Started by reynoldsn, Today, 07:11 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post reynoldsn  
                            Started by needsomehelp147, 04-29-2024, 06:43 AM
                            2 responses
                            19 views
                            0 likes
                            Last Post needsomehelp147  
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            177 responses
                            2,400 views
                            0 likes
                            Last Post jeronymite  
                            Working...
                            X