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

Pattern detection via indicator

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

    Pattern detection via indicator

    I am trying to create an indicator that detects a pattern of 3 bars with the high of the middle bar is higher than the high of the surrounding 2 bars.
    Here is the code, with Overlay set to true and PlotStyle.Dot. I see nothing

    if (CurrentBar == 0) {
    Upfractal.Set(0);
    } else {

    if ((High[0] < High[1]) && (High[2] < High[1])) {
    Upfractal.Set(High[1]);
    } else {Upfractal.Set(0);}

    }


    I tried overlay set to false, and PlotStyle.Line to see if it paints in the lower panel, but in that case I see a blank panel below.

    #2
    Whenever you experience something unexpected you should inspect the logs. In your case they will indicate that
    High[2]
    is the problem, since you need to change your code like this
    if (CurrentBar <= 1) {

    Comment


      #3
      Pattern detection via indicator Reply to Thread

      Good tip... never thought of looking at the log
      Have the following log upon refreshing the chart
      "Error on calling the 'OnBarUpdate' method for indicator 'Fractals2' on bar 3: Index was out of range. Must be non-negative and less than the size of the collection."

      I did replace the (CurrentBar == 0) with (CurrentBar
      <= 1) and it gave the above error. With CurrentBar ==0 it just stated "bar 1" instead of "bar 3".

      Hoping for another clue.

      I have a different question. Who is Ninjatrader targeted to ? The programmer/investor demographic ? You need to get into super duper programming to implement anything beyond the most basic strategies. Is the average trader really into this learning curve? I really appreciate the fast response on this forum, but reading through the other posts, I see you folks do draw the line quite fast.
      Don't get me wrong - I get a gut feeling for the power of NT, but having used Metastock for a while, this is far more complex.
      Implementing the pattern detection exercise I am trying to do took me 30 seconds to do in Metastock after 2 days of using their experts !

      Originally posted by NinjaTrader_Dierk View Post
      Whenever you experience something unexpected you should inspect the logs. In your case they will indicate that
      High[2]
      is the problem, since you need to change your code like this
      if (CurrentBar <= 1) {

      Comment


        #4
        (edited my post)
        I suggest starting simple as possible and see where your code below causes the problem. You then could add more logic step-by-step.

        On NT: It depends on what you want to do: A good starter is the strategy wizard where you can implement simple strategies. More flexibility comes at the expense of coding strategies/indicators manually.
        Unfortunately we do not yet have a wizard for indicators or pattern detection.

        Comment


          #5
          Pattern detection via indicator

          re: starting simple as possible...
          does it get any simpler than ..
          if ((High[0] < High[1]) && (High[2] < High[1])) {
          MyIndicator.Set(High[1]);
          }
          How about this... Can you provide a simple example of a simple historical pattern based indicator? I understand you're not here to code my problems. But I think its a fair question.

          This thing takes 10 seconds in Metastock using the expert.
          Fine.. so why I am I still struggling with NT ? Because I was using Metastock EOD, and now considering moving to Realtime... one advantage of NT is the cost.. the other is that I need a real time trade execution platform which I don't think Metastock has.

          Originally posted by NinjaTrader_Dierk View Post
          (edited my post)
          I suggest starting simple as possible and see where your code below causes the problem. You then could add more logic step-by-step.

          On NT: It depends on what you want to do: A good starter is the strategy wizard where you can implement simple strategies. More flexibility comes at the expense of coding strategies/indicators manually.
          Unfortunately we do not yet have a wizard for indicators or pattern detection.

          Comment


            #6
            This code works perfectly on a wizard generated indicator template:
            Code:
                    protected override void OnBarUpdate()
                    {
                        if (CurrentBar <= 1) 
                            Plot0.Set(0);
                        else if (High[0] < High[1] && High[2] < High[1])
                            Plot0.Set(High[1]);
                        else 
                            Plot0.Set(0);
                    }
            Note: You need to replace Plot0 by the name of your actual plot series you entered in the wizard.

            Comment


              #7
              Pattern detection via indicator

              Thank you. This works. And I even figured out to set the Displacement value to -1 manually and save the chart template so that it appears on the actual high bar.
              Very nice.

              Originally posted by NinjaTrader_Dierk View Post
              This code works perfectly on a wizard generated indicator template:
              Code:
                      protected override void OnBarUpdate()
                      {
                          if (CurrentBar <= 1) 
                              Plot0.Set(0);
                          else if (High[0] < High[1] && High[2] < High[1])
                              Plot0.Set(High[1]);
                          else 
                              Plot0.Set(0);
                      }
              Note: You need to replace Plot0 by the name of your actual plot series you entered in the wizard.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Sparkyboy, Today, 10:57 AM
              0 responses
              3 views
              0 likes
              Last Post Sparkyboy  
              Started by TheMarlin801, 10-13-2020, 01:40 AM
              21 responses
              3,917 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by timmbbo, 07-05-2023, 10:21 PM
              3 responses
              152 views
              0 likes
              Last Post grayfrog  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              30 responses
              811 views
              1 like
              Last Post grayfrog  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Erick  
              Working...
              X