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

% 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:	517
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);





                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 alifarahani, Today, 09:40 AM
                  4 responses
                  19 views
                  0 likes
                  Last Post alifarahani  
                  Started by gentlebenthebear, Today, 01:30 AM
                  3 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by PhillT, Today, 02:16 PM
                  2 responses
                  7 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Started by Kaledus, Today, 01:29 PM
                  3 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by frankthearm, Yesterday, 09:08 AM
                  14 responses
                  47 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X