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

Slope Change Indicator

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

    Slope Change Indicator

    I have a slope indicator based on the value of SMA(3,close) which draws arrows along the slope. What I really want is to only see one arrow drawn when the slope changes and not all the way along the slope. Please see image.
    The code I have is as follows:
    // When the close of the bar with SMA(3) crosses above the SMA(3) one bar back, draw an UP ARROW
    if ((SMA(3)[0] > SMA(3)[1]))
    {
    DrawArrowUp("Up Arrow", 0, SMA(3)[0] -0.05, Color.Lime);
    }

    // Else if the close of the bar with SMA(3) crosses below the SMA(3) one bar back, draw a DOWN ARROW
    else if ((SMA(3)[0] < SMA(3)[1]))
    {
    DrawArrowDown("Down Arrow", 0, SMA(3)[0] +0.05, Color.Red);
    }
    My question is: Is there a way to draw only one arrow at a slope change?
    Thanks in advance.
    Attached Files

    #2
    Are you sure that is your exact code? If you provide the same string name the objects will just modify prior instances instead of drawing new ones.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Try this:

      if (Falling(SMA(3) && SMA(3)[1] > SMA(3)[2]))
      //plot down arrow and make sure it has a unique name such as "Down Arrow" + CurrentBar//
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        If you only want one arrow you do not want unique signal names. You want one name for each arrow you wish to draw.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          But my code would give one arrow only when the slope changes from rising to falling etc.
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment


            #6
            I have not evaluated your code and am not saying if it is right or wrong. Your code may very well work. In general though, if you only want one object drawn you want to use non-unique names. This way any further calls to that object will just be a modification of it instead of drawing a new one.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              NP Josh, it was just that I though he wanted just one arrow every time there was a change and to keep those arrows. You know much more than I but I interpreted his question differently.
              eDanny
              NinjaTrader Ecosystem Vendor - Integrity Traders

              Comment


                #8
                private bool SlopeToggle = false;

                // When the close of the bar with SMA(3) crosses above the SMA(3) one bar back, draw an UP ARROW
                if ((SMA(3)[0] > SMA(3)[1]) && !SlopeToggle)
                {
                DrawArrowUp("Up Arrow" + CurrentBar, 0, SMA(3)[0] -0.05, Color.Lime);
                SlopeToggle = true;
                }

                // Else if the close of the bar with SMA(3) crosses below the SMA(3) one bar back, draw a DOWN ARROW

                else
                if ((SMA(3)[0] < SMA(3)[1]) && SlopeToggle)
                {
                DrawArrowDown("Down Arrow" + CurrentBar, 0, SMA(3)[0] +0.05, Color.Red);
                SlopeToggle = false;
                }


                if C# is anything like C/C++ you'll want to put the SlopeToggle first in the test. C/C++ bail on the evaluation of an if statement at the first false condition. You'll save a little CPU overhead in not doing the lookups for the values of the SMA.

                Comment


                  #9
                  Thanks for all the replys.

                  Yes Josh I should have added the "+ CurrentBar" to both the "Up Arrow" and "Down Arrow" in the code I posted.

                  eDanny thanks alot for that hint. At first I could not compile the code as you posted but added parentheses and it works fine.

                  Newshues I was not able to get the SlopeToggle to work. I will try working with that some more later.

                  Code I have now is as follows:
                  // When the close of the bar with SMA(3) crosses above the SMA(3) one bar back, draw an UP ARROW
                  if (Rising(SMA(3)) && (SMA(3)[1] < SMA(3)[2]))
                  {
                  DrawArrowUp("Up Arrow" + CurrentBar, 0, SMA(5)[0] -0.25, Color.Lime);
                  }

                  // Else if the close of the bar with SMA(3) crosses below the SMA(3) one bar back, draw a DOWN ARROW
                  else if (Falling(SMA(3)) && (SMA(3)[1] > SMA(3)[2]))
                  {
                  DrawArrowDown("Down Arrow" + CurrentBar, 0, SMA(5)[0] +0.25, Color.Red);
                  }
                  Here is what I have now. Thanks all for the help.

                  Attached Files

                  Comment


                    #10
                    Actually I misunderstood you post and what you have is just the change from rising to falling of the SMA. Your test would be more like :
                    if(Close[0] > SMA(3)[1])
                    but again you would get lots off arrows. That's why Newshues tried to give you some kind of toggle.

                    Glad this works for you.
                    eDanny
                    NinjaTrader Ecosystem Vendor - Integrity Traders

                    Comment


                      #11


                      Code:
                      private bool SlopeToggle = false;  // place in the variables section
                      
                              protected override void OnBarUpdate()
                              {
                                  if ( CurrentBar == 0 )
                                      return;
                                  
                                  // When the close of the bar with SMA(3) crosses above the SMA(3) one bar back, draw an UP ARROW
                                  if ( !SlopeToggle && (Close[0] > SMA(3)[1]) )
                                  {
                                      DrawArrowUp("Up Arrow" + CurrentBar, 0, Low[0] - 0.25, Color.Lime);
                                      SlopeToggle = true;
                                  }
                                  
                                  // Else if the close of the bar with SMA(3) crosses below the SMA(3) one bar back, draw a DOWN ARROW
                                  else if ( SlopeToggle && (Close[0] < SMA(3)[1]) )
                                  {
                                      DrawArrowDown("Down Arrow" + CurrentBar, 0, High[0] + 0.25, Color.Red);
                                      SlopeToggle = false;
                                  } 
                              }
                      gives an arrow when a bar closes above or below the prior bars SMA(3) but only for the first bar to do so. Subsequent bars in a series of closes below/above the SMA(3) are ignored.

                      Comment


                        #12
                        Thanks for posting this code and screenshot Newshues!
                        BertrandNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by trilliantrader, 04-18-2024, 08:16 AM
                        4 responses
                        18 views
                        0 likes
                        Last Post trilliantrader  
                        Started by mgco4you, Today, 09:46 PM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by wzgy0920, Today, 09:53 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post wzgy0920  
                        Started by Rapine Heihei, Today, 08:19 PM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by Rapine Heihei, Today, 08:25 PM
                        0 responses
                        10 views
                        0 likes
                        Last Post Rapine Heihei  
                        Working...
                        X