• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multiple instruments on a single chart

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

    multiple instruments on a single chart

    Hello,

    I am trying to trade to instruments off of one chart. I am sure someone else has already asked this yet I am unable to find anything helpful in the forums. What I am attempting to do is take a strategy that I already use for trading the SPY and when it receives a buy or sell signal for the SPY to either long or short the VXX.

    THX in advance

    #2
    Hello Cboat,

    You have to work with a multi - instrument strategy for this. Can see a sample at Tools > Edit NinjaScript > Strategy > SampleMultiInstrument.

    You can then use the advanced overload for the Enter methods that support submitting to a specific BarsInProgress Index.

    The second series is access with BIP = 1, and so would submit the order to that series.

    EnterLong(int barsInProgressIndex, int quantity,string signalName)
    EnterShort(int barsInProgressIndex, int quantity,string signalName)

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      RYAN
      Thanks I finally got it running. Now I only have one last question. I am setting a profit target on the SPY but it is affecting the VXX. How could I write that so that they profit target is only taken on the spy.

      Comment


        #4
        For this you have to use unique entry names for your SPY orders, and then tie the profit targets to these orders with the fromEntrySignal parameter indicated below.

        SetProfitTarget(string fromEntrySignal, CalculationMode mode,double value)
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          is there a way that if the profit target is met for the Spy that it would also exit the VXX no matter what price they are at?

          Comment


            #6
            You can work from the principles in this reference sample:
            Monitoring Stop-Loss and Profit Target Orders

            When the profit target is filled you could then submit your exit order to the BIP value for SPY.

            http://www.ninjatrader-support.com/H.../ExitLong.html

            http://www.ninjatrader-support.com/H...ExitShort.html
            Last edited by NinjaTrader_RyanM1; 08-05-2010, 01:32 PM.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              So if my profit target for the SPY is met I can exit my position in the second instrument?

              Comment


                #8
                Yes, you can code for this scenario. Reference sample linked above helps with setting up the conditions for profit target is filled and then you submit your exit orders to BIP 1.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  I took a look at the reference sample. Yet, I am still getting the same outcome as before. How would I give the profit target a unique identifier? The way the reference same does it does not seem to work for me.

                  Comment


                    #10
                    cboat,

                    This line is what gives the Profit Target a new identifier:
                    profitTargetTokens.Add(order.Token);

                    It applies to all profit target orders due to this line here: (order.Name == "Profit target")


                    Can you please post the strategy file you're using here and clarify what you're looking for versus what you're seeing?

                    Strategy .cs fils is stored in My Documents\NinjaTrader 7\bin\custom\strategy.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Code:
                              protected override void Initialize()
                              {
                                  
                                   Add("VXX", PeriodType.Minute, 1);
                                   Add(Indicator);
                                  
                      //           TraceOrders = true;
                                   CalculateOnBarClose = true;
                              }
                              
                              /// <summary>
                              /// Called on each bar update event (incoming tick)
                              /// </summary>
                              /// 
                              protected override void OnOrderUpdate(IOrder order)
                              {
                                  if(BarsInProgress == 0)
                                  {
                                  if(order.OrderState == OrderState.Filled)
                                  {
                                  if(order.Name == "Profit target")
                                      profitTargetTokens.Add(order.Token);
                                  }
                                  if(profitTargetTokens.Contains(order.Token))
                                  {
                                      if(order.OrderState == OrderState.Filled || order.OrderState == OrderState.PartFilled || order.OrderState == OrderState.Working)
                                      {
                                          ExitLong(1,ent1,"Exit Long VXX","Buy VXX");
                                          ExitShort(1,ent1,"Exit Short VXX","Sell VXX");
                                          
                                          profitTargetTokens.Remove(order.Token);
                                      }
                                  }
                                  }
                                  
                              }
                              protected override void OnBarUpdate()
                                  
                              {
                                  
                                  if(BarsInProgress != 0)
                                      return;
                                   
                                  if (ToTime(Time[0]) >= aStartTime && ToTime(Time[0]) < aStopTime)
                                  {
                                      
                                      // Condition set 1
                                      if (Condtion > Var1 && Position.MarketPosition == MarketPosition.Flat )
                                      {
                                           myOrderShort = EnterShortLimit(0, true, ent1,GetCurrentAsk(),"SHORT LIMIT 1");
                                          EnterLong(1, ent1, "Buy VXX");    
                                          SetProfitTarget("SHORT LIMIT 1", CalculationMode.Price, Close[0] - scalp);    
                                          
                                      }    
                                      if (Condition <Var2 )
                                      {
                                          ExitShort("", "");    
                                          ExitLong(1,ent1,"Exit Long VXX","Buy VXX");
                                      }
                          
                                      // Condition set 3
                                      if (Condition < Var3 && Position.MarketPosition == MarketPosition.Flat)
                                      {
                                          myOrderLong = EnterLongLimit(0, true, ent1,GetCurrentBid(),"LONG LIMIT 1");
                                          EnterShort(1, ent1, "Sell VXX");
                                          SetProfitTarget("LONG LIMIT 1", CalculationMode.Price, Close[0] + scalp);                
                                      }
                                      // Condition set 4
                                      if (Condition > Var4 )
                                      {
                                          ExitLong("", "");
                                          ExitShort(1,ent1,"Exit Short VXX","Sell VXX");
                                      }
                      This is what i have so far. I changed the Orderstate.filled so that i could backtest on it.would pending submit work with backtesting or would i need realtime data
                      Last edited by cboat; 08-09-2010, 10:41 AM.

                      Comment


                        #12
                        PendingSubmit will work in a backtest - NinjaTrader will simulate all the appropriate order states. The best way to evaluate this is in real time or market replay. You lose a lot of granularity for these statements during a backtest.

                        My suspicion is that you're submitting exit orders when your Profit Target state is working.
                        order.OrderState == OrderState.Working

                        These orders will typically be working upon entry execution and so you might see an exit on SPY anytime you enter on your primary series.

                        This is just a guess here. Please clarify what you're looking for versus what you're seeing.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          What i'm looking for is:
                          Using the Momentum indicator.
                          The Primary instrument will enter short above 2 and the Secondary instrument enters Long. There are two exit conditions. First, if the Primary instrument only, reaches a profit target of 10 ticks it will exit it's short and the Secondary instrument should exit it's long regardless of whether it has hit a profit target or not. So, they should exit simultaneously.
                          The second exit condition is they will both exit there positions if the the Momentum indicator falls below 1.
                          The conditions above are reversed for longs of the Primary instrument.
                          So, all indicator entries and exits as well as profit targets are based solely on the conditions of the primary instrument.
                          let me know if you need further clarification. I'll try the real time backtest now.
                          Thanks

                          Comment


                            #14
                            Thanks - please let us know how it goes when you make the suggested change. You were submitting exit orders to the secondary series whenever profit target status = working.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Ryan Thank you everything seems to be working correctly except for one final hiccup. When the profit target is met on the SPY the VXX does not exit it's position until the open of the next bar.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jleira, Today, 10:26 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post jleira
                              by jleira
                               
                              Started by wuileng, Today, 10:14 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post wuileng
                              by wuileng
                               
                              Started by mntemel, Today, 09:07 PM
                              1 response
                              10 views
                              0 likes
                              Last Post MojoJojo  
                              Started by martyn73, Today, 08:22 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Marco  
                              Started by RobertoPaez, Today, 08:13 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post RobertoPaez  
                              Working...
                              X