• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 jrobin747, Today, 02:37 PM
          2 responses
          11 views
          0 likes
          Last Post bltdavid  
          Started by Gav_G, Today, 01:23 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by webus, Today, 01:05 PM
          2 responses
          23 views
          0 likes
          Last Post webus
          by webus
           
          Started by Wick Wrangler, Today, 12:42 AM
          1 response
          22 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by pman777, 04-15-2020, 05:09 AM
          5 responses
          49 views
          0 likes
          Last Post NinjaTrader_Kate  
          Working...
          X