Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA of an indicator

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

    SMA of an indicator

    Hi,

    My first attempt at coding an indicator. I'm trying to create a SMA of the forecast oscillator (FOSC), where I can select the period of the SMA as well as the period of the SMA. I'm totally stuck.

    This is what I have:

    double test1 = SMA(FOSC(Close,Period1),Period2)[0];

    Any help would be appreciated!

    Erin

    #2
    SMA of an indicator

    I'm getting an error, 'property accessor already defined' (CS1007). how can I correct this. I'm attaching the full code below. SMA_N is the parameter for the SMA moving average period, and FOSC_N is the parameter for the forecast oscillator (FOSC) period. Thanks in advance! E


    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class test1 : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int SMA_N = 5; // Default setting for SMA_N
    private int FOSC_N = 14; // Default setting for FOSC_N
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.Blue, "test1"));
    CalculateOnBarClose = false;
    Overlay = false;
    PriceTypeSupported = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    double test1 = SMA(FOSC(Close,FOSC_N),SMA_N)[0];
    Plot.Set(test1[0]);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Plot0
    {
    get { return Values[0]; }
    }

    [Description("")]
    [Category("Parameters")]
    public int SMA_N
    {
    get { return SMA_N; }
    set { SMA_N = Math.Max(1, value); }
    }

    public int FOSC_N
    {
    get { return FOSC_N; }
    set { FOSC_N = Math.Max(1, value); }
    }
    #endregion
    }
    }

    Comment


      #3
      Hello,

      Try starting over and only use this line in your OnBarUpdate block (and make sure Overlay = false in your intialization block so it shows up in a lower panel):

      Plot0.Set(SMA(FOSC(Close,14),10)[0]);
      DenNinjaTrader Customer Service

      Comment


        #4
        thank you!

        hi ben,

        thank you!

        erin

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 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
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X