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

BarsInProgress: Array[0] and Array[1]

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

    #16
    koganam, awesome thinking in developing a tool to trouble-shoot!

    Here is the code I used:
    double vBlue = (a21+a22+a23+a24+a25+a26) / 6;
    Print(null);
    Print("CurrentBar: " + CurrentBar);
    Print("CP1");
    Print(vBlue); // value returned = perfect
    // CP1 complete
    yBlueRaw.Set(vBlue);
    Print("CP2");
    Print(yBlueRaw[0]); // value returned = perfect
    Print(yBlueRaw[1]); // value returned is "0"
    // CP2 complete
    yBlue.Set(yBlueRaw[1]);
    Print("CP3");
    Print(yBlue[0]); // value returned is "0"
    // CP3 complete
    BlueLine.Set(yBlue[0]);
    Print("CP4");
    Print(yBlue[0]); // value returned is "0"
    // CP4 complete

    Here are the results:
    CurrentBar: 94
    CP1
    1170.91341269841
    CP2
    1170.91341269841
    0
    CP3
    0
    CP4
    0


    Clearly, with this code, data is set to DataSeries: yBlueRaw[0] but not available in yBlueRaw[1]. Where did it go? yBlueRaw.Set occurs only once in the entire code.

    The creation of the DataSeries:
    #region Variables
    private DataSeries yBlueRaw;
    private DataSeries yBlue;
    protectedoverridevoid Initialize()
    yBlueRaw = new DataSeries(this);
    yBlue = new DataSeries(this);

    The problem is likely clear to you . . . but I don't see anything wrong. What do you see?

    Comment


      #17
      Originally posted by JulieC View Post
      koganam, awesome thinking in developing a tool to trouble-shoot!

      Here is the code I used:
      double vBlue = (a21+a22+a23+a24+a25+a26) / 6;
      Print(null);
      Print("CurrentBar: " + CurrentBar);
      Print("CP1");
      Print(vBlue); // value returned = perfect
      // CP1 complete
      yBlueRaw.Set(vBlue);
      Print("CP2");
      Print(yBlueRaw[0]); // value returned = perfect
      Print(yBlueRaw[1]); // value returned is "0"
      // CP2 complete
      yBlue.Set(yBlueRaw[1]);
      Print("CP3");
      Print(yBlue[0]); // value returned is "0"
      // CP3 complete
      BlueLine.Set(yBlue[0]);
      Print("CP4");
      Print(yBlue[0]); // value returned is "0"
      // CP4 complete

      Here are the results:
      CurrentBar: 94
      CP1
      1170.91341269841
      CP2
      1170.91341269841
      0
      CP3
      0
      CP4
      0


      Clearly, with this code, data is set to DataSeries: yBlueRaw[0] but not available in yBlueRaw[1]. Where did it go? yBlueRaw.Set occurs only once in the entire code.

      The creation of the DataSeries:
      #region Variables
      private DataSeries yBlueRaw;
      private DataSeries yBlue;
      protectedoverridevoid Initialize()
      yBlueRaw = new DataSeries(this);
      yBlue = new DataSeries(this);

      The problem is likely clear to you . . . but I don't see anything wrong. What do you see?
      Well, all the checkpoints are returned, so we know that we do not have an untrapped exception.

      It is hard to say why your DataSeries is returning zero for a value that must evidently have been set to something other than zero, when CurrentBars1 was 93. Does every bar really return zero? If so, there is something going on in your code that unfortunately we can probably not account for without seeing the actual entire code.

      Comment


        #18
        If you prefer to send code to support at ninjatrader dot com please send it via email and we can spot the issue for you. Otherwise if your ok sharing on the forum then post to the forum. If you send via email please reference this forum post in the subject line in an email to support at ninjatrader dot com

        -Brett

        Comment


          #19
          Thanks for the replies koganam & Brett,

          Attached is .zip ArrayProblemSample. I wanted to start with the basics and spare y’all the distraction of other code. I’ve removed bells & whistles from my other indicator – this is the basics (that don’t seem to be working). I’ve been running it on instrument TF and watching its performance on everything from a 30Min, 1000Tick, 300Tick, and 150Tick. There is a bool option to turn on “Prints” to the Output Window. I’ve blanked out the “if(BarsInProgress) {}” statement – otherwise there would be no plots.

          Thank you for reviewing this problem!
          Attached Files

          Comment


            #20
            You have several issues but the main problem with this thread is this one:

            On line 81 you have the following.

            dsA1Raw = new DataSeries(this);
            dsA2Raw = new DataSeries(this);
            dsA3Raw = new DataSeries(this);

            These just need to be removed, as these even being here set dsA1Raw to be synced to the primary data series and thus the code you added here wont work as it wont be null so your never getting your bar series in sync.

            if (dsA1Raw == null) {
            dsA1Raw = new DataSeries(SMA(BarsArray[1], 50));
            }


            Secondary issues,

            1) You have 4 total data series. The primary one you have the chart on and the 3 you are adding in Initialize. You only have CurrentBars checks for 3, you need to add a forth.

            2) All code in OnBarUpdate should be surrounded in a BarsInProgress check. If its not then it will run on each BarsInProgress which may be aiding in giving you the unexpected results you are getting. Add a BarsInProgress check for all 4 input series otherwise as I mentioned the code will run once on each series.

            3) You should only set the following Data Series frommthe primary (BarsInProgress == 0) series as they are synced to that series in Initialize via the = new DataSeries(this);. So what you will want to do is add an if (BarsInProgress == 0) check and set these values that you want to combine in that single series via accessing the other series as such.

            dsA1 = new DataSeries(this);
            dsA2 = new DataSeries(this);
            dsA3 = new DataSeries(this);
            dsACombo = new DataSeries(this);
            yBlue = new DataSeries(this);
            yWhite = new DataSeries(this);
            yTest1 = new DataSeries(this);
            yTest2 = new DataSeries(this);
            yTest3 = new DataSeries(this);
            yTest4 = new DataSeries(this);
            yTest5 = new DataSeries(this);


            There might be more I didn't miss, for me to help out more we may need to simplify down the stratyegy even further to where there is just one plot and one issue and we can go from there but hopefully this gives you enough pointers to get you headed in the right direction.

            Let me know if I can explain any more of it in detail.

            Comment


              #21
              IT IS SO NICE WHEN IT WORKS !

              Thanks Brett for your help – I made the changes as you suggested.
              I now receive the exact same plot regardless of which Time-Frame I watch. ( 30Min, 1000Tick, 300Tick, etc.)
              In case someone else stumbles on the same issues, attached is .zip ArrayNoProblemSample.

              Thanks again Brett & koganam.
              Attached Files

              Comment


                #22
                Your first sentence made me lol.

                I know the feeling! Glad that its finally up and running. MTF programming is easily one of deepest (complex) things to do in the product but once your over the hill its downhill from there.

                -Brett

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by habeebft, Today, 07:27 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_ChristopherS  
                Started by AveryFlynn, Today, 04:57 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by Max238, Today, 01:28 AM
                4 responses
                37 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by r68cervera, Today, 05:29 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by geddyisodin, Today, 05:20 AM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X