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

Using one market to trigger a trade in another

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

    Using one market to trigger a trade in another

    Hello

    I'd like to automate a strategy where I'm using a certain condition in market A to trigger a buy/sell order in market B.

    As this is probably a bit unusual I haven't found any hints on the forum and would thus very much appreciate any pointers.

    Thanks in advance.

    #2
    Hello laocoon,

    You may use a Multiseries script to be able to compare different Instruments/Markets to each other and enter an order in either Markets. Here is a link to our Help Guide that goes over in detail about the Multiseries scripts that you may view.


    Also, NinjaTrader does come reloaded with a sample NinjaScript Strategy that you may view that demonstrates this as well by going to Tools -> Edit NinjaScript -> Strategies and double click on the "SampleMultiInstrument" strategy.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hello JC

      Thanks for your reply. I've read about the Multiseries scripts and I'm familiar with the SampleMultiInstrument strategy but I don't understand where in the buy order syntax you can specify which market to trade. Usually, this problem doesn't even occur because the strategy is enabled in the same market where it's traded, but in this specific case it's different as the market that provides the entry criteria is a different one than the one that is traded.

      In the SampleMultiInstrument strategy the example says: EnterLongLimit(GetCurrentAsk(), "RSI");
      If I enable this strategy in Market A, but want to trade Market B if certain criteria in Market A are met, it should be modified along those lines, but this doesn't work.

      EnterLongLimit "Market B" (GetCurrentAsk(), "RSI");

      Thanks

      Comment


        #4
        Hello laocoon,

        Are you changing or checking the BarsInProgress to enter the market in the Instrument that you would like?

        See example below:
        Code:
        protected override void Initialize()
        {
        	// Add an MSFT 1 minute Bars object to the strategy. "MSFT" will be set to BarsInProgress = 1, since the instrument that the Strategy is applied to is BarsInProgress = 0.
        	Add("MSFT", PeriodType.Minute, 1);
        
                // Sets a 20 tick trailing stop for an open position
        	SetTrailStop(CalculationMode.Ticks, 20);
        }
        
        protected override void OnBarUpdate()
        {	
                //Checks to see if the Close of the Primary Series or the Instrument that the Strategy is applied to current bars is greater than the 1 bar ago
        	if (Closes[0][0] > Closes[0][1])
        	{
        		// Checks to make sure that BarsInProgress is 1 or the "MSFT"
        		if (BarsInProgress == 1)
        		{
                                // Enter Long Position in the "MSFT" Instrument
        			EnterLong();
        		}
        	}
        }
        JCNinjaTrader Customer Service

        Comment


          #5
          Hello JC,

          BarsInProgress is indeed the way to go, but I always find it a little difficult to figure out the right syntax when calling an indicator for a Secondary Series (the same indicator with a Primary Series works great). In this particular case I'm using the standard BidAskHistVolume indicator in a Multi-Timeframe & Multi-Instrument strategy.

          The two variables from the indicator I'm using are: buy / sell

          buy = buys;
          sell = sells;
          buys = 0;
          sells = 0;

          In a Single-Timeframe strategy, the following snippet works fine:

          if (buy > sell && my conditions here) etc

          But in a Multi-Timeframe Strategy, I'm not sure about the correct syntax if I want to use the buys/sells from the secondary series. I've tried

          if(buy Closes[1] > sell Closes[1] && my conditions here) etc

          but it won't compile.

          I've played around with the syntax for quite some time but it just won't work.

          It would really make my weekend if you could show me the correct syntax of the above snippet.

          Thanks a lot.

          Comment


            #6
            Originally posted by laocoon View Post
            Hello JC,

            BarsInProgress is indeed the way to go, but I always find it a little difficult to figure out the right syntax when calling an indicator for a Secondary Series (the same indicator with a Primary Series works great). In this particular case I'm using the standard BidAskHistVolume indicator in a Multi-Timeframe & Multi-Instrument strategy.

            The two variables from the indicator I'm using are: buy / sell

            buy = buys;
            sell = sells;
            buys = 0;
            sells = 0;

            In a Single-Timeframe strategy, the following snippet works fine:

            if (buy > sell && my conditions here) etc

            But in a Multi-Timeframe Strategy, I'm not sure about the correct syntax if I want to use the buys/sells from the secondary series. I've tried

            if(buy Closes[1] > sell Closes[1] && my conditions here) etc

            but it won't compile.

            I've played around with the syntax for quite some time but it just won't work.

            It would really make my weekend if you could show me the correct syntax of the above snippet.

            Thanks a lot.
            You must use the correct syntax for entries in a multi-series/timeframe script. It is detailed in the help at http://www.ninjatrader.com/support/h...r_handling.htm

            In fact, the text there handles pretty much exactly what you are trying to do.

            It is also detailed in the specific help for each of the order methods. e.g., here is the blurb for EnterLongLimit().
            The following method variation is for experienced programmers who fully understand Advanced Order Handling concepts.

            EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

            Comment


              #7
              Thanks for your reply koganam. I've read and re-read the whole section about Multi-Timeframe / Multi-Instrument Strategies and the way I understand it, the following snippet should work, but it doesn't:

              Add ("ES 06-13",PeriodType.Minute, 1); //Secondary Series

              if (buy [1] [0] > sell [1] [0]) //if the buys are bigger than the sells in the ES
              //do something

              This is really quite frustrating as the exact same code works perfectly when applied to a Primary Series:
              if (buy > sell)
              //do something

              As a reminder, "buy" stands for trades at the ask or higher and "sell" stands for trades at the bid and lower, as per the standard Ninja BidAskHistVolume Indicator.

              Thanks

              Comment


                #8
                Originally posted by laocoon View Post
                Thanks for your reply koganam. I've read and re-read the whole section about Multi-Timeframe / Multi-Instrument Strategies and the way I understand it, the following snippet should work, but it doesn't:

                Add ("ES 06-13",PeriodType.Minute, 1); //Secondary Series

                if (buy [1] [0] > sell [1] [0]) //if the buys are bigger than the sells in the ES
                //do something

                This is really quite frustrating as the exact same code works perfectly when applied to a Primary Series:
                if (buy > sell)
                //do something

                As a reminder, "buy" stands for trades at the ask or higher and "sell" stands for trades at the bid and lower, as per the standard Ninja BidAskHistVolume Indicator.

                Thanks
                I have emphasized your comparisons in red. They cannot even possibly be remotely the same. In your first statement, the quantities are indexed: in the second they are not. That is just a comment on the validity of your code. You cannot just index when you please.

                Not knowing the indicator that you are using, it is hard to say how to proceed, other than to say that you must treat variables within their character. If your output that you are reading are ints, then you must treat them as ints: if they are Plots, then treat them accordingly. Ints cannot be indexed.

                As far as entering orders against a bar series, that has a specific syntax that involves the BarsInProgress parameter as an input, and is independent of whatever you are reading to make a decision.
                Last edited by koganam; 03-25-2013, 08:31 AM.

                Comment


                  #9
                  Hello laocoon,

                  The usage of your variables here depend on what kind of variable type they are.

                  In your example you use if (buy > sell). This indicates that buy is a local variable that is set to a double (a price). Unless you have rewritten your script to create the buy variable as an array of arrays this will cause an error.

                  Using BarsInProgress will allow you to specify the dataseries you would like to be using for the calculations.

                  For example:

                  if (BarsInProgress != 1)
                  return;

                  Adding this line will ensure that all following code will only execute if the secondary data series is in progress.

                  At which point you can calculate the buy and sell amounts and do comparisons.


                  Please let me know if this does not resolve your inquiry.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks a lot koganam & ChelseaB. I indeed didn't pay attention to the variable type, thus my wrong reasoning. I've found a way to make it work with BIP now.

                    Thanks again to both of you.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DawnTreader, Yesterday, 05:58 PM
                    2 responses
                    13 views
                    0 likes
                    Last Post DawnTreader  
                    Started by quicksandatl, Today, 11:11 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by OllieFeraher, Today, 11:14 AM
                    1 response
                    2 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by aman jain, 10-01-2020, 09:25 PM
                    3 responses
                    293 views
                    0 likes
                    Last Post Legiboka  
                    Started by reynoldsn, Today, 07:23 AM
                    5 responses
                    12 views
                    1 like
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X