• 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

% of ATR for Market Analyzer

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

    % of ATR for Market Analyzer

    I'm just trying to create an indicator that takes X% of daily ATR over a given period. You could change the % if you want to use it for stops or profit targets. Can't seem to figure out what I'm doing wrong here... Seems like this should be pretty straightforward. Although I have no experience at this Any help would be appreciated.

    Click image for larger version

Name:	ATR 1.jpg
Views:	169
Size:	161.1 KB
ID:	1080955

    #2
    Hi tvaughan4, thanks for your note.

    If you want to make the percentage modifiable from the indicators menu make it a public property e.g.
    Code:
            #region Properties
            [NinjaScriptProperty]
            [Range(1, double.MaxValue)]
            [Display(Name="ATRPercentage", Order=1, GroupName="Parameters")]
            public double ATRPercentage
            { get; set; }
            #endregion
    To get the value of an ATR on a particular bar, define the statement like so:

    double myvalue = ATRPercentage*ATR(20)[0]; //a 20 period ATR

    What you have is a declaration, the implementation needs some integer that represents the ATR period.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      So I have it compiling now. I just made the percentage and ATR value fixed for now for simplicity. But it's spitting out zero for the number (ATRProfitTarget), which is obviously incorrect. ???


      namespace NinjaTrader.NinjaScript.Indicators.MyIndicators
      {
      public class ATRTarget : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Percent Target from Daily ATR";
      Name = "ATRTarget";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      DisplayInDataBox = true;
      DrawOnPricePanel = true;
      DrawHorizontalGridLines = true;
      DrawVerticalGridLines = true;
      PaintPriceMarkers = true;
      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      IsSuspendedWhileInactive = true;



      AddPlot(Brushes.Orange, "ATRProfitTarget");
      }
      }

      protected override void OnBarUpdate()
      {
      double ATRProfitTarget = .25*ATR(10)[0];
      }
      }
      }

      Comment


        #4
        Hi, Im not getting the same thing.

        This works for me:

        protected override void OnBarUpdate()
        {
        double ATRProfitTarget = .25*ATR(10)[0];
        Print(ATRProfitTarget);

        }

        You do have either historical data or live data coming in correct?
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Yep, live data, same code as you

          this is what i'm getting in market analyzer

          is the AddPlot correct?? AddPlot(Brushes.Orange, "ATRProfitTarget");
          Attached Files

          Comment


            #6
            Hello tvaughan4,

            It looks like Chris was testing a Print statement to confirm the value where you are not outputting the value in any way. I would suggest that you also do a Print and then check the output window to confirm the value is working.

            The AddPlot alone doesn't do anything except adds a plot, it doesn't look like you are setting the plot in OnBarUpdate. To set the plot you would need to use Value:

            Code:
            Value[0] = someValue;
            or

            Code:
            double ATRProfitTarget = .25*ATR(10)[0];
            Value[0] = ATRProfitTarget;

            Please let me know if I can assist any further.
            Last edited by NinjaTrader_Jesse; 12-16-2019, 10:43 AM. Reason: spelling
            JesseNinjaTrader Customer Service

            Comment


              #7
              That'll do it!!! Thanks so much for the help!!

              One more question, how would I change the price output from the regular price of the instrument to convert it over to ticks?

              Comment


                #8
                Hello tvaughan4,

                Generally to convert to an amount of ticks you could multiply by the tick size:

                double ticks = amount * TickSize;

                For example if we wanted to know the price 4 ticks away from the current price it looks like:

                double price = Close - (4 * TickSize);

                https://ninjatrader.com/support/help...8/ticksize.htm



                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Yep, perfect, thanks again

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by morrnel, Yesterday, 04:18 PM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Started by jmahon, Today, 02:45 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post jmahon
                  by jmahon
                   
                  Started by brianshih, Today, 02:40 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post brianshih  
                  Started by franco12364, Yesterday, 02:29 PM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Started by wildwex, 07-31-2020, 10:45 PM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Marco  
                  Working...
                  X