• 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

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

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Tradarr, Today, 06:25 PM
    2 responses
    13 views
    0 likes
    Last Post Tradarr
    by Tradarr
     
    Started by cocopod, Today, 04:47 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_JoshG  
    Started by digibob, Today, 02:47 AM
    2 responses
    14 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by mntemel, Today, 03:31 PM
    4 responses
    23 views
    0 likes
    Last Post mntemel
    by mntemel
     
    Started by mrlucky1x, Today, 03:14 PM
    2 responses
    7 views
    0 likes
    Last Post mrlucky1x  
    Working...
    X