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

higher highs count

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

    higher highs count

    Hello,

    Can you help me to write a scrip to count higher highs for strategy development?
    Also include to do something when count >5;

    Thanks for your help in advance.

    Laimis

    #2
    Hello Laimis,

    Thank you for your inquiry and welcome to the NinjaTrader Support Forum.

    While we do not provide coding services, I can provide you some assistance on how you can obtain the values you want.

    You can use the MAX indicator to find the highest high value over a specified period. Here's an example of how you can use this indicator:
    Code:
    // Prints the highest high value over the last 5 periods
    Print(MAX(High, 5)[0]);
    More information about utilizing the MAX indicator can be found here: http://ninjatrader.com/support/helpG...aximum_max.htm

    To have logic run when your count variable is more than 5, you can utilize an if statement:
    Code:
    if (count > 5) // if the count is more than 5, do something
    {
         // do something
    }
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      thanks for reply,

      I was looking for higher not highest high.

      I mean:
      if (High[0] > High[1])
      {
      // do something
      }

      but if there was 5th time it have met this criteria, then do something else..


      Sorry, I wasn't clear enough.
      Laimis

      Comment


        #4
        Hello Laimis,

        I apologize for the misunderstanding.

        You could do something like this:
        Code:
        if (High[0] > High[1])
        {
             count++;
             if (count < 5)
             {
                  // do something
             }
             else if (count >= 5)
             {
                  // do something else
             }
        }
        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hey, thanks for quick response!

          I will try this out.

          Laimis

          Comment


            #6
            Can I do the same, but instead of just counting, check 10 bars ago if there was a higher high?
            should I use the same count or something else?

            Code:
            if (/*criteria*/)
            {
            // check 10 bars ago[INDENT]if (High[0] > High[1])
            {
            // first time do something
            // second time do something else
            }[/INDENT]
            }
            ZacharyG,
            I want to count how many times there was higher highs since last swing.high when price went lower.
            And due to the lack of knowledge I am completely confused. maybe I am approaching this in a wrong way?

            Thanks again for your effort.
            Laimis

            Comment


              #7
              Hello Laimis,

              Just to clarify, can you please provide a screenshot of a chart with the Swing indicator loaded on it of what values you are trying to obtain?

              To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

              Click here for instructions

              Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

              Click here for detailed instruction
              Zachary G.NinjaTrader Customer Service

              Comment


                #8
                Hello again,

                please find attached file.

                my script looks like this. problem, it still count only 1st higher high, but not second, third, etc.

                Code:
                		protected override void OnBarUpdate()
                        {
                			
                			for (int count = 0; count < 2; count++)
                			{
                				if (High[0] < Swing(3).SwingHigh[0])
                				{
                					if (High[0] > High[1])
                					{
                						if (count ==1)
                							DrawText("My text" + CurrentBar, "1st", 1, Low[1] + -1 * TickSize, Color.Blue);
                						if (count == 2)
                							DrawText("My text" + CurrentBar, "2nd", 1, Low[1] + -1 * TickSize, Color.Green);
                						//etc...
                					}
                				}
                			}
                		}
                Attached Files
                Last edited by Laimis; 10-25-2015, 10:26 AM.

                Comment


                  #9
                  Hello Laimis,

                  Please take a look at the condition you have specified for your for loop:
                  count < 2

                  This would mean that if your count was 2, the for loop won't execute again because 2 is not less than 2. The for loop will only execute the first time (count == 0) and the second (count == 1).

                  Please note that the logic you have provided will have each of your DrawText instances overwrite the previous one. You are checking the same bars on every iteration and placing your DrawText at the same location.

                  You will want to make sure to increment the barsAgo values for the High[0] > High[1] as well. With the code you have provided, only the current bar and previous bar will be evaluated every time in your loop.

                  Here's an example:
                  if (High[count] > High[count + 1])
                  Zachary G.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bmartz, 03-12-2024, 06:12 AM
                  4 responses
                  32 views
                  0 likes
                  Last Post bmartz
                  by bmartz
                   
                  Started by Aviram Y, Today, 05:29 AM
                  4 responses
                  12 views
                  0 likes
                  Last Post Aviram Y  
                  Started by algospoke, 04-17-2024, 06:40 PM
                  3 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by gentlebenthebear, Today, 01:30 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by cls71, Today, 04:45 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X