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

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.
    JimNinjaTrader Customer Service

    Comment


      #3
      Did you ever finish the acceleration indicator

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DanielTynera, Today, 01:14 AM
      0 responses
      2 views
      0 likes
      Last Post DanielTynera  
      Started by yertle, 04-18-2024, 08:38 AM
      9 responses
      40 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by techgetgame, Yesterday, 11:42 PM
      0 responses
      12 views
      0 likes
      Last Post techgetgame  
      Started by sephichapdson, Yesterday, 11:36 PM
      0 responses
      2 views
      0 likes
      Last Post sephichapdson  
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,615 views
      0 likes
      Last Post aligator  
      Working...
      X