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 algospoke, 04-17-2024, 06:40 PM
              6 responses
              48 views
              0 likes
              Last Post algospoke  
              Started by arvidvanstaey, Today, 02:19 PM
              4 responses
              11 views
              0 likes
              Last Post arvidvanstaey  
              Started by samish18, 04-17-2024, 08:57 AM
              16 responses
              61 views
              0 likes
              Last Post samish18  
              Started by jordanq2, Today, 03:10 PM
              2 responses
              9 views
              0 likes
              Last Post jordanq2  
              Started by traderqz, Today, 12:06 AM
              10 responses
              18 views
              0 likes
              Last Post traderqz  
              Working...
              X