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

Making a Double Top/Bottom Indicator

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

    Making a Double Top/Bottom Indicator

    This is supposed to draw a line from the high of some number of bars back to the high of the previous bar. i had to take out the code for the low but its the same for the high but using low. This isn't drawing any lines and i know one of the statements is true.
    i added print High[i] and it is getting the value of the bar on the first day of the chart and i changed it to a while loop and still same thing.
    for(i= 1; i == NumBars; i++)
    {
    if(High[i] == High[1] || High[i]+.75 == High[1] || High[i]-.75 == High[1] ||
    High[i]+
    .5 == High[1] || High[i]-.5 == High[1] ||
    High[i]+
    .25 == High[1] || High[i]-.25 == High[1])
    {
    DrawLine(
    "High", false, i, High[i], 1, High[1], Color.DarkRed, DashStyle.Dot, 2);
    }
    }
    Last edited by cbart2; 12-22-2010, 10:21 PM.

    #2
    Hello,

    Thanks for your forum post.

    NumBars What value is in here?

    Also, have you tried printing these High[1] and High[i] values during the loop. What do you find?

    Also, a disadvantage to your current code is it will run on every on bar update to check all the Highs of the entire chart. This will add a huge ammount of processing time with no cutoff from the bars being checked back unless your doing this in numBars.

    Heres what I suggest, please take a look at Swing indicator, and also ZigZag indicators. the code of which is in your NinjaTrader platform. You can even use this methos to pull out swing highs and lows and double tops or bottoms in your case with no need to code your own version.

    Let me know if I can be of further assistance.

    Comment


      #3
      well NumBars is a user input for now i had entered 6 so it would look back only 6 bars. High[1] i didnt try to check but high[0] is giving me the value of the first bar if i scroll back to the first day of the chart. i need to make my own because i want to have alarms in it and some other things that those dont have. Also i noticed that it is not going through the for loop it is only doing it once and if i put a negative number for i it will look forward from the first bar on the chart.
      Last edited by cbart2; 12-23-2010, 09:41 AM.

      Comment


        #4
        Hello,

        Please add a Print("This was supposed to draw a line"); statement right above your drawLine call. Does this print to the output window when you run your code?

        I look forward to assisting you further.

        Comment


          #5
          i did and it doesnt show nothing in the ouput window. For some reason its not starting at the current bar. I noticed it is going from the first bar of the first day on the chart instead of the current bar on the current day. So it cant look back any further because there is no more bars to look back at.

          i also put in a negative number for i and it went forwards to that number of bars from the first bar but it still doesnt run through the for loop but only once.

          High[0] should give me the value of the current bar and not from the first bar on the chart because that would be around High[240] for 5 days on a 30 minute chart.
          Last edited by cbart2; 12-23-2010, 10:05 AM.

          Comment


            #6
            Hello,

            Are you only wanting to run this live or on historical data.

            Also, do you see any errors in the log tab of the control center.

            I look forward to assisting you further.

            Comment


              #7
              yes this is on a live chart.

              this is the error im getting

              ########
              DefaultError on calling the 'OnBarUpdate' method for indicator 'DoubleTopBottom' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection.

              Comment


                #8
                Hello,

                Thanks for the information. This is the issue.

                You either need to run this on lie data only using the following check:



                Or check to make sure you have at least Numbars varible number of bars on the chart.

                Using this:



                Let me know if I can be of further assistance.

                Comment


                  #9
                  yeah for some reason i always forget to put in
                  if(CurrentBar < 1)
                  return;
                  but 1 doesnt work if i put NumBars it does.
                  if i put 1 it still starts at the first bar on the first day
                  Last edited by cbart2; 12-23-2010, 11:20 AM.

                  Comment


                    #10
                    Hello,

                    Right.

                    Essentially you have to think this way. Your strategy starts to run on Bar 1. On bar one its executing the loop to look at the highs of 6 bars back or the number of bars you specify in numBar variable that is user defined.

                    This errors and the strategy doesnt run.

                    Therefor you need to not check just for 1 bar in your case. YOu need to check for at least 6, or more specifically currently the number of bars yor requested your for loop to process back set by the user/you.

                    Let me know if I can be of further assistance.

                    Comment


                      #11
                      Thank you. That is all i need for now. Now i need to check if one of the bars is the High or Low of the day and then look at the other bars for the double top.

                      Actually i just noticed that it is not drawing a line from some highs and lows that are equal within the 6 bars specified.
                      Last edited by cbart2; 12-23-2010, 12:26 PM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Segwin, 05-07-2018, 02:15 PM
                      14 responses
                      1,789 views
                      0 likes
                      Last Post aligator  
                      Started by Jimmyk, 01-26-2018, 05:19 AM
                      6 responses
                      837 views
                      0 likes
                      Last Post emuns
                      by emuns
                       
                      Started by jxs_xrj, 01-12-2020, 09:49 AM
                      6 responses
                      3,294 views
                      1 like
                      Last Post jgualdronc  
                      Started by Touch-Ups, Today, 10:36 AM
                      0 responses
                      13 views
                      0 likes
                      Last Post Touch-Ups  
                      Started by geddyisodin, 04-25-2024, 05:20 AM
                      11 responses
                      63 views
                      0 likes
                      Last Post halgo_boulder  
                      Working...
                      X