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

DonchianChannel problem

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

    DonchianChannel problem

    Hello. I'm newbie in writing ninjascript. I have created a very simple to learn more. But when I apply it to the chart, it cannot come out any result. Would anyone please kindly help to tell me what's wrong in the script. many thanks.

    // Condition set 1
    if (High[0] > DonchianChannel(14).Upper[25])
    {
    DrawDot("My dot" + CurrentBar, true, 0, Low[0] + -5 * TickSize, Color.Blue);
    }


    I just want it to plot a dot when the high of current bar is higher than the highest of 14 bars with starting from 25 bars ago.

    #2
    Hello oldboy,

    Thanks for the post and welcome to the NinjaTrader forums. You will likely see an error on the log tab of the control center for this.

    Please see here for most likely reason why your indicator does not draw:


    To resolve, add something like this to prevent processing for the first so many bars.
    if (CurrentBar < 25) return;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Dear Ryan,

      many thanks for your speedy reply. I read the post and edit my code. I have tried three ways but unfortunately the error in log still exist. Here is those I have tried.

      1.
      protected override void OnBarUpdate()
      {
      if(CurrentBar<25)
      return;

      // Condition set 1

      if (High[0] > DonchianChannel(14).Upper[25])
      {
      DrawDot("My dot" + CurrentBar, true, 0, Low[0] + -5 * TickSize, Color.Blue);
      }
      }

      2.
      protected override void OnBarUpdate()
      {
      // Condition set 1

      if (High[0] > DonchianChannel(14).Upper[25][Math.Min(CurrentBar,25)])
      {
      DrawDot("My dot" + CurrentBar, true, 0, Low[0] + -5 * TickSize, Color.Blue);
      }
      }

      3.
      protected override void OnBarUpdate()
      {
      if(CurrentBar<25)
      return;

      // Condition set 1

      if (High[0] > DonchianChannel(14).Upper[25][Math.Min(CurrentBar,25)])
      {
      DrawDot("My dot" + CurrentBar, true, 0, Low[0] + -5 * TickSize, Color.Blue);
      }
      }

      Comment


        #4
        What is the error message you get in log tab? After making any code changes did you also Right Click > Reload NinjaScript from your chart?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I have reload after each change. And the error is the same like this.

          "Error on calling 'OnBarUpdate' method for strategy 'MyCustomStrategy': Index was out of range. Must be non-negative and less than the size of the collection.
          Parameter name: index,"

          Many thanks.

          Comment


            #6
            I'm not sure. I copy-pasted exactly using your approach #1 and I'm able to see dots.

            What are the details of the chart you're applying this to?
            • Instrument
            • Interval
            • Data Provider
            • Days to load


            If it helps, I attached the script I'm using here. Can import it using File > Utilties > Import NinjaSCript.
            Attached Files
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Dear Ryan,

              The script is created on NT 6.5. And I upgrade to 7.0 and recreate again. It works. Cheers.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Shansen, 08-30-2019, 10:18 PM
              24 responses
              939 views
              0 likes
              Last Post spwizard  
              Started by Max238, Today, 01:28 AM
              0 responses
              7 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by rocketman7, Today, 01:00 AM
              0 responses
              4 views
              0 likes
              Last Post rocketman7  
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              28 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              33 views
              0 likes
              Last Post wzgy0920  
              Working...
              X