Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on multiple instrument strategy

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

    Question on multiple instrument strategy

    Greetings

    I have read the help file on multiple instrument strategy development. While I found the information very helpful, I still have some lingering doubts.

    The strategy that I have in mind is dependent on several custom indicators that have been developed in NT 6.5. This strategy will run on a basket of 50 stocks for the daily timeframe. If I understood the help file correctly, the OnBarUpdate method will look like this:

    protected override void OnBarUpdate()
    {
    for (int i = 0; i < 50; i++)
    {
    if (BarsInProgress == i)
    {
    CustomIndicator.m_CurrentBar = CurrentBar; //needed for ref. of close, open, etc.
    if (CustomIndicator(BarsArray[i]).GetX(CurrentBar) > SOME_CONSTANT)
    {
    EnterLong();
    }
    }
    }

    Is this code snippet an accurate reflection of what needs to be done for a multiple instrument strategy?

    Thanks very much in advance.

    #2
    Not sure about your sample code. OnBarUpdate will be triggered whit BarsInProgress being set correctly. Not sure why you would need a for loop. Please check out the SampleMultiInstrument strategy.

    Comment


      #3
      Thank you for the reply, Dierk

      I looked at that previously but it seems that I misunderstood it. From studying the sample, I was under the impression that BarsArray corresponding to a symbol must be passed to built-in or custom indicators. Hence the reason for the existance of the loop.

      I take it that since the timeframes and the buy rules for all symbols are the same, the revised OnBarUpdate() code may look like this:

      CustomIndicator.m_CurrentBar = CurrentBar; //needed for ref. of close, open, etc.
      if (CustomIndicator(BarsArray[BarsInProgress]).GetX(CurrentBar) > SOME_CONSTANT)
      {
      EnterLong();
      }

      Thanks again.

      Comment


        #4
        Sorry, not sure I follow. There is no "m_CurrentBar" logic at any indicator.
        I suggest
        - running the sample to see how it works
        - copying the sample and amending it step by step to reflect your desired logic

        Comment


          #5
          No worries, Dierk. m_CurrentBar is just a class variable that was added so the prices are retreived with the bar index number.

          I will run my strategy and if problems occur, I will use the VS debugger.

          Thanks again.

          Comment


            #6
            Dierk

            I apologize but I'm still not clear how a multi symbol strategy should be coded. So let me clarify my objective:

            I have a series of custom indicators:

            MyIndicator1
            MyIndicator2

            If this was a single instrument strategy, the buy logic would look like this:

            if ((MyIndicator1().GetValue(CurrentBar) > 20) && (MyIndicator2().GetValue(CurrentBar) < 30)) EnterLong();

            For a basket of 50 symbols, the buy rules are very much the same as above. My question is does BarsArray[BarsInProgress] need to be passed to MyIndicator1 and MyIndicator2? I assume BarsInProgress is the index which is used to obtain the correct price bars for the symbol being called in OnBarUpdate.

            Thanks very much in advance.

            Comment


              #7
              Not sure what you mean by "series of indicators". There are bar series and indicators which can run on these bar series. See SampleMultiInstrument strategy where ADX running on series0 (=default) and ADX running on series1 make up a condition
              Code:
              if (ADX(14)[0] > 30 && ADX(BarsArray[1], 14)[0] > 30)
              Hope this clear the confusion.

              Comment


                #8
                SampleMultiInstrument is the reason that I ask this question. I'm not sure if BarsArray needs to b passed to the indicator object if the buy rules are exactly the same for every symbol.

                For example, let's just say the buy rule for a single symbol was if (ADX(14) > 30). The same rule will apply to every symbol in a multi-instrument strategy. So the question becomes, will BarsArray need to be passed to the ADX object or is that not necessary?

                Thanks again.

                Comment


                  #9
                  Sorry I don't follow. BarsArray[n] is the bar series for an instrument which needed to be passed in for the indicator which runs on that series. Indicator by default run on BarsArray[0], meaning no need to pass in BarsArray[0]. Hope, this clears the confusion.

                  Also: Please make sure you understood the relevant sections in the docs http://www.ninjatrader-support.com/H...struments.html

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  648 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  369 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  109 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  573 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  575 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X