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

Multi Instrument Strategy

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

    Multi Instrument Strategy

    Hi,

    Quick question;

    I'm trying to develop a strategy that has 5 symbols. I want to verify a few questions before I start coding:

    I understand that I will need to add data series for each symbol. But under the current setup of NT, I understand that the "primary" data series will always be the data series I load. Say primary is Y

    For example, say I added:
    X min data for EUR/usd
    X min data for EUR/AUD
    X min data for EUR/TRY
    X min data for EUR/JPY

    How can I make sure that X always equals Y without having to manually adjust the time frames I am loading for the above tickers to match the time series that I loaded for the primary symbol?

    The reason why I need this is because I want to be able to easily test multiple time series against my tickers.

    I want to be able to analyze each dataseries and enter based on their output rather than enter long/short based on primary dataseries alone. I could test the same strategy against a "list" of symbols in strategy analyzer, but that limits my risk management. Therefore, I want to create one strategy that has multiple logics for each symbol, multi risk managements for each symbol but I want to test them all at the same time in one single strategy.

    In short; how can I make:
    Code:
    Data.BarsPeriodType.Minute, 1,
    for each "added" ticker to by same as the primary data series without having to manually adjust it each time.

    Thank you
    Last edited by staycool3_a; 12-10-2017, 08:21 PM.

    #2
    Hello calhawk01,

    Thank you for your note.

    You could use the following syntax,

    AddDataSeries(BarsPeriodType periodType, int period)


    Which would look like,

    AddDataSeries(BarsPeriodType.Minute, 1);

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      Hello calhawk01,

      Thank you for your note.

      You could use the following syntax,

      AddDataSeries(BarsPeriodType periodType, int period)


      Which would look like,

      AddDataSeries(BarsPeriodType.Minute, 1);

      Please let us know if you need further assistance.
      Your suggestion is exactly what I posted in my original post. My question is, how can I add additional data series that match whatever period type and minute int is added on the primary, AUTOMATICALLY.

      Another example:

      Say I load primary data series as 5 minute

      How can I code my secondary data series so they match data loaded on primary (5 minute) WITHOUT having to manually adjust the code.

      Another question:

      Is there a way to access tradeperformance data for individual instruments within a strategy: example: I have 10 symbols being traded within 1 strategy. One of them is audnzd. I'd like to access the tradeperformance for ONLY audnzd. How? I believe for n7 you could only access primary symbols trade performance? Can I access each instruments tradeperformance within ONE strategy in n8?

      Thank you
      Last edited by staycool3_a; 12-11-2017, 11:57 PM.

      Comment


        #4
        Hello calhawk01,

        There is no syntax which would allow this however I will put in a feature request for the following syntax,

        Code:
        AddDataSeries(string instrumentName);
        The closest syntax for what you’re trying to do is the following, would just require the instrument name and the Bars Period.

        Code:
        AddDataSeries(string instrumentName, BarsPeriod barsPeriod)
        Regarding trade performance by instrument, I put together a sample which will loop through trade performance on each bar and depending on whether a trade was NQ or ES, will assign the PL to a variable, nqProfit/ esProfit, then print this to the output window.

        I would suggest testing the strategy on an ES 1 second chart with an output window open.

        Please let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_AlanP View Post
          Hello calhawk01,

          There is no syntax which would allow this however I will put in a feature request for the following syntax,

          Code:
          AddDataSeries(string instrumentName);
          The closest syntax for what you’re trying to do is the following, would just require the instrument name and the Bars Period.

          Code:
          AddDataSeries(string instrumentName, BarsPeriod barsPeriod)
          Regarding trade performance by instrument, I put together a sample which will loop through trade performance on each bar and depending on whether a trade was NQ or ES, will assign the PL to a variable, nqProfit/ esProfit, then print this to the output window.

          I would suggest testing the strategy on an ES 1 second chart with an output window open.

          Please let us know if you need further assistance.
          thank you for the sample

          Comment


            #6
            Originally posted by NinjaTrader_AlanP View Post
            Hello calhawk01,

            There is no syntax which would allow this however I will put in a feature request for the following syntax,

            Code:
            AddDataSeries(string instrumentName);
            The closest syntax for what you’re trying to do is the following, would just require the instrument name and the Bars Period.

            Code:
            AddDataSeries(string instrumentName, BarsPeriod barsPeriod)
            Regarding trade performance by instrument, I put together a sample which will loop through trade performance on each bar and depending on whether a trade was NQ or ES, will assign the PL to a variable, nqProfit/ esProfit, then print this to the output window.

            I would suggest testing the strategy on an ES 1 second chart with an output window open.

            Please let us know if you need further assistance.
            I'm curious what your thoughts are on the below solution. What if I add a bool, this way I can select different int periods based on my selection of the bool variable:

            Code:
            			else if (tenmin == true && State == State.Configure)
            			{
            				AddDataSeries("NZDUSD",Data.BarsPeriodType.Minute, 1);//1
            				AddDataSeries("AUDUSD",Data.BarsPeriodType.Minute, 1);//2
            				AddDataSeries("AUDNZD",Data.BarsPeriodType.Minute, 1);//3
            				AddDataSeries("EURUSD",Data.BarsPeriodType.Minute, 1);//4		
            				AddDataSeries("USDCAD",Data.BarsPeriodType.Minute, 1);//5				
            				AddDataSeries("NZDUSD", Data.BarsPeriodType.Minute, 10, Data.MarketDataType.Last);//6
            				AddDataSeries("AUDUSD", Data.BarsPeriodType.Minute, 10, Data.MarketDataType.Last);//7
            				AddDataSeries("AUDNZD", Data.BarsPeriodType.Minute, 10, Data.MarketDataType.Last);//8
            				AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 10, Data.MarketDataType.Last);//9
            				AddDataSeries("USDCAD", Data.BarsPeriodType.Minute, 10, Data.MarketDataType.Last);//10
            			}
            			else if (sixtymin == true && State == State.Configure)
            			{
            				AddDataSeries("NZDUSD",Data.BarsPeriodType.Minute, 1);//1
            				AddDataSeries("AUDUSD",Data.BarsPeriodType.Minute, 1);//2
            				AddDataSeries("AUDNZD",Data.BarsPeriodType.Minute, 1);//3
            				AddDataSeries("EURUSD",Data.BarsPeriodType.Minute, 1);//4		
            				AddDataSeries("USDCAD",Data.BarsPeriodType.Minute, 1);//5				
            				AddDataSeries("NZDUSD", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);//6
            				AddDataSeries("AUDUSD", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);//7
            				AddDataSeries("AUDNZD", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);//8
            				AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);//9
            				AddDataSeries("USDCAD", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);//10
            			}
            			
            			else if (5min == true && State == State.Configure)
            			{
            				AddDataSeries("NZDUSD",Data.BarsPeriodType.Minute, 1);//1
            				AddDataSeries("AUDUSD",Data.BarsPeriodType.Minute, 1);//2
            				AddDataSeries("AUDNZD",Data.BarsPeriodType.Minute, 1);//3
            				AddDataSeries("EURUSD",Data.BarsPeriodType.Minute, 1);//4		
            				AddDataSeries("USDCAD",Data.BarsPeriodType.Minute, 1);//5				
            				AddDataSeries("NZDUSD", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);//6
            				AddDataSeries("AUDUSD", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);//7
            				AddDataSeries("AUDNZD", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);//8
            				AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);//9
            				AddDataSeries("USDCAD", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);//10
            			}
            I was able to compile and run the above but i'm not sure if this will have any adverse impact that I'm not noticing. Thoughts?

            Also if the above shouldn't cause any issues, does the position of the data change? I.e primary = 0, secondary data series = 1, secondary+1 data series = 2, secondary+2 data series = 3.. and so on..
            Last edited by staycool3_a; 12-14-2017, 01:37 AM.

            Comment


              #7
              Hello calhawk01,

              I have not seen such a solution implemented before and in theory as long as you do not change your bool after initially applying the strategy in theory it should work.

              You would not want to test a strategy on 1 symbol, then switch the symbol and bool to test another. You would want to remove that instance of the strategy, and apply a new strategy per each symbol. If you were to do this I would expect the setting from the previous settings to stick. This is touched on in warning 3 at the following link,



              Please let us know if you need further assistance.
              Alan P.NinjaTrader Customer Service

              Comment


                #8
                Hi....i am a new user here. In my case I'm currently looking at a few stock rotation strategies which involve many instruments and am having some problems with backtesting.So far, NT support has not been any help, and I'm not sure if there are any better ways to approach this.
                Basically, I'd like to take the current Russell 1000 and backtest my rotation/portfolio strategy on a large chunk of 2000-2015. However, NT does not call OnBarUpdate() until there is data for all added instruments, even if code has been put in to avoid out of bounds errors.

                printed circuit assemblies
                Last edited by NealXu; 02-02-2018, 03:12 PM.

                Comment


                  #9
                  Hello NealXu,

                  Thank you for your note.

                  Without the full code we're unable to test on our end.

                  If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.

                  I look forward to your reply.
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #10
                    hi

                    suppose you have:

                    Code:
                    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);//1
                    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);//2
                    				AddDataSeries("AUDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);//3
                    				AddDataSeries("AUDUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);//4
                    				AddDataSeries("AUDNZD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);//5
                    				AddDataSeries("AUDNZD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);//6
                    				AddDataSeries("EURUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);//7
                    				AddDataSeries("EURUSD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);//8
                    				AddDataSeries("USDCAD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Ask);//9
                    				AddDataSeries("USDCAD", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Bid);//10
                    				
                    				[B]AddDataSeries("NZDUSD", Data.BarsPeriodType.Minute, 90, Data.MarketDataType.Last);//11[/B]
                    				AddDataSeries("AUDUSD", Data.BarsPeriodType.Minute, 90, Data.MarketDataType.Last);//12
                    				AddDataSeries("AUDNZD", Data.BarsPeriodType.Minute, 90, Data.MarketDataType.Last);//13
                    				AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 90, Data.MarketDataType.Last);//14
                    				AddDataSeries("USDCAD", Data.BarsPeriodType.Minute, 90, Data.MarketDataType.Last);//15
                    				
                    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);//16
                    				AddDataSeries("NZDUSD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Bid);//17
                    				AddDataSeries("AUDUSD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);//18
                    				AddDataSeries("AUDUSD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Bid);//19
                    				AddDataSeries("AUDNZD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);//20
                    				AddDataSeries("AUDNZD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Bid);//21
                    				AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);//22
                    				AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Bid);//23
                    				AddDataSeries("USDCAD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);//24
                    				AddDataSeries("USDCAD", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Bid);//25
                    then:

                    Code:
                    			if(nzd==true)
                    			{
                    			if (BarsInProgress==1 && CurrentBars[11] > BarsRequiredToTrade && [B]Positions[11].MarketPosition[/B] == MarketPosition.Flat && [B]INDICATOR[/B][0] < -Entry)
                    				
                    				{
                    				EnterLongLimit(Convert.ToInt32(nzd_Q), GetCurrentAsk(1), @"nzdb1");	
                    				}
                    And I have:

                    Code:
                    Calculate									= Calculate.OnBarClose;
                    And during strategy analyzer, I run it on a 90 minute (higher time frame). IF, my bolded INDICATOR values are being derived from my bolded dataseries of 90 min, given that my logic states, BarsInProgress==1 (which is tick data), is NT still waiting until my indicator goes below -Entry threshold based on 90 minute, and then entering on a shorter time frame (tick)?

                    Another question:

                    Given that I am entering the long position on tick data of NZDUSD (dataseries 1), would it be best practice to say, "Positions[1].MarketPosition" rather than "Positions[11].MarketPosition" (also bolded in the code)? I've been using Position[11] because dataseries 1 and 11 both are represented by NZDUSD in different time frames and have not noticed any probems. But what do you recommend and is less resource intensive?

                    I'm trying to generate my order on 90 minute based on Indicator, then enter on 1(dataseries 16) minute ask and execute it on 1 tick. The code for this is not up there, any suggestion?

                    I thought I could just point the currentask to 16 dataseries but it didn't work:

                    Code:
                    			if(nzd==true)
                    			{
                    			if (BarsInProgress==1 && CurrentBars[11] > BarsRequiredToTrade && Positions[11].MarketPosition == MarketPosition.Flat && INDICATOR[0] < -Entry)
                    				
                    				{
                    				EnterLongLimit(Convert.ToInt32(nzd_Q), GetCurrentAsk([B]16[/B]), @"nzdb1");	
                    				}
                    Last edited by staycool3_a; 12-22-2017, 02:00 PM.

                    Comment


                      #11
                      Hello calhawk01,

                      In your sample code, since its BIP==1, your enter long call would be submitted to BIP1. I might suggest using the following syntax so you have more control over which bars in progress you are submitting your order to.

                      Code:
                      EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)


                      If your indicator was SMA(BarsArray[5]), within BarsInProgress==1, it would be calculated off the 5th series added. There is not enough information about the indicator to know which BIP its being calculated off.

                      If BIP 1 is a tick series, that if statement is going to be checked on each tick. What entry threshold is at that time would depend on what entry is, I would suggest adding print statements to better understand your logic,

                      I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
                      Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


                      Regarding two additional data series of the same instrument and which one should you check, you should check the series which you submitted the order to with the EnterLongLimit syntax I added above. The helpguide suggests they may not be the same, see PositionsAccount[1] ==


                      If you need the value of the indicator on a 90 minute bar, you will have to wait for that bar to close, so checking its value on a tick series before the 90 minute bar might introduce issues. You are adding a lot of complexity with the additional bid/offer series just to discount for the bid ask spread, I wonder if you could accomplish the same by calculating an average bid/ask spread, and discounting historical performance per trade by that.

                      Please let us know if you need further assistance.
                      Alan P.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by algospoke, Yesterday, 06:40 PM
                      2 responses
                      23 views
                      0 likes
                      Last Post algospoke  
                      Started by ghoul, Today, 06:02 PM
                      3 responses
                      14 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      45 views
                      0 likes
                      Last Post jeronymite  
                      Started by Barry Milan, Yesterday, 10:35 PM
                      7 responses
                      22 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by AttiM, 02-14-2024, 05:20 PM
                      10 responses
                      181 views
                      0 likes
                      Last Post jeronymite  
                      Working...
                      X