Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SUM of Volumes with a condition by period

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

    #31
    Hello Brandon,

    I'm waiting for your support, and I will be happy for your response.

    Thanks,

    Marom

    Comment


      #32
      Hello Marom,

      Do you still have AddDataSeries(BarsPeriodType.Tick, 1); added in State.Configure?

      This would be causing OnBarUpdate() to update for every tick. (Which you could actually use for your tick counter)

      Do you have this tick counter increment code for BarsInProgress 0, BarsInProgress 1, or both?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #33
        Hello Chelsea,

        Yes, there is AddDataSeries(BarsPeriodType.Tick, 1); in State.Configure (Please find the attached script in text and file below)

        I tried to count the Ticks for BarsInProgress 1 only, But without success.

        This is the last thing that I looking for to complete the script (A variable Period for the SUM Which calculat from a counter).
        Note: if I'm enter to SUM(mySeries, 4)[0]; the Period (number of ticks) manually, the script works well.

        I will very appreciate for your assistance to resolve this issue.

        Thanks in advanced,

        Marom




        ************************************************** ************************************************** ************************************************** ******************



        namespace NinjaTrader.NinjaScript.Indicators
        {
        public class AAMYNEWVOLTICK : Indicator
        {
        private Series<double> mySeries;
        private Series<double> volvalue;
        //private Series<int> counttick;

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Indicator here.";
        Name = "AAMYNEWVOLTICK";
        Calculate = Calculate.OnBarClose;
        IsOverlay = false;
        DisplayInDataBox = true;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = true;
        PaintPriceMarkers = true;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
        //See Help Guide for additional information.
        IsSuspendedWhileInactive = true;
        AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Bar, "AAMYNEWVOLTICK");
        }

        else if (State == State.DataLoaded)
        {
        mySeries = new Series<double>(BarsArray[1]);
        volvalue = new Series<double>(BarsArray[1]);
        //counttick = new Series<int>(BarsArray[1]);
        }

        else if (State == State.Configure)
        {
        AddDataSeries(BarsPeriodType.Tick, 1);
        }
        }


        protected override void OnBarUpdate()
        {

        if (CurrentBars[0] < 15 || CurrentBars[1] < 15)
        return;



        if (BarsInProgress == 1)
        {

        if (Closes[1][0] > Closes[1][1])
        {
        volvalue[0] = 1;
        }
        else if (Closes[1][0] < Closes[1][1])
        {
        volvalue[0] = -1;
        }
        else
        {
        volvalue[0] = volvalue[1];
        }


        mySeries[0] = Volumes[1][0] * volvalue[0];

        //if (IsFirstTickOfBar)
        //{
        //for (int i = 0; i < Bars.Count-1; i++)
        //{
        //counttick = i;
        //Print(i + " " + Close.GetValueAt(i) + " " + Time[0]);
        //}

        //}
        }


        // mySeries[0] = Volumes[1][0];

        // if(CurrentBar % 5 == 0)
        // mySeries.Reset();
        // if(mySeries.IsValidDataPoint(0))
        //if (IsFirstTickOfBar)
        //{
        Values[0][0] = SUM(mySeries, 4)[0];
        //}
        //Print("The tick count of the current bar is " + Bars.TickCount.ToString() + " " + Time[0]);
        }
        }
        }​
        Attached Files
        Last edited by marommos; 02-25-2023, 02:31 AM.

        Comment


          #34
          Hello Marom,

          Thanks for your note.

          "I tried to count the Ticks for BarsInProgress 1 only, But without success."

          Please see the attached example script that demonstrates incrementing a tick counter for both the primary series the script is running on and the added 1-Tick secondary series so that you could see how this would be done for either series.

          Note the attached indicator draws the primary series tick counter on the chart and prints both the primary and secondary series tick counters to the NinjaScript Output window.

          You could consider assigning the number of ticks from the tick counter to your 'Period' variable so that this variable holds the number of ticks from the tick counter. The 'Period' variable could then be used in your SUM() method.

          Let me know if I may assist further.
          Attached Files
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #35
            Hello Brandon,

            Thank you for your response.

            I have implemnted your suggestion in the script (please find the attached script below), but I get wrong values.
            Note: if I'm enter instead myPrimarySeriesTickCounter[0] (in the script use for a variable period) the number of ticks manually, I get right values.
            Reminder: I'm looking for the number of ticks each primary bar that will be use for the variable Period in SUM object - SUM(myseries, Period)[0];


            I almost finished, please your advise.

            Marom



            ************************************************** ************************************************** ************************************************** ************************************************** ***

            namespace NinjaTrader.NinjaScript.Indicators
            {
            public class AAMYNEWVOLTICK : Indicator
            {
            private Series<double> mySeries;
            private Series<double> volvalue;
            private Series<int> myPrimarySeriesTickCounter;

            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Enter the description for your new custom Indicator here.";
            Name = "AAMYNEWVOLTICK";
            Calculate = Calculate.OnBarClose;
            IsOverlay = false;
            DisplayInDataBox = true;
            DrawOnPricePanel = true;
            DrawHorizontalGridLines = true;
            DrawVerticalGridLines = true;
            PaintPriceMarkers = true;
            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
            //Disable this property if your indicator requires custom values that cumulate with each new market data event.
            //See Help Guide for additional information.
            IsSuspendedWhileInactive = true;
            AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Bar, "AAMYNEWVOLTICK");
            }

            else if (State == State.DataLoaded)
            {
            mySeries = new Series<double>(BarsArray[1]);
            volvalue = new Series<double>(BarsArray[1]);
            myPrimarySeriesTickCounter = new Series<int>(this);
            }

            else if (State == State.Configure)
            {
            AddDataSeries(BarsPeriodType.Tick, 1);
            }
            }


            protected override void OnBarUpdate()
            {

            if (CurrentBars[0] < 10 || CurrentBars[1] < 10)
            return;

            if (BarsInProgress == 0)
            {
            if (IsFirstTickOfBar)
            {
            myPrimarySeriesTickCounter[0] = 0;
            }

            myPrimarySeriesTickCounter[0] += 1;
            Print("myPrimarySeriesTickCounter count is " + myPrimarySeriesTickCounter[0] + " TIME" + Time[0]);
            Draw.TextFixed(this, "PrimarySeriesTickCounter", myPrimarySeriesTickCounter[0].ToString(), TextPosition.BottomRight);
            }

            if (BarsInProgress == 1)
            {

            if (Closes[1][0] > Closes[1][1])
            {
            volvalue[0] = 1;
            }
            else if (Closes[1][0] < Closes[1][1])
            {
            volvalue[0] = -1;
            }
            else
            {
            volvalue[0] = volvalue[1];
            }


            mySeries[0] = Volumes[1][0] * volvalue[0];
            }


            Values[0][0] = SUM(mySeries, myPrimarySeriesTickCounter[0])[0];

            }
            }
            }​
            Attached Files

            Comment


              #36
              Hello Marom,

              Thanks for your note.

              Within the IsFirstTickOfBar condition, myPrimarySeriesTickCounter[1] will hold the number of ticks that occurred on the bar that just closed. You could consider assigning that value to the 'Period' variable in your script so that 'Period' holds the number of ticks for the bar that just closed.

              For example, if the bar that just closed has a total tick value of 3763, myPrimarySeriesTickCounter[1] will be 3763 within the IsFirstTickOfBar condition. If you assign that value to the 'Period' variable, the 'Period' variable will be 3763 also. Then you could use the Period variable when calling SUM().

              An example of what this might look like could be seen below.

              Code:
              if (BarsInProgress == 0)
              {
                  if (IsFirstTickOfBar)
                  {
                      myPrimarySeriesTickCounter[0] = 0;
                      Print("myPrimarySeriesTickCounter[1] count is " + myPrimarySeriesTickCounter[1]);
                      Period = myPrimarySeriesTickCounter[1];
                      Print("Period is " + Period);
                  }
              
                  myPrimarySeriesTickCounter[0] += 1;
              }
              Please let me know if I may assist further.​
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment


                #37
                Hello Brandon,

                I will be gladd to try your solution, but there is an error in the script when I'm adding the code (please find the script attached below).
                The error: "Cannot implicitly convert type "int" to NinjaTrader.NinjaScript.Series <int>'"

                Please your notice about the script below.

                Thank you,

                Marom






                ************************************************** ************************************************** *******************************************

                namespace NinjaTrader.NinjaScript.Indicators
                {
                public class Counter : Indicator
                {

                private Series<int> myPrimarySeriesTickCounter;
                private Series<int> Period;

                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"Enter the description for your new custom Indicator here.";
                Name = "Counter";
                Calculate = Calculate.OnBarClose;
                IsOverlay = false;
                DisplayInDataBox = true;
                DrawOnPricePanel = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines = true;
                PaintPriceMarkers = true;
                ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;
                AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Bar, "Counter");
                }

                else if (State == State.DataLoaded)
                {
                myPrimarySeriesTickCounter = new Series<int>(this);
                Period = new Series<int>(this);
                }

                else if (State == State.Configure)
                {
                AddDataSeries(BarsPeriodType.Tick, 1);
                }
                }


                protected override void OnBarUpdate()
                {

                if (CurrentBars[0] < 10 || CurrentBars[1] < 10)
                return;

                if (BarsInProgress == 0)
                {
                if (IsFirstTickOfBar)
                {
                myPrimarySeriesTickCounter[0] = 0;
                Print("myPrimarySeriesTickCounter[1] count is " + myPrimarySeriesTickCounter[1]);
                Period = myPrimarySeriesTickCounter[1];
                Print("Period is " + Period);
                }

                myPrimarySeriesTickCounter[0] += 1;

                }

                }
                }
                }​
                Last edited by marommos; 02-28-2023, 01:53 PM.

                Comment


                  #38
                  Hello Marom,

                  Thanks for your note.

                  What exactly is the error message state that you are referring to?

                  The example code I shared in post # 36, Period is just a regular int variable. I see in the code you shared that you are using a Series<int> variable for Period.

                  Since you are using a custom Series variable, you should add an index of 0 when assigning a value to Period. For example:

                  Period[0] = myPrimarySeriesTickCounter[1];
                  Print("Period is " + Period[0]);

                  Ultimately, if you encounter a compile error, you should take debugging steps to determine the exact cause of the error.

                  Debugging Your NinjaScript Code: https://ninjatrader.com/support/help...script_cod.htm

                  Please let me know if I may assist further.
                  <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                  Comment


                    #39
                    Hello Brandon,

                    Of course a silly mistake
                    But I have modified the script, and I implemented your suggestion to the script, but the Period get 0 from the counter (Please see the script, screenshot and txt file attached below).

                    Please your advise.

                    Marom


                    ************************************************** ************************************************** ************************************************** ************


                    namespace NinjaTrader.NinjaScript.Indicators
                    {
                    public class AAMYNEWVOLTICK : Indicator
                    {
                    private Series<double> mySeries;
                    private Series<double> volvalue;
                    private Series<int> myPrimarySeriesTickCounter;
                    private Series<int> Period;

                    protected override void OnStateChange()
                    {
                    if (State == State.SetDefaults)
                    {
                    Description = @"Enter the description for your new custom Indicator here.";
                    Name = "AAMYNEWVOLTICK";
                    Calculate = Calculate.OnBarClose;
                    IsOverlay = false;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    DrawHorizontalGridLines = true;
                    DrawVerticalGridLines = true;
                    PaintPriceMarkers = true;
                    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive = true;
                    AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Bar, "AAMYNEWVOLTICK");
                    }

                    else if (State == State.DataLoaded)
                    {
                    mySeries = new Series<double>(BarsArray[1]);
                    volvalue = new Series<double>(BarsArray[1]);
                    myPrimarySeriesTickCounter = new Series<int>(this);
                    Period = new Series<int>(this);
                    }

                    else if (State == State.Configure)
                    {
                    AddDataSeries(BarsPeriodType.Tick, 1);
                    }
                    }


                    protected override void OnBarUpdate()
                    {

                    if (CurrentBars[0] < 10 || CurrentBars[1] < 10)
                    return;

                    if (BarsInProgress == 0)
                    {
                    if (IsFirstTickOfBar)
                    {
                    myPrimarySeriesTickCounter[0] = 0;
                    Print("myPrimarySeriesTickCounter[1] count is " + myPrimarySeriesTickCounter[1]);
                    Period[0] = myPrimarySeriesTickCounter[1];
                    Print("Period is " + Period[0]);
                    }

                    myPrimarySeriesTickCounter[0] += 1;

                    }

                    if (BarsInProgress == 1)
                    {

                    if (Closes[1][0] > Closes[1][1])
                    {
                    volvalue[0] = 1;
                    }
                    else if (Closes[1][0] < Closes[1][1])
                    {
                    volvalue[0] = -1;
                    }
                    else
                    {
                    volvalue[0] = volvalue[1];
                    }


                    mySeries[0] = Volumes[1][0] * volvalue[0];
                    }


                    Values[0][0] = SUM(mySeries, Period[0])[0];

                    }
                    }
                    }​
                    Attached Files

                    Comment


                      #40
                      Hello Marom,

                      Thanks for your note.

                      To resolve this error, you could include a condition in your script that checks if Period[0] is greater than 0 before assigning the value to the plot.

                      This ensures that Period[0] is within a valid range before assigning it to a plot.

                      For example, see below.
                      Code:
                      if (Period[0] > 0)
                          Values[0][0] = SUM(mySeries, Period[0])[0];
                      When I add this to the code you shared and test it, the error no longer appears. See the attached image.

                      Please let me know if I may assist further.​
                      Attached Files
                      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                      Comment


                        #41
                        Hello Brandon,

                        I have modified the script, but unfortunately, it doesn't work yet.
                        I have attached two screenshots, one of them is with number of ticks manually (2 Ticks in this excample), and the other is with a variable period (the last counter we wrote).
                        As you see, the results arn't same. the right result is in the Screenshot with number of ticks manually.
                        There are at 23:23 two Ticks with volumes 100 and 200 which both price is Close[0] >Close[1], so the result shall be 300, as shown in Screenshot with number of ticks manually.
                        Note: each modifying of the number of ticks manually, according to the number of the ticks in the tested bar, get the right result.

                        In addition, as you colud see in the attached txt file the Period allways is 1.

                        Could you think what is the reason? what isn't well in the counter?
                        As you see, this is a complicated issue, and it isn't write simply in the guides, And without your assistance it will be very challenging​.

                        Please find the attached script below.

                        Please your advise.

                        Thanks in advanced,

                        Marom


                        ************************************************** ************************************************** ************************************************** ***************

                        namespace NinjaTrader.NinjaScript.Indicators
                        {
                        public class AAMYNEWVOLTICK : Indicator
                        {
                        private Series<double> mySeries;
                        private Series<double> volvalue;
                        private Series<int> myPrimarySeriesTickCounter;
                        private Series<int> Period;

                        protected override void OnStateChange()
                        {
                        if (State == State.SetDefaults)
                        {
                        Description = @"Enter the description for your new custom Indicator here.";
                        Name = "AAMYNEWVOLTICK";
                        Calculate = Calculate.OnBarClose;
                        IsOverlay = false;
                        DisplayInDataBox = true;
                        DrawOnPricePanel = true;
                        DrawHorizontalGridLines = true;
                        DrawVerticalGridLines = true;
                        PaintPriceMarkers = true;
                        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                        //See Help Guide for additional information.
                        IsSuspendedWhileInactive = true;
                        AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Bar, "AAMYNEWVOLTICK");
                        }

                        else if (State == State.DataLoaded)
                        {
                        mySeries = new Series<double>(BarsArray[1]);
                        volvalue = new Series<double>(BarsArray[1]);
                        myPrimarySeriesTickCounter = new Series<int>(this);
                        Period = new Series<int>(this);
                        }

                        else if (State == State.Configure)
                        {
                        AddDataSeries(BarsPeriodType.Tick, 1);
                        }
                        }


                        protected override void OnBarUpdate()
                        {

                        if (CurrentBars[0] < 10 || CurrentBars[1] < 10)
                        return;

                        if (BarsInProgress == 0)
                        {
                        if (IsFirstTickOfBar)
                        {
                        myPrimarySeriesTickCounter[0] = 0;
                        Print("myPrimarySeriesTickCounter[1] count is " + myPrimarySeriesTickCounter[1]);
                        Period[0] = myPrimarySeriesTickCounter[1];
                        Print("Period is " + Period[0]);
                        }

                        myPrimarySeriesTickCounter[0] += 1;

                        }

                        if (BarsInProgress == 1)
                        {

                        if (Closes[1][0] > Closes[1][1])
                        {
                        volvalue[0] = 1;
                        }
                        else if (Closes[1][0] < Closes[1][1])
                        {
                        volvalue[0] = -1;
                        }
                        else
                        {
                        volvalue[0] = volvalue[1];
                        }


                        mySeries[0] = Volumes[1][0] * volvalue[0];
                        }

                        if (Period[0] > 0)
                        Values[0][0] = SUM(mySeries, Period[0])[0];

                        }
                        }
                        }​
                        Attached Files
                        Last edited by marommos; 02-28-2023, 04:22 PM.

                        Comment


                          #42
                          Hello Marom,

                          Thanks for your note.

                          I am not sure what the behavior you are describing would be caused by without thoroughly debugging and testing your logic.

                          Please keep in mind that it would ultimately be up to you to come up with the exact custom logic in your script to accomplish your overall goal. In the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. This is so that we can maintain a high level of service for all of our clients as well as our partners.

                          If the script does not behave exactly as you are expecting it to, you should further debug your script to understand how it is behaving and calculating values so that you could modify your logic to suit your exact needs.

                          I suggest further debugging your script to fully understand how each section of code is behaving so that you could modify your logic to suit your overall goal.

                          Below is a link to a forum post that demonstrates how to debug a script to understand behavior.

                          https://ninjatrader.com/support/foru...121#post791121

                          Please let me know if I may assist with creating a print or understanding the output window prints.​
                          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                          Comment


                            #43
                            Hello Brandon,

                            Thank you for your response and your explantion about your policy.

                            But it intersting, In post No.36 you helped me write a script which count the ticks each primary bar. and you described what the script does, exactly what I'm looking for! but the script isn't work well. so I asked you about this in the previous post.
                            And now you are telling me that I'm asking from you to create for me a logic, so why we have worked a lot of time about understanding the counter issue till now, and now you are telling me that against your policy?
                            Therefore if I violated over your policy specifically in the last post, I'm sorry about that, if not I will be glad for a professional support.

                            In any case, the text file is attached below, where the Period shown as 1 all the time. this is the bug in the script you helped me to write in post No.36

                            If anyone from you could help me to understand how the counter does work and how to Implement it in the script, according to your describe in post No.36, I will be glad.
                            For that matter, if the script you suggested worked, according to the example you gave in post 36, it would be very nice.


                            Tanks in advanced,

                            Marom


                            ******************* This is the complete code that plot the Period as "1" regularly ********************************

                            namespace NinjaTrader.NinjaScript.Indicators
                            {
                            public class AAMYNEWVOLTICK : Indicator
                            {
                            private Series<double> mySeries;
                            private Series<double> volvalue;
                            private Series<int> myPrimarySeriesTickCounter;
                            private Series<int> Period;

                            protected override void OnStateChange()
                            {
                            if (State == State.SetDefaults)
                            {
                            Description = @"Enter the description for your new custom Indicator here.";
                            Name = "AAMYNEWVOLTICK";
                            Calculate = Calculate.OnBarClose;
                            IsOverlay = false;
                            DisplayInDataBox = true;
                            DrawOnPricePanel = true;
                            DrawHorizontalGridLines = true;
                            DrawVerticalGridLines = true;
                            PaintPriceMarkers = true;
                            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                            //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                            //See Help Guide for additional information.
                            IsSuspendedWhileInactive = true;
                            AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Bar, "AAMYNEWVOLTICK");
                            }

                            else if (State == State.DataLoaded)
                            {
                            mySeries = new Series<double>(BarsArray[1]);
                            volvalue = new Series<double>(BarsArray[1]);
                            myPrimarySeriesTickCounter = new Series<int>(this);
                            Period = new Series<int>(this);
                            }

                            else if (State == State.Configure)
                            {
                            AddDataSeries(BarsPeriodType.Tick, 1);
                            }
                            }


                            protected override void OnBarUpdate()
                            {

                            if (CurrentBars[0] < 10 || CurrentBars[1] < 10)
                            return;

                            if (BarsInProgress == 0)
                            {
                            if (IsFirstTickOfBar)
                            {
                            myPrimarySeriesTickCounter[0] = 0;
                            Print("myPrimarySeriesTickCounter[1] count is " + myPrimarySeriesTickCounter[1]);
                            Period[0] = myPrimarySeriesTickCounter[1];
                            Print("Period is " + Period[0]);
                            }

                            myPrimarySeriesTickCounter[0] += 1;

                            }

                            if (BarsInProgress == 1)
                            {

                            if (Closes[1][0] > Closes[1][1])
                            {
                            volvalue[0] = 1;
                            }
                            else if (Closes[1][0] < Closes[1][1])
                            {
                            volvalue[0] = -1;
                            }
                            else
                            {
                            volvalue[0] = volvalue[1];
                            }


                            mySeries[0] = Volumes[1][0] * volvalue[0];
                            }

                            if (Period[0] > 0)
                            {
                            Values[0][0] = SUM(mySeries, Period[0])[0];
                            }
                            }
                            }
                            }​
                            Attached Files
                            Last edited by marommos; 03-01-2023, 01:35 AM.

                            Comment


                              #44
                              Hello Marom,

                              Thanks for your note.

                              We are able to provide simple example scripts that demonstrate a concept that you could implement into the script you are creating. We are also able to share links to reference samples, forum threads, and documentation on our help guide.

                              That said, 'Period' in your script does not need to be a custom Series<int> variable and this can likely be removed. You should change this to be a regular class-level int variable in your script similar to the 'Period' variable seen in the sample code on post # 36 and seen in the attached example script.

                              For OnBarUpdate() to update for BarsInProgress 0 tick by tick, please note that the Calculate setting must be set to Calculate.OnEachTick and requires Tick Replay to be enabled so that historical data is calculated tick-per-tick exactly as they would have been if the indicatory was running live.

                              Tick Replay: https://ninjatrader.com/support/help...ick_replay.htm
                              Calculate: https://ninjatrader.com/support/help...tsub=calculate

                              "In post No.36 you helped me write a script which count the ticks each primary bar. and you described what the script does, exactly what I'm looking for! but the script isn't work well."

                              When testing the attached example script using the code from post # 36, I am seeing the indicator work correctly for counting the number of ticks on a primary series bar. I have attached a demonstration video below showing the script working properly. If you test the attached exampled script with Tick Replay enabled and Calculate set to OnEachTick on your end, do you see a different behavior that what is seen in the attached video below?

                              Demonstration video: https://brandonh-ninjatrader.tinytak...M18yMTA2NzY0NQ

                              I look forward to assisting further.
                              Attached Files
                              Last edited by NinjaTrader_BrandonH; 03-01-2023, 10:03 AM.
                              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                              Comment


                                #45
                                Hello Brandon,

                                Thank you for your valuable support.

                                The last script you have attached work well exept one thing.
                                There isn't a synchronization between the time in the output window to the time in the chart. I have added Time[0] to the Print "myPrimarySeriesTickCounter" in your script and in the result was a shift between the times. meaning, the count of the Ticks is good, but there is no adjustment to the time when the actual number of ticks occurred.
                                For excample, if at 2:48 were six Ticks, in the Output window we will see these six ticks at 2:50.
                                This cause, in my script, to take a wrong count. but if it will fix, and will be synchronization, probably, I will get the desirable results.

                                I have attached Output file below.

                                Please your advise.

                                A lot of thanks,

                                Marom
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                571 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                331 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                101 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                549 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                549 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X