Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi instrument Donchian Channel

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

    Multi instrument Donchian Channel

    I am migrating code from NT7 to NT 8 and am confronted with the following issue.
    I am using multiple instruments AAPL and AXP. I have the following statement under State.Configure:
    AddDataSeries
    ("AXP", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);

    I have the following statement under OnBarUpdate():
    DonchianLow = DonchianChannel(5.Lower[1];
    if (Close[0]<DonchianLow)
    {placeorder()};

    I launch a Strategy with instrument AAPL. DonchianLow then calculates the correct value for AAPL but incorrectly gives the same value when calculating DonchianLow for AXP - even though BarsInProgress = 1.
    The Strategy then compares Close[0] for AXP to DonchianLow for AAPL and places an order.

    Why is DonchianLow not calculated for the instrument BarsInProgress=1 (AXP) but is instead calculated for the instrument BarsInProgress=0 (AAPL)?




    #2
    Try BarsInProgress == 1

    Comment


      #3
      I am not using BarsInProgress=1 nor BarsInProgress==1.
      After OnBarUpdate() the instrument should switch from AAPL to AXP for calculation of the DonchianChannel function. It seems to do this correctly in NT7 but incorrectly in NT8?

      Comment


        #4
        Hello,

        Thank you for the post.

        I wanted to see if you could provide a copy of the syntax you have in OnBarUpdate currently. I am not able to tell from what you provided already what the problem could be or what Prints you are using to see it is not changing. If you could provide your test that would be helpful.

        I could suggest to also try using the overload that takes a Series like the following:

        Code:
        DonchianChannel(Closes[1], 5).Upper[0];
        I look forward to being of further assistance.

        Comment


          #5
          I tied your suggestion and am using DonchianChannel(Closes[BarsInProgress], 5).Lower[1]; but that does not bring an improvement.

          I am using the following code:
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {......}
          else if (State == State.Configure)
          {

          AddDataSeries("AXP", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
          }
          //+------------------------------------------------------------------+
          //Function to check if Donchian low is crossed down
          //+------------------------------------------------------------------+
          private bool BelowDonchian()
          {
          bool LowPrice = false;
          double DonchianLow = -1000000000;
          DonchianLow = DonchianChannel(Closes[BarsInProgress],8).Lower[1];
          Print(Time[0]+" DonchianLow: "+DonchianLow+ " Close: "+ Close[0]+" BarsInProgress: "+BarsInProgress);
          if (Close[0]<DonchianLow)
          {LowPrice = true;}
          return(LowPrice);
          }

          protectedoverridevoidOnBarUpdate()
          {
          if (CurrentBars[BarsInProgress] >= BarsRequiredToTrade)
          {
          bool PositionFlat = (Positions[BarsInProgress].MarketPosition == MarketPosition.Flat);
          if (PositionFlat&&BelowDonchian()&&TrendUp())
          {BuyOrder();}
          }
          }

          I then launch the Strategy tester on AAPL dayly bars and get the following output:
          9/13/2016 10:00:00 PM DonchianLow: 102.53 Close: 107.95 BarsInProgress: 0
          9/13/2016 10:00:00 PM DonchianLow: 102.53 Close: 64.36 BarsInProgress: 1

          The second print shows that the DonchianChannel is always based on AAPL whereas it should be based on AAPL if BarsInProgress == 0 and based on AXP if BarsInProgress ==1.

          Any idea how I can repair this?

          Comment


            #6
            Hello PaulZ,

            Thanks for your reply.

            What version of NinjaTrader8 are you using? This can be found in the NinjaTrader control center through Help>About.

            Comment


              #7
              8.0.2.0 64-bit

              Comment


                #8
                Hello PaulZ,

                Thanks for your reply.

                Please update to 8.0.4.0 at this link: http://ninjatrader.com/PlatformDirect (You will need your license key)

                Once updated please test again and update this thread.

                Comment


                  #9
                  I upgraded to NT 8.0.4.0 and the program now runs as it should.
                  So, this was a bug in NT 8.0.2.0 that has been fixed recently?

                  Comment


                    #10
                    Hello,

                    Thanks for your reply.

                    It was fixed in 8.0.4.0.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    44 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    124 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    65 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    42 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    46 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X