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 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.
        JesseNinjaTrader Customer Service

        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.
            Paul H.NinjaTrader Customer Service

            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.
                Paul H.NinjaTrader Customer Service

                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.
                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by KirkHammett, Today, 03:23 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post KirkHammett  
                    Started by eleven, Yesterday, 10:06 PM
                    0 responses
                    37 views
                    0 likes
                    Last Post eleven
                    by eleven
                     
                    Started by ezrollin, Yesterday, 08:12 PM
                    7 responses
                    72 views
                    0 likes
                    Last Post bltdavid  
                    Started by kyamato, 11-23-2021, 10:51 PM
                    6 responses
                    91 views
                    0 likes
                    Last Post jeronymite  
                    Started by fscabrera03, Yesterday, 07:14 PM
                    0 responses
                    49 views
                    0 likes
                    Last Post fscabrera03  
                    Working...
                    X