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

Indicator Plot Goes Blank

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

    Indicator Plot Goes Blank

    My indicator will plot initially, but then goes blank when the parameters are changed.

    To replicate this error.

    1) import attached indicator.

    2) add the indicator to a chart with 3 data series. press the apply button. the indicator automatically detects all 3 series and adds them to the barsarray.

    3) remove the 3rd indicator name from parameters. press Apply/OK. in the initialize method, the 3rd instrumnt is no longer added to the bars array.

    Result: The chart fails to plot. Is this by design? How can I update the number of instruments used by the indicator?

    Thanks

    Code:

    protected override void Initialize()
    {
    int barValue;

    DrawOnPricePanel = false; // TRUE - Draw objects paint on price panel; FALSE - indicator panel.
    Overlay = false; // TRUE - Indicator plots drawn on top of price; FALSE - Indicator drawn separate panel

    Add(new Plot(Color.Black, PlotStyle.Line, "MyClose"));

    barValue = Math.Max(1,base.BarsPeriod.Value);
    Add(symbol2, BarsPeriod.Id, barValue);
    if (symbol3!="" && symbol3!=null)
    Add(symbol3, BarsPeriod.Id, barValue);

    }

    protected override void OnBarUpdate()
    {
    MyClose.Set(Close[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 MyClose
    {
    get { return Values[0]; }
    }

    private string symbol1="";
    [Description("")]
    [GridCategory("\t\t\t\t\tInstrument 1 Parameters")]
    [Gui.Design.DisplayName ("\t\t\t\tSymbol")]
    public string Symbol1
    {
    get
    {
    if (((symbol1 == "") || (symbol1 == null)) && (ChartControl != null) && (Instruments != null))
    {
    symbol1=ChartControl.BarsArray[0].Instrument.FullName;
    }
    return symbol1;
    }
    set
    {
    if((symbol1 == "") || (symbol1 == null))
    {
    symbol1=value;
    }
    }
    }
    private string symbol2 = @"";
    [Description("")]
    [GridCategory("\t\t\t\tInstrument 2 Parameters")]
    [Gui.Design.DisplayName ("\t\t\t\tSymbol")]
    public string Symbol2
    {
    get
    { // symbol2 defaults to secondary chart data series
    if (((symbol2 == "") || (symbol2 == null)) && (ChartControl != null) && (Instruments != null))
    {
    symbol2 = ChartControl.BarsArray[1].Instrument.FullName;
    }
    return symbol2;
    }
    set { symbol2 = value; }
    }

    private string symbol3 = @"";
    [Description("")]
    [GridCategory("\t\t\t\tInstrument 3 Parameters")]
    [Gui.Design.DisplayName ("\t\t\t\tSymbol")]
    public string Symbol3
    {
    get
    { // symbol3 defaults to secondary chart data series
    if (((symbol3 == "") || (symbol3 == null)) && (ChartControl != null) && (Instruments != null))
    {
    symbol3 = ChartControl.BarsArray[2].Instrument.FullName;
    }
    return symbol3;
    }
    set
    {
    // check for update Symbol3Units default...
    symbol3 = value;
    }
    }
    #endregion
    Attached Files

    #2
    Hello symbol,

    Thank you for your post.

    I will test this on my end, however can you advise if any error messages are seen on the Log tab of the NinjaTrader Control Center when this occurs? And if so, what do they report?

    I look forward to your response.

    Comment


      #3
      Hi Patrick

      Thanks for your reply. I do not get any error messages on the log prior to the chart going blank.

      Nick

      Comment


        #4
        Hello Nick,

        Thank you for your response.

        I have corrected this item in your script, you can find a corrected version attached to this response.

        Key items here are the following:
        • Using NinjaTrader_AdamP's SpreadCandlesticks indicator you can see a few differences that needed to be applied to your indicator: http://www.ninjatrader.com/support/f...d=4&linkid=512
        • I removed your null checks on several items including the Add() method for the third bar series in Initialize():
          Code:
          barValue = Math.Max(1,base.BarsPeriod.Value);			
                      Add(symbol2, BarsPeriod.Id, barValue);
          			Add(symbol3, BarsPeriod.Id, barValue);
        • Each symbol except for the first one has been edited in the properties to reflect the following:
          Code:
          get
                      {   // symbol# defaults to secondary chart data series
                          if ((symbol# == "") && (ChartControl != null) && (Instruments != null))
                          {
          	                for(int i=0; i<ChartControl.BarsArray.Length; i++)
          						if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
          						{
          							symbol# = ChartControl.BarsArray[i].Instrument.FullName;
          							break;
          						}
                          }
                          return symbol#;
                      }
                      set { symbol# = value.ToUpper(); }

        Please let me know if you have any questions.
        Attached Files

        Comment


          #5
          Thanks Patrick. That has corrected the issue.
          Nick

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by benmarkal, Yesterday, 12:52 PM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by helpwanted, Today, 03:06 AM
          1 response
          17 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 aussugardefender, Today, 01:07 AM
          0 responses
          6 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          244 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Working...
          X