• 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

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, 06: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 escobar63, Yesterday, 05:06 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by Brutus, Today, 06:00 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by phesi, Today, 03:36 AM
            2 responses
            7 views
            0 likes
            Last Post phesi
            by phesi
             
            Started by Guru73, Today, 01:35 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Marco  
            Started by Maxwell123, Today, 12:34 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Working...
            X