Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Defining and plotting custom indicator as a DataSeries

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

    Defining and plotting custom indicator as a DataSeries

    Within my strategy code, how do i define and plot a custom indicator as a DataSeries?

    The indicator i need is "ATR expressed in # of Ticks", and I tried the following code but it doesn't compile.
    - Appreciate if you could provide any sample code ..
    - Also, how do i specify a command to plot a DataSeries on the chart?

    //// Code
    protected override void Initialize()
    {
    atrInTicks = new DataSeries(this);
    atrInTicks = ATR(14) / TickSize();
    Add(atrInTicks);

    CalculateOnBarClose = true;
    }

    #2
    Hello kbellare,

    Thank you for your inquiry.

    You would need to first create this custom indicator before adding it to a strategy.

    Here's a simple example of an indicator that will do this for you:
    Code:
    #region Variables
    private int period = 1;
    #endregion
    
    protected override void Initialize()
    {
         Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ATRTicks"));
         Overlay = false;
    }
    
    protected override void OnBarUpdate()
    {
         ATRTicks.Set(ATR(period)[0] / TickSize);
    }
    
    #region Properties
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries ATRTicks
    {
         get { return Values[0]; }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public int Period
    {
         get { return period; }
         set { period = Math.Max(1, value); }
    }
    #endregion
    Now, in your strategy, you'll want to add the indicator under Initialize() to plot the indicator while the strategy is running:
    Code:
    public override void Initialize()
    {
         Add(indicatorName(int period));
    }
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    557 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X