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

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.



            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


                    #10
                    Hi everyone,
                    I need to bring an important correction on how the stoploss is calculated.
                    In many presentations, Charles LeBeau described how to calculate its Chandelier Stoploss.
                    The parameters are:
                    • Indicator used is the ATR with a period length of 22 periods, (ATR(22 periods));
                    • Previous highest High for long position (HH(22 periods)) or the lowest Low for short position (LL(22 periods))over the past 22 periods;
                    • Multiplicator for the ATR with a value of 3. (k)
                    The stoploss for the next bar is calculated as follow:
                    For long position
                    Stoploss (long) = HH(22 periods) -(k * ATR(22 periods))
                    if Stoploss (long) > Low(current bar) then Stoploss = Low(current bar)



                    For short position
                    Stoploss (short) = LL(22 periods) + (k * ATR(22 periods))
                    if Stoploss (short) < High(current bar)​ then Stoploss = High(current bar)


                    The stoploss can be also ratchet, i.e. for long position the stoploss never reduces
                    and for short position the stoploss never increases.

                    Good luck.

                    References:
                    Stocks & Commodities V.24:11 (28-32)
                    Alexander Elder "Come into My Trading Room"
                    Last edited by Dan_D_Trader; 12-28-2023, 11:58 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by funk10101, Today, 12:02 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by GLFX005, Today, 03:23 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by nandhumca, Yesterday, 03:41 PM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by The_Sec, Yesterday, 03:37 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by vecnopus, Today, 06:15 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post vecnopus  
                    Working...
                    X