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

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 frslvr, 04-11-2024, 07:26 AM
    6 responses
    105 views
    1 like
    Last Post NinjaTrader_BrandonH  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    6 responses
    26 views
    0 likes
    Last Post trilliantrader  
    Started by arvidvanstaey, Yesterday, 02:19 PM
    5 responses
    14 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by Rapine Heihei, Yesterday, 08:25 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Mongo, Yesterday, 11:05 AM
    6 responses
    27 views
    0 likes
    Last Post Mongo
    by Mongo
     
    Working...
    X