Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi instrument indicator no values in chart

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

    Multi instrument indicator no values in chart

    The indicator values show up when I use my live market analyzer, so I'm pretty sure it has to do with the starting bars (CurrentBars) not lining up. I've attached a shortened version of my code to see if anyone knows what's going on.

    public class Stats : Indicator
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    double ad = 0;
    double dec = 0;
    double advol = 0;
    double decvol = 0;
    #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("FB",PeriodType.Day,1);
    Add("AMZN",PeriodType.Day,1);
    Add("NFLX",PeriodType.Day,1);
    Add("GOOGL",PeriodType.Day,1);

    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "ADV"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "DEC"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "ADVVOL"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Firebrick), PlotStyle.Line, "DECVOL"));


    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.

    for (int i=0; i < 5; i++)
    {
    if(CurrentBars[i] < 2)
    return;
    }

    ad = 0;
    dec = 0;
    advol = 0;
    decvol = 0;

    for (int x=1; x < 5; x++)
    {
    if(Closes[x][0] > Closes[x][1])
    {
    ad = ad + 1;
    advol = advol + Volumes[x][0];
    }
    else if(Closes[x][0] < Closes[x][1])
    {
    dec = dec + 1;
    decvol = decvol + Volumes[x][0];
    }
    }

    ADV.Set(ad);
    DEC.Set(dec);
    ADVVOL.Set(advol);
    DECVOL.Set(decvol);

    }
    Last edited by pretender; 03-14-2016, 07:06 PM.

    #2
    Hello pretender,

    Thanks for your post.

    I suspect your hunch is correct about the CurrentBars. Your CurrentBar check would let one of the dataseries into the code section when not all of them are = 2 or more. Not sure what you base dataseries is but if I assume it is also day bars then a solution would be something like:

    if (CurrentBars[0] < 2 || CurrentBars[1] < 2 || CurrentBars[2} < 3 etc etc) return; // Do not process until all are 2 or >.

    http://ninjatrader.com/support/helpG...urrentbars.htm

    If the code does not run on the chart, you can always check the "log" tab of the control center for any run time error messages that would help you.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks. I think you're right, that my method allows one of the dataseries through when not all of them have requisite bars. I can do the method you used for example for 4 instruments no problem, but if I'm to add upwards of 100+ instruments I was hoping for an iterative method to cut down the code.

      Comment


        #4
        Hello pretender,

        Thanks for your reply.

        After thinking about it further your (currentbar check) code may be fine. What I recommend is adding print statements throughout your code to find where it is breaking down.

        Here is a reference that may help:http://ninjatrader.com/support/forum...ead.php?t=3418
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for replying back.
          After looking at the code for the long version of the what i posted here, I realized that on one occasion one of the outputs spit out a mathematically undefined result, and I think that's what did it. It doesn't appear in the output window, but the log shows a "value outside of valid range" error.
          I guess I just find it weird that one undefined result means the entire plot disappears instead of just the results of that particular bar.

          Comment


            #6
            Hello pretender,

            Thanks for your reply and glad you found the issue.

            Yes, any run time error would result in no plot and an error message in the log.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by selu72, Today, 02:01 PM
            0 responses
            0 views
            0 likes
            Last Post selu72
            by selu72
             
            Started by f.saeidi, Today, 12:14 PM
            8 responses
            18 views
            0 likes
            Last Post f.saeidi  
            Started by Mikey_, 03-23-2024, 05:59 PM
            3 responses
            49 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Started by Russ Moreland, Today, 12:54 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by philmg, Today, 12:55 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Working...
            X