Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Acceleration Band code bug

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

    Acceleration Band code bug

    I converted the code below from Keltner Channel indicator in NT8 to Acceleration Band indicator but something is not right and I would appreciate corrections and feedback. The formula for acceleration bands is:

    Upperband=SMA(H*(1+4*(H - L) / (H + L)),20);
    Lowerband= SMA(L*(1-4*(H - L)/ (H + L)),20);

    namespace NinjaTrader.NinjaScript.Indicators
    {
    /// <summary>
    /// Keltner Channel code converted to Acceleration Bands.
    /// </summary>
    public class AccelerationBands : Indicator
    {
    //private Series<double> diff;
    private Series<double> diffU;
    private Series<double> diffL;
    //private SMA smaDiff;

    private SMA smaDiffU;
    private SMA smaDiffL;
    //private SMA smaTypical;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionKeltnerChannel;
    Name = "AccelerationBands";
    Period = 20;
    IsOverlay = true;
    IsSuspendedWhileInactive = true;
    OffsetMultiplier = 1.0;

    AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUp per);
    AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLo wer);
    }
    else if (State == State.DataLoaded)
    {

    diffU = new Series<double>(this);
    smaDiffU = SMA(diffU, Period);
    diffL = new Series<double>(this);
    smaDiffL = SMA(diffL, Period);

    //smaTypical = SMA(Typical, Period);
    }
    }

    protected override void OnBarUpdate()
    {
    diffU[0] = High[0]*(1+4*(High[0] - Low[0]) / (High[0] + Low[0]));
    diffL[0] = Low[0]*(1+4*(High[0] - Low[0]) / (High[0] + Low[0]));

    double upper = smaDiffU[0];
    double lower = smaDiffL[0];

    Upper[0] = upper;
    Lower[0] = lower;
    }







    #2
    Hello jjones,

    Thanks for your post.

    The script will not compile in the current state because there are dependencies that are not included with the snippet. Please use the guide below to export indicators as source code so all dependencies are included and we can test on our end.

    Exporting NinjaScript as source code - https://ninjatrader.com/support/help...tAsSourceFiles

    I'm also not sure what sort of assistance you are looking for. What is not working right? What is the result you are getting and what did you expect?

    Glancing at the code and your implementation, diffL is not being calculated as you have outlined

    Lowerband= SMA(L*(1-4*(H - L)/ (H + L)),20);
    diffL[0] = Low[0]*(1+4*(High[0] - Low[0]) / (High[0] + Low[0]));

    I look forward to being of further assistance.

    Comment


      #3
      Did you ever finish the acceleration indicator

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      569 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X