• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Upside/Downside ATR

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

    Upside/Downside ATR

    Has anyone here come across an upside/downside ATR indicator for NT8? Thanks

    #2
    Hi vstoichk, thanks for your note.

    I'm not aware of anything like this. Do you have an example from the web I can look at?
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris, don't have anything on the internet for it, but pretty simple -

      Upside ATR =20-period daily ATR + Current Low of Day

      Downside ATR = Current Hi of Day - 20-period Daily ATR

      If there is a gap open:

      Upside ATR = 20-period daily ATR + previous close

      Downside ATR = previous close - 20-period daily ATR

      Will probably try to create myself, just need to read a bit on ninja script. Any guidance on where to start would be appreciated

      Comment


        #4
        Hello vstoichk,

        I would suggest viewing the AddPlot() page of the Help Guide which demonstrates how plots are added, and how values are assigned to those plots.

        AddPlot() - https://ninjatrader.com/support/help...t8/addplot.htm

        Documentation for referencing system indicators can be found here - https://ninjatrader.com/support/help...indicators.htm

        You may also wish to use the Strategy Builder to generate and learn syntax. If you have not used this tool before, I recommend starting with the resources below. The View Code button can be helpful for learning NinjaScript.

        Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE

        Conditions examples —https://ninjatrader.com/support/help...on_builder.htm

        Actions examples — https://ninjatrader.com/support/help...us/actions.htm

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          Thanks for your post; Below is what I was able to come up with but think I'm missing something. Would you be able to help, not very experienced with this

          public class UpsideDownsideATR : Indicator
          {
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Enter the description for your new custom Indicator here.";
          Name = "UpsideDownsideATR";
          Calculate = Calculate.OnEachTick;
          IsOverlay = true;
          DisplayInDataBox = true;
          DrawOnPricePanel = true;
          DrawHorizontalGridLines = true;
          DrawVerticalGridLines = true;
          PaintPriceMarkers = true;
          ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
          //Disable this property if your indicator requires custom values that cumulate with each new market data event.
          //See Help Guide for additional information.
          IsSuspendedWhileInactive = true;

          AddPlot(Brushes.Indigo, "UpsideATR");
          AddPlot(Brushes.Indigo, "DownsideATR");

          }
          else if (State == State.Configure)
          {
          }
          }

          protected override void OnBarUpdate()
          {
          //Add your custom indicator logic here.

          double AtrValue = ATR(Closes[1], 20)[0];
          double prevClose = Close[1];
          double DownsideATR;
          double UpsideATR;


          if (!Bars.BarsType.IsIntraday) return;


          lastDate = currentDate;
          currentDate = sessionIterator.GetTradingDay(Time[0]);

          if (lastDate != currentDate || currentOpen == double.MinValue)
          {

          currentHigh = High[0];
          currentLow = Low[0];
          }

          currentHigh = Math.Max(currentHigh, High[0]);
          currentLow = Math.Min(currentLow, Low[0]);

          if (currentLow > prevClose)
          {

          UpsideATR = prevClose + AtrValue;
          DownsideATR = currentHigh - AtrValue;


          else if (currentHigh < prevCLose)

          UpsideATR = currentLow + AtrValue;
          DownsideATR = prevClose - AtrValue;

          else

          UpsideATR = currentLow + AtrValue;
          DownsideATR = currentHigh - AtrValue;
          }
          Values[0][0] = UpsideATR[0];
          Values[1][0] = DownsideATR [0];


          }

          Comment


            #6
            Hello vstoichk,

            The snippet provided does not compile in its current form.

            You will need to mind when curly braces should be open and closed, and you will also need to make sure that any variables that are referenced in the script are also created in the script.

            I suggest starting small, and to create a new in indicator using the New Indicator Wizard, (Right click on Indicator's folder in the NinjaScript Editor and select New Indicator). Next you can assign Values[0][0] to a value like Close[0] and add plots following the AddPlot documentation page. Once that is working, I suggest comparing your code to existing indicators to get more familiar with the syntax.

            We don't provide programming education services, but you may wish to reference the Programming Concepts page of the NinjaTrader 7 Help Guide and you also may wish to use the Strategy Builder to generate syntax. Using the Strategy Builder can help to see how it generates C# so you can write similar code.

            https://ninjatrader.com/support/help...g_concepts.htm

            We look forward to assiting.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hi Jim,

              With the below code it compiles but doesn't seem to plot anything. Do you have an idea why that might be? Thanks

              protected override void OnBarUpdate()
              {
              if (Low[0] > Close[1])
              {

              Values[0][0] = Close[1] + ATR(20)[0] ;
              Values[1][0] = High[0] - ATR(20)[0] ;
              }



              else if (High[0]< Close[1])
              {
              Values[0][0] = Low[0] + ATR(20)[0] ;
              Values[1][0] = Close[1] - ATR(20)[0] ;
              }


              else
              {
              Values[0][0] = Low[0] + ATR(20)[0] ;
              Values[1][0] = High[0] - ATR(20)[0] ;
              }
              }

              Comment


                #8
                Hello vstoichk,

                If your indicator is not plotting or if you are running a strategy that automatically disables, please check the log tab of the Control Center for any errors that may have bee thrown by the script.

                I can see that you are making a BarsAgo reference of 1 before ensuring the script has processed that many bars, so this would likely be your issue.

                Making sure you have enough bars in the data series you are accessing - https://ninjatrader.com/support/help...nough_bars.htm

                We look forward to assisting.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by vstoichk View Post
                  Hi Chris, don't have anything on the internet for it, but pretty simple -

                  Upside ATR =20-period daily ATR + Current Low of Day

                  Downside ATR = Current Hi of Day - 20-period Daily ATR

                  If there is a gap open:

                  Upside ATR = 20-period daily ATR + previous close

                  Downside ATR = previous close - 20-period daily ATR

                  Will probably try to create myself, just need to read a bit on ninja script. Any guidance on where to start would be appreciated
                  Look in the NT Eco-System for the indicator called a Chandelier Stop. Those are the calculations that are used for a Chandelier Stop.

                  ref: https://ninjatraderecosystem.com/use...andelier-stop/ as it was a bit hard to find using the search in the Eco-System. I had to shell out to Google!
                  Last edited by koganam; 03-27-2020, 06:17 PM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Fiocco, Today, 05:59 AM
                  0 responses
                  15 views
                  0 likes
                  Last Post Fiocco
                  by Fiocco
                   
                  Started by catinabag, Today, 06:09 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post catinabag  
                  Started by junposlee, Today, 02:59 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post junposlee  
                  Started by patpat, Yesterday, 11:02 AM
                  2 responses
                  8 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by jameslee001, Yesterday, 08:09 AM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X