Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Donchian Channel values in a multi-instrument strategy

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

    Donchian Channel values in a multi-instrument strategy

    Hello,

    I'm developing a multi-instrument strategy which needs to obtain DonchianChannel's upper and lower values within the "OnPositionUpdate(IPosition position)" method. All the trading logic is processed based on the primary Bars, but I'm entering positions for both--the primary and the secondary Bars instruments: if (altInUse == false) {entryOrder = EnterLong(IQ, "IQ");} else {entryOrder = EnterShort(1, aIQ, "IQ");}. The problem is the following: if I enter a secondary Bars' position: {entryOrder = EnterShort(1, aIQ, "IQ");}, I cannot then obtain the primary Bars DonchianChannel's values within the "OnPositionUpdate()" method--I receive the secondary Bars values. How can I get DonchianChannel's primary Bars values?

    Thank you!

    #2
    dmitry75, the OnPositionUpdate() would not have a BarsInProgress logic as the event you're tied to here is soley the update of the IPosition object of the strategy.

    'I cannot then obtain the primary Bars DonchianChannel's values within the "OnPositionUpdate()" method--I receive the secondary Bars values'

    Which snippet have you been using to attempt accessing the values? Have you passed the needed BarsArray to the DonchianChannel indicator?

    Comment


      #3
      Bertrand,

      here is the code:

      protected override void Initialize()
      {
      Add(AAPL, PeriodType.Minute, 1);
      ...
      }

      protected override void OnBarUpdate()
      {

      if (Historical)
      return;
      if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
      return;
      if (BarsInProgress != 0)
      ... return;
      }


      protected override void OnPositionUpdate(IPosition position)
      {
      Print (Closes[0][0]); // 38.01 (correct first Bars close)
      Print (Closes[1][0]); // 502.18 (correct second Bars close)
      Print (DonchianChannel(1).Lows[0][0]); // 502.08 (second Bars lower channel -- not the first Bars as I needed)
      Print (DonchianChannel(1).Lows[1][0]); // *NT** Error on calling 'OnPositionUpdate' method for strategy ...: Index was outside the bounds of the array.
      }


      As you can see, I can obtain the last price from both the first and the second Bars but cannot do the same with DonchianChannel's values. Why?
      Last edited by dmitry75; 08-22-2013, 08:33 AM.

      Comment


        #4
        Are you using the standard NT DonchianChannel?

        If so, you want to use the following:

        Code:
        Print (DonchianChannel(BarsArray[0], 1).Lower[0]); // Lower of primary
        Print (DonchianChannel(BarsArray[1], 1).Lower[0]); // Lower of secondary
        MatthewNinjaTrader Product Management

        Comment


          #5
          It worked. Thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 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
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X