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 cmtjoancolmenero, Yesterday, 03:58 PM
    1 response
    17 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by benmarkal, Yesterday, 12:52 PM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by helpwanted, Today, 03:06 AM
    1 response
    19 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    11 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    244 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Working...
    X