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

AddDataSeries syntax

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

    AddDataSeries syntax

    Hello-

    My syntax is wrong on the AddDataSeries and I'm hoping you can help me out. I'm adding about 10 series. I use a 3rd party indicator. If my indicator is > 0 on all 10 data series I want to paint my background. All the examples I see use EMA which adds 20 periods or so and does not apply. My error comes in OnBarUpdate. I'm writing:
    // if (BarsInProgress == 0)
    // {
    // if (resValue[0] > 0)
    // R0 = 1;
    // else if (supValue[0] > 0)
    // S0 = 1;
    // else { R0 = 0; S0 = 0; }
    // }
    // if (BarsInProgress == 1)
    // {
    // if (resValue[1][0] > 0)
    // R1 = 1;
    // else if (supValue[1][0] > 0)
    // S1 = 1;
    // else { R1 = 0; S1 = 0; }
    // }
    This is just a sample of two. Error comes on all the resValue and supValue lines. It's the typical error: cannot apply indexing with [] to an expression of type 'double'
    Can someone tell me how to write this?
    Thank you.

    #2
    Repasted the code:

    if (BarsInProgress == 0)
    {
    if (resValue[0] > 0)
    R0 = 1;
    else if (supValue[0] > 0)
    S0 = 1;
    else { R0 = 0; S0 = 0; }
    }
    if (BarsInProgress == 1)
    {
    if (resValue[1][0] > 0)
    R1 = 1;
    else if (supValue[1][0] > 0)
    S1 = 1;
    else { R1 = 0; S1 = 0; }
    }
    if (BarsInProgress == 2)
    {
    if (resValue[2][0] > 0)
    R2 = 1;
    else if (supValue[2][0] > 0)
    S2 = 1;
    else { R2 = 0; S2 = 0; }
    }

    Comment


      #3
      Hello imalil,

      Thanks for your post.

      Looking at your code you are using the series two different ways. I do not know which is correct with the information provided but you should make them all the same one way or the other and that should get you functional.

      For example, in one area you have resValue[0] > 0 in another area you have resValue[2][0] If these are indeed added data series then resValue[2][0] would be correct. If they are actually custom series then resValue[0] would be correct.

      I noted that this is a duplicate topic, I will remove the other topic.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Hi Paul, thanks for the reply. I copied the example from the NT8 support site:



        It says:
        protected override void OnBarUpdate()
        {
        // Ignore bar update events for the supplementary - Bars object added above
        if (BarsInProgress == 1 || BarsInProgress == 2)
        return;

        // Go long if we have three up bars on all bars objects
        if (Close[0] > Open[0] && Closes[1][0] > Opens[1][0] && Closes[2][0] > Opens[2][0])
        EnterLong();
        }
        I'm adding the series resValue[1][0], resValue[2][0], etc. Is the main series then resValue[0][0] and not resValue[0]? Should the variables I'm adding be series variables, like open and close? Do I need something in data loaded? I cannot find an example that answers these questions.
        Thank you.

        Comment


          #5
          Hello imalil,

          Thanks for your reply.

          The link you posted goes to the Code Breaking Changes section of the help guide so I did not see where your example was.

          Your example of the Go long code is showing 3 different data series (The chart bars, add series 1 and added series2). It also shows that that line of code will only happen when the chart bars (BarsInProgress 0) calls OnBarUpdate(). The Close[0] would then naturally point to the chart bars close price of the current bar. Closes[1][0] points to the 1st added data series close price of the current bar, Closes[2][0] points to the 2nd added data series close price of the current bar. Note the differentiation from "Close" for the chart bars to "Closes" for the added data series. When using the plurals you provide a bars array index as well as a bar index.

          In order to further assist I think it would be best if you could post or attach your complete code.
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by funk10101, Today, 09:43 PM
          0 responses
          4 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          36 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          44 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          26 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          24 views
          0 likes
          Last Post algospoke  
          Working...
          X