Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting Lines at nearest 1/8 centries

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

    Plotting Lines at nearest 1/8 centries

    What im trying to do here is get the value of the current bar and Draw lines at the nearest 1/8 centries. For some reason this isn't working. I think my math is correct but i just cant seem to get this to work.

    for (int EC = 0; EC >= 15; EC++)
    {
    if (((EC + 1) * 100) - Close[0] <= 100 && Close[0] - (EC * 100) >= 87.5)
    {
    PlotECAbove.Set((EC +
    1) * 100);
    PlotECBelow.Set((EC *
    100) + 87.5);
    }

    #2
    Originally posted by cbart_1 View Post
    What im trying to do here is get the value of the current bar and Draw lines at the nearest 1/8 centries. For some reason this isn't working. I think my math is correct but i just cant seem to get this to work.

    for (int EC = 0; EC >= 15; EC++)
    {
    if (((EC + 1) * 100) - Close[0] <= 100 && Close[0] - (EC * 100) >= 87.5)
    {
    PlotECAbove.Set((EC +
    1) * 100);
    PlotECBelow.Set((EC *
    100) + 87.5);
    }
    Your for loop control expression can never be satisfied, so the loop is never entered.

    Comment


      #3
      I dont understand

      I dont understand am i just missing something or is it not possible the way im trying. this is what i have trying to check every 12.5 points.

      if (Close[0] - (EC * 100) <= 87.5 && Close[0] - (EC * 100) >= 75)
      {
      PlotECAbove.Set((EC *
      100) + 87.5);
      PlotECBelow.Set((EC *
      100) + 75);
      break;
      }
      if (Close[0] - (EC * 100) <= 75 && Close[0] - (EC * 100) >= 62.5)
      {
      PlotECAbove.Set((EC *
      100) + 75);
      PlotECBelow.Set((EC *
      100) + 62.5);
      break;
      }
      ...

      Comment


        #4
        Originally posted by cbart_1 View Post
        I dont understand am i just missing something or is it not possible the way im trying. this is what i have trying to check every 12.5 points.

        if (Close[0] - (EC * 100) <= 87.5 && Close[0] - (EC * 100) >= 75)
        {
        PlotECAbove.Set((EC *
        100) + 87.5);
        PlotECBelow.Set((EC *
        100) + 75);
        break;
        }
        if (Close[0] - (EC * 100) <= 75 && Close[0] - (EC * 100) >= 62.5)
        {
        PlotECAbove.Set((EC *
        100) + 75);
        PlotECBelow.Set((EC *
        100) + 62.5);
        break;
        }
        ...
        I understand what you are trying to do: that is not what you are telling the computer to do. Translate your for loop control expression into natural language, and you will see that it can never be satisfied. Ergo, the loop is never entered.

        Comment


          #5
          ok i realized i had the &gt;= wrong

          It should be <=. i guess that is why it isnt entering the loop. but i changed it and i still get no lines plotted.

          Comment


            #6
            cbart_1, any log errors seen as you apply your study? Please put a few prints in to check if the condition coded in ever triggers for you?

            Comment


              #7
              now i get an error in the output window

              Error on calling 'OnBarUpdate' method for indicator 'EightCentryPrices' on bar 1: Index was outside the bounds of the array.

              Comment


                #8
                cbart,

                Please make sure you have enough bars on your chart for this script to function - you're likely running into an issue explained int he following forum post:
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Im getting the error on that line of code

                  if(CurrentBar < 1)
                  return;

                  Error on calling 'OnBarUpdate' method for indicator 'EightCentryPrices' on bar 1: Index was outside the bounds of the array.

                  this is what is giving the error if i change it to any other number like 0.
                  It says:

                  Error on calling 'OnBarUpdate' method for indicator 'EightCentryPrices' on bar 0: Index was outside the bounds of the array.

                  Comment


                    #10
                    Hello,

                    Are you adding more than one data series to this script? Are you still using the same code you posted in post #3?

                    Have you tried commenting out various lines and checking to see if you can isolate this error to a single line of code? If so, can you please provide me with the line that is introducing issues?

                    More information on Debugging can be found below:

                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      ok i noticed it is starting at the first bar on the chart not the curent bar

                      Why is it starting at the first bar on the chart instead of the current bar.

                      Comment


                        #12
                        Hello,

                        CurrentBar is indexed from left to right.

                        CurrentBar 0 would be the first bar on the chart.

                        Please review our Tip section on Referencing the correct bar:

                        MatthewNinjaTrader Product Management

                        Comment


                          #13
                          I have had this problem before

                          I cant find what is wrong i will just come back to it another day.

                          Comment


                            #14
                            here is my code

                            if(CurrentBars[0] < 15
                            return;
                            ECC.Set(Close[
                            0]);
                            Print(ECC[
                            0]);
                            for(EC = 15; EC <= 0; EC--)
                            {

                            if (((EC + 1) * 100) - ECC[0] <= 100 && ECC[0] - (EC * 100) >= 87.5)
                            {
                            TL = ((EC +
                            1) * 100);
                            BL = (EC *
                            100) + 87.5;
                            PlotECAbove.Set(TL);
                            PlotECBelow.Set(BL);
                            break;
                            }

                            Comment


                              #15
                              it continues on to check for 0 to 12.5

                              I changed the for(EC = 15; EC <= 0; EC--)
                              to
                              for(EC = 15; EC != 0; EC--).
                              It is entering the loop but when it gets to the correct if statement it gives an error.

                              I put Print(EC); in the for loop and it prints 15, 14, 13, 12 , 11 and then it gives the error:

                              Error on calling 'OnBarUpdate' method for indicator 'EightCentryPrices' on bar 15: Index was outside the bounds of the array.
                              Last edited by cbart_1; 09-23-2011, 12:31 PM. Reason: found out more

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              600 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              347 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              558 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              558 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X