Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Choppiness Index Script

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

    Choppiness Index Script

    I created this custom Indicator script but its returning the following errors. Could you guide me on how I can fix it.



    using System;

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class CustomChoppinessIndex : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Custom Choppiness Index with -10 offset";
    Name = "CustomChoppinessIndex";
    IsOverlay = false;
    Period = 14;

    AddPlot(Brushes.DodgerBlue, "ChoppinessIndex");
    AddLine(Brushes.DarkCyan, 38.2, "Lower");
    AddLine(Brushes.DarkCyan, 62.8, "Upper");
    }
    }

    protected override void OnBarUpdate()
    {
    double chopIndex = (MAX(High, Period)[0] - MIN(Low, Period)[0]).ApproxCompare(0) == 0 || SUM(ATR(1), Period)[0].ApproxCompare(0) == 0 ? 0 : 100 * Math.Log10(SUM(ATR(1), Period)[0] / (MAX(High, Period)[0] - MIN(Low, Period)[0])) / Math.Log10(Period);

    // Apply the offset of -10 to the Choppiness Index values
    Value[0] = chopIndex - 10;
    }

    region Properties

    [Range(2, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
    public int Period
    { get; set; }

    #endregion
    }
    }


    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private CustomChoppinessIndex[] cacheCustomChoppinessIndex;
    public CustomChoppinessIndex CustomChoppinessIndex(int period)
    {
    return CustomChoppinessIndex(Input, period);
    }

    public CustomChoppinessIndex CustomChoppinessIndex(ISeries<double> input, int period)
    {
    if (cacheCustomChoppinessIndex != null)
    for (int idx = 0; idx < cacheCustomChoppinessIndex.Length; idx++)
    if (cacheCustomChoppinessIndex[idx] != null && cacheCustomChoppinessIndex[idx].Period == period && cacheCustomChoppinessIndex[idx].EqualsInput(input))
    return cacheCustomChoppinessIndex[idx];
    return CacheIndicator<CustomChoppinessIndex>(new CustomChoppinessIndex(){ Period = period }, input, ref cacheCustomChoppinessIndex);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.CustomChoppinessIndex CustomChoppinessIndex(int period)
    {
    return indicator.CustomChoppinessIndex(Input, period);
    }

    public Indicators.CustomChoppinessIndex CustomChoppinessIndex(ISeries<double> input , int period)
    {
    return indicator.CustomChoppinessIndex(input, period);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.CustomChoppinessIndex CustomChoppinessIndex(int period)
    {
    return indicator.CustomChoppinessIndex(Input, period);
    }

    public Indicators.CustomChoppinessIndex CustomChoppinessIndex(ISeries<double> input , int period)
    {
    return indicator.CustomChoppinessIndex(input, period);
    }
    }
    }

    #endregion
    Attached Files

    #2
    Hello pickles1774,

    Thank you for your post.

    The errors seem to be related to attributes used in the Properties region of your script. This is what you currently have in that region:

    Code:
    [Range(2, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
    public int Period
    { get; set; }​
    The DisplayAttribute page of the help guide mentions the following:
    "You may have noticed the default NinjaTrader types such as indicators or strategies use a "ResourceType = typeof(Custom.Resource)" property in the DisplayAttribute. This is done for localization purposes, so the default NinjaTrader UI translates to other supported international languages, but is not required for your custom NinjaScript types. The ResourceType property can be safely ignored and left out in your custom development."


    I suspect that this indicator is a copy of the Choppiness Index that comes with NinjaTrader, and that is why the properties have ResourceType = typeof(Custom.Resource) in the DisplayAttribute. I am curious; if you remove this do you still get errors? Otherwise, you could try creating a new indicator from the Indicator wizard in the NinjaScript Editor and set up an input parameter for Period as an int, then simply copy the system generated Properties information from the new script and paste it into your CustomChoppinessIndex script.

    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

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