Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator does not plot?

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

    Indicator does not plot?

    Hello,

    The code below compiles ok but does not plot anything when placed on a chart. Where do I go wrong?

    Anyone?

    Regards,

    Dennis


    // 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 EURUSDpara : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    private int _stochastic_period_1 = 60; // Default setting for _stochastic_period_1
    private int _lookback_2 = 5; // Default setting for _lookback_2

    #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.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = 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 result = 0;
    if ((High[_stochastic_period_1] - Low[_stochastic_period_1]) != 0)
    result += (Close[0] - + Low[_stochastic_period_1]) / (High[_stochastic_period_1] - Low[_stochastic_period_1]);
    result *= High[0];
    result = Math.Cos(result);
    result += Open[0] - Open[_lookback_2];
    result = Math.Tanh(result);
    if (result > 0)
    result = 1;
    else if (result < 0)
    result = -1;
    else
    result = 0;

    Value.Set(result);
    Plot0.Set(result);
    }

    #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]; }
    }
    //Put the code below into the Parameters / Properties section
    [Description("")]
    [GridCategory("Parameters")]
    public int _Stochastic_Period_1
    {
    get { return _stochastic_period_1; }
    set { _stochastic_period_1 = Math.Max(10, value); }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public int _Lookback_2
    {
    get { return _lookback_2; }
    set { _lookback_2 = Math.Max(5, value); }
    }

    #endregion
    }
    }

    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    public partial class Indicator : IndicatorBase
    {
    private EURUSDpara[] cacheEURUSDpara = null;

    private static EURUSDpara checkEURUSDpara = new EURUSDpara();

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public EURUSDpara EURUSDpara(int _Lookback_2, int _Stochastic_Period_1)
    {
    return EURUSDpara(Input, _Lookback_2, _Stochastic_Period_1);
    }

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public EURUSDpara EURUSDpara(Data.IDataSeries input, int _Lookback_2, int _Stochastic_Period_1)
    {
    if (cacheEURUSDpara != null)
    for (int idx = 0; idx < cacheEURUSDpara.Length; idx++)
    if (cacheEURUSDpara[idx]._Lookback_2 == _Lookback_2 && cacheEURUSDpara[idx]._Stochastic_Period_1 == _Stochastic_Period_1 && cacheEURUSDpara[idx].EqualsInput(input))
    return cacheEURUSDpara[idx];

    lock (checkEURUSDpara)
    {
    checkEURUSDpara._Lookback_2 = _Lookback_2;
    _Lookback_2 = checkEURUSDpara._Lookback_2;
    checkEURUSDpara._Stochastic_Period_1 = _Stochastic_Period_1;
    _Stochastic_Period_1 = checkEURUSDpara._Stochastic_Period_1;

    if (cacheEURUSDpara != null)
    for (int idx = 0; idx < cacheEURUSDpara.Length; idx++)
    if (cacheEURUSDpara[idx]._Lookback_2 == _Lookback_2 && cacheEURUSDpara[idx]._Stochastic_Period_1 == _Stochastic_Period_1 && cacheEURUSDpara[idx].EqualsInput(input))
    return cacheEURUSDpara[idx];

    EURUSDpara indicator = new EURUSDpara();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
    indicator.Input = input;
    indicator._Lookback_2 = _Lookback_2;
    indicator._Stochastic_Period_1 = _Stochastic_Period_1;
    Indicators.Add(indicator);
    indicator.SetUp();

    EURUSDpara[] tmp = new EURUSDpara[cacheEURUSDpara == null ? 1 : cacheEURUSDpara.Length + 1];
    if (cacheEURUSDpara != null)
    cacheEURUSDpara.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheEURUSDpara = tmp;
    return indicator;
    }
    }
    }
    }

    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
    public partial class Column : ColumnBase
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.EURUSDpara EURUSDpara(int _Lookback_2, int _Stochastic_Period_1)
    {
    return _indicator.EURUSDpara(Input, _Lookback_2, _Stochastic_Period_1);
    }

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public Indicator.EURUSDpara EURUSDpara(Data.IDataSeries input, int _Lookback_2, int _Stochastic_Period_1)
    {
    return _indicator.EURUSDpara(input, _Lookback_2, _Stochastic_Period_1);
    }
    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.EURUSDpara EURUSDpara(int _Lookback_2, int _Stochastic_Period_1)
    {
    return _indicator.EURUSDpara(Input, _Lookback_2, _Stochastic_Period_1);
    }

    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    /// <returns></returns>
    public Indicator.EURUSDpara EURUSDpara(Data.IDataSeries input, int _Lookback_2, int _Stochastic_Period_1)
    {
    if (InInitialize && input == null)
    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

    return _indicator.EURUSDpara(input, _Lookback_2, _Stochastic_Period_1);
    }
    }
    }
    #endregion

    #2
    Hello,
    Thank you for your post.
    Are you receiving any errors in the log tab on the control center?
    I look forward to your reply.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Could it be simply that you you haven't put:

      if (CurrentBar < N) // N = Max period value of any variable
      return;

      I've done this so many times. If this declaration isn't made, the ind won't plot.

      Comment


        #4
        Hello,
        This indicates that there are not enough bars on the chart for the indicator to run.
        protected override void OnBarUpdate()
        {
        if (CurrentBar < 1)
        return;

        if (Close[0] > Close[1])
        // Do something
        }
        I have included a link to a forum post that explains this topic thoroughly. http://www.ninjatrader.com/support/f...ead.php?t=3170
        If there is anything else I can assist with please let me know.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          that indeed solves the problem...thank you...

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by samir, Today, 07:00 PM
          0 responses
          9 views
          0 likes
          Last Post samir
          by samir
           
          Started by travisloneker, Today, 06:52 PM
          0 responses
          6 views
          0 likes
          Last Post travisloneker  
          Started by InfraredBusa, Today, 05:50 PM
          0 responses
          3 views
          0 likes
          Last Post InfraredBusa  
          Started by White Fork, Today, 04:56 PM
          1 response
          8 views
          0 likes
          Last Post White Fork  
          Started by steveyinyang, Today, 02:48 PM
          3 responses
          22 views
          0 likes
          Last Post steveyinyang  
          Working...
          X