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

Secondary Data Series as an Array with secondary Timeframe

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

    Secondary Data Series as an Array with secondary Timeframe

    Hi,

    I'm developing an indicator where I have 2 additional TimeFrames Data series.
    For each of these TimeFrames I have 3 secondary DataSeries.

    I have problems having them synchronized

    What I've done:


    In the variable "area" I have defined them:

    private Series<double>[] SecondPMC;


    In the “State == State.Configure” I’m adding the secondary DataSeries:
    if(MultiTFPeriod1 > 0) AddDataSeries(GetBarType(MultiTFType1), MultiTFPeriod1);
    if(MultiTFPeriod2 > 0) AddDataSeries(GetBarType(MultiTFType2), MultiTFPeriod2);


    In the “State == State.DataLoaded” I’m synchronizing them:
    SecondPMC = new Series<double>[6]; // - - defining them as array
    if(MultiTFPeriod1 > 0) for(int i= 0; i < 3; i++)
    SecondPMC[i] = new Series<double>(BarsArray[1]);
    // - -I sync the first 3 DataSeries to the 1st TimeFrame

    if(MultiTFPeriod2 > 0) for(int i= 3; i < 6; i++)
    SecondPMC[i] = new Series<double>(BarsArray[2]);
    // - -I sync the second 3 DataSeries to the 2nd TimeFrame


    for(int i= 0; i < 6; i++)
    SecondPMC[i] = new Series<double>(this,MaximumBarsLookBack.Infinite);
    // - - I dim them to all Bars in every TF



    I cannot get them synchronized!
    If TF1 = double TF0, I get the results:
    SecondPMC[0][0] = correct value
    SecondPMC[0][1] = 0
    SecondPMC[0][2] = correct value
    SecondPMC[0][3] = 0

    Am I putting every Step in its correct place?

    Thanks!

    #2
    Hello artson,

    Thank you for your post.

    You should use prints to verify the values being used in your script:


    Ultimately, it is not supported to call AddDataSeries() dynamically. It should use hard-coded values only as mentioned on the following help guide page:
    • "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.​"
    As a test, please check the results if you call AddDataSeries() twice without the if statements and without any variables.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thanks Emily,

      I've just tried
      AddDataSeries(Data.BarsPeriodType.Volume, 3000);

      Only one, not the 2nd DataSeries.
      It doesn't work.
      The base TF ist Volume 1000.
      With this secondary as Volume 3000 I become the values as:
      [0]= value
      [1]= 0
      [2]= 0
      [3]= value
      [4]= 0
      [5]= 0​

      As a note, I use several indicators with the AddDataSeries and dynamical variables and it has worked very well.

      May here be the use of Array for DataSeries?

      Comment


        #4
        Ok,

        I've tried with the AddDataSeries without a variable and without an Array
        It neither worked.

        Then, I've tried without variable and without an Array but with
        SecondPMC = new Series<double>(this,MaximumBarsLookBack.Infinite);
        in the if (State == State.SetDefaults) area and it has worked perfectly

        So I would say the error is using Array and defining it in the State.SetDefaults.

        Could you please check?

        Comment


          #5
          Hello artson,

          Thank you for your reply.

          What is your use case for adding the series into an array? What are the results after adding prints? You could print the value of MultiTFPeriod1 and MultiTFPeriod2 before checking if they are greater than 0. You could print inside of each for loop to ensure the expected series is being added.

          Code:
          [B]In the “State == State.DataLoaded” I’m synchronizing them:[/B]
          SecondPMC = new Series<double>[6]; // - - defining them as array
          if(MultiTFPeriod1 > 0) for(int i= 0; i < 3; i++)
          SecondPMC[i] = new Series<double>(BarsArray[1]);
          // - -I sync the first 3 DataSeries to the 1st TimeFrame
          
          if(MultiTFPeriod2 > 0) for(int i= 3; i < 6; i++)
          SecondPMC[i] = new Series<double>(BarsArray[2]);
          // - -I sync the second 3 DataSeries to the 2nd TimeFrame
          
          
          for(int i= 0; i < 6; i++)
          SecondPMC[i] = new Series<double>(this,MaximumBarsLookBack.Infinite);
          // - - I dim them to all Bars in every TF​
          It should be possible to create an array of Series<T> objects. This has been discussed in other threads, such as the following:Arrays are a general C# concept and not specific to NinjaScript, so our support on the subject is limited. You may utilize outside resources for more information regarding arrays. Prints should give you some additional insight as to which parts of your code have been evaluated as expected or not. Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one-on-one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

          That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

          You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational services.

          Please let us know if we may be of further assistance.​
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DJ888, Today, 10:57 PM
          0 responses
          5 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Today, 09:29 PM
          0 responses
          7 views
          0 likes
          Last Post Belfortbucks  
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          151 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Working...
          X