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 Option Whisperer, Today, 09:55 AM
    0 responses
    4 views
    0 likes
    Last Post Option Whisperer  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    8 responses
    58 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by halgo_boulder, 04-20-2024, 08:44 AM
    2 responses
    22 views
    0 likes
    Last Post halgo_boulder  
    Started by mishhh, 05-25-2010, 08:54 AM
    19 responses
    6,189 views
    0 likes
    Last Post rene69851  
    Started by gwenael, Today, 09:29 AM
    0 responses
    6 views
    0 likes
    Last Post gwenael
    by gwenael
     
    Working...
    X