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

How to reference a SuperTrend arrow?

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

    How to reference a SuperTrend arrow?

    Hi there,

    I'm integrating a Supertrend indicator I found in your "Version 7 Indicators" forum, and I'm able to access the UpTrend and DownTrend values found in the DataBox.

    While I could easily write some code that distinguishes when a trend reverses via the indicator (i.e. when UpTrend and DownTrend equal each other), is there a way to access the tag number of the arrow that's drawn?

    I know the syntax is something like (arrow.CurrentBar), but the following code from the indicator doesn't give me a clue how to bring it up:

    Code:
    if (CurrentBar < Lenght)
    				{ 
    					Trend.Set(true);
    					UpTrend.Set (Close[0]); 
    					DownTrend.Set(Close[0]);
    					return; 
    				};
    			if (Close[0]>DownTrend[1])
    				Trend.Set(true);
    			else
    				if (Close[0]<UpTrend[1])
    					Trend.Set(false);
    				else
    					Trend.Set(Trend[1]);
    			if(Trend[0] && !Trend[1])
    			{
    				UpTrend.Set(Median[0] - ATR(Lenght)[0]*Multiplier);
    				UpTrend.Set(1, DownTrend[1]);
    				if (ShowArrows)
    					DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, Color.Blue);
    			} else
    				if (!Trend[0]  && Trend[1])
    				{
    					DownTrend.Set(Median[0] + ATR(Lenght)[0]*Multiplier);
    					DownTrend.Set(1, UpTrend[1]);
    					if (ShowArrows)
    						DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, Color.Red);
    				} else
    					if (Trend[0])
    						UpTrend.Set((Median[0] - ATR(Lenght)[0]*Multiplier) > UpTrend[1] ? (Median[0] - ATR(Lenght)[0]*Multiplier) : UpTrend[1]);
    					else
    						DownTrend.Set((Median[0] + ATR(Lenght)[0]*Multiplier) < DownTrend[1] ? (Median[0] + ATR(Lenght)[0]*Multiplier) : DownTrend[1]);
            }
    No worries if this isn't a supported aspect of NT and you can't comment, but was wondering for future reference as well how I can access chart elements properly via tags.

    Thanks in advance!

    #2
    Hello Spiderbird,

    Can you provide a link to the indicator you are using from the forum?

    Comment


      #3
      Hi Patrick,

      I did a little searching in the Indicators forum and couldn't find it, but it was referenced in the following thread, second post down:

      Comment


        #4
        And to correct something I typed earlier... it looks like the UpTrend/DownTrend values are never equal, so i can't go that route. Have to figure out how to reference the arrows (draw objects) on the chart by their tags.

        Comment


          #5
          More attempts... I tried using a reference from Ninjatrader Help but it can't seem to locate the draw objects associated with arrows (which are tagged by CurrentBar.ToString() in the indicator:

          Code:
          if (DrawObjects[CurrentBar.ToString()] != null && DrawObjects[CurrentBar.ToString()].DrawType == DrawType.ArrowDown)
          Didn't work though...

          Comment


            #6
            Another thought...

            I could just create a variable within the indicator to capture either the value of CurrentBar or true/false if an arrow is about to be drawn. However, I have no idea how to acquire the value of that variable in the indicator via my strategy.

            Help?

            Comment


              #7
              Hello SpiderBird,

              I have altered the code to feature an int that you can access for the bars ago that the trend changed and the arrow was plotted.

              Using my edited SuperTrend, you can call the barsAgo from another indicator or strategy in the following manner:
              Code:
              Print(CurrentBar - SuperTrend(14, 2.618, true).BarTrend[0]); // Print the bars ago of the arrow/trend change.
              Attached is the file for the SuperTrend.
              Attached Files

              Comment


                #8
                Hi Patrick!

                Thanks for the assist! Imported the new file you sent over, and it references the variable fine, but SuperTrend(14, 2, true).BarTrend[0] just returns a value of 0 on every bar.

                Additionally, there's no distinguishing between a down arrow and an up arrow in the indicator. The line of code you added (barTrend[0] = CurrentBar is the same for both down/up arrows. So while it attempts to record the CurrentBar as a value, that only helps determine when the event occured, but not what type of event it is.

                Should there be two IntSeries for these? Something like:

                Code:
                ArrowDownHappened = new IntSeries(this);  // Instead of barTrend
                ArrowUpHappened = new IntSeries(this);
                ... and link them to CurrentBar?

                Btw, why isn't CurrentBar assigning itself via the code you inserted into the SuperTrend indicator?

                Comment


                  #9
                  The SuperTrend that you find here

                  The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


                  has the trend already exposed. It comes with a public BoolSeries UpTrend that holds the value "True", if the SuperTrend is in an uptrend and that holds the value "False" when it is in a downtrend.

                  You can access the trend directly via a strategy. For example

                  Code:
                  if(anaSuperTrendM11(int multiplier, int volaPeriod, int medianPeriod).UpTrend[0] &&
                  !anaSuperTrendM11(int multiplier, int volaPeriod, int medianPeriod).UpTrend[1])
                  // do something
                  would allow you to catch an arrow up.

                  Comment


                    #10
                    Hi Harry,

                    Thanks for the link! I'm a registered user of BigMike's, but the download links don't work on that page to acquire that version of SuperTrend (M11). Likewise, the new version they point to (U11 at https://www.bigmiketrading.com/downl...load.html?view) doesn't have a download link either.

                    I'm assuming you have to be an 'Elite' member to download these files, but correct me if that's not the case. I also tried accessing the page with AdBlock off (on the chance that something was preventing me from seeing a download form element).

                    Help?

                    Comment


                      #11
                      Originally posted by Spiderbird View Post
                      Hi Harry,

                      Thanks for the link! I'm a registered user of BigMike's, but the download links don't work on that page to acquire that version of SuperTrend (M11). Likewise, the new version they point to (U11 at https://www.bigmiketrading.com/downl...load.html?view) doesn't have a download link either.

                      I'm assuming you have to be an 'Elite' member to download these files, but correct me if that's not the case. I also tried accessing the page with AdBlock off (on the chance that something was preventing me from seeing a download form element).

                      Help?
                      You need to be an elite member to download the files. Please send me a private message with your e-mail and I will send you both SuperTrend files. The M11 is easier to reference, the U11 has a few enums to select between different moving averages and volatility indicators.

                      Comment


                        #12
                        PM Sent!

                        Originally posted by Harry View Post
                        You need to be an elite member to download the files. Please send me a private message with your e-mail and I will send you both SuperTrend files. The M11 is easier to reference, the U11 has a few enums to select between different moving averages and volatility indicators.
                        Fantastic! Just sent over a PM to you. Much appreciated.

                        Comment


                          #13
                          Also figured out original problem...

                          Hi all,

                          I also figured out my mistake with the original post. Instead of modifying the indicator itself, I could have just wrote some code checking to see if the first tick of the new bar was higher than the value of the Downtrend plot for new up-trends, and vice versa.

                          So something like:
                          Code:
                          if (SuperTrend.DownTrend < Open[0])
                          { do something }
                          Not exactly right, but I hope you know what I mean.

                          Thanks to all who helped!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by CortexZenUSA, Today, 12:53 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post CortexZenUSA  
                          Started by CortexZenUSA, Today, 12:46 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post CortexZenUSA  
                          Started by usazencortex, Today, 12:43 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post usazencortex  
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          168 responses
                          2,264 views
                          0 likes
                          Last Post sidlercom80  
                          Started by Barry Milan, Yesterday, 10:35 PM
                          3 responses
                          11 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Working...
                          X