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

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 wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        26 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, Yesterday, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        192 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,234 views
        0 likes
        Last Post xiinteractive  
        Working...
        X