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 SaltyCoffee, Today, 01:13 AM
      0 responses
      5 views
      0 likes
      Last Post SaltyCoffee  
      Started by FishTrade, 05-13-2024, 11:11 PM
      3 responses
      13 views
      0 likes
      Last Post FishTrade  
      Started by Graci117, Yesterday, 09:02 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by ETFVoyageur, Yesterday, 07:55 PM
      0 responses
      10 views
      0 likes
      Last Post ETFVoyageur  
      Started by janio973, Yesterday, 07:24 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X