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

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.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    5 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    13 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,982 views
    3 likes
    Last Post jhudas88  
    Working...
    X