Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Amount of bars not changed after the indicator had been launched last.

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

    Amount of bars not changed after the indicator had been launched last.

    Hello!

    Is there in Ninjatrader a function returning the "amount of bars not changed after the indicator had been launched last"? I want to use the equivalent of this function "IndicatorCounted()" from mql in ninjatrader. Has someone ever experienced this function already here?

    If there is an equivalent, could someone advice me?
    If there is not equivalence of this function in Ninjatrader, how can I skip this function in my implementation? Wich function could I use instead? I do not think it would be CurrenBar() right?

    Best regards

    #2
    Hello Stanfillirenfro,

    Thank you for your post.

    NinjaTrader does not have a method that checks the number of bars that have not changed after the indicator has been launched last. This would require custom logic to be programmed.

    Please provide a brief description clarifying your goal so we may accurately assist.

    Are you wanting to check how many historical bars have processed before the indicator starts processing real-time data?
    Are you wanting to skip historical data processing?
    Are you wanting to check that a certain number of bars have processed before the indicator begins calculation?

    I look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello BrandonH and many thank for your reply.
      Excactly! I want to check that a certain number of bars have processed before the indicator begins calculation. Exactly that.

      Comment


        #4
        Hello Stanfillirenfro,

        Thank you for the clarification.

        A CurrentBar check could be used in your indicator's logic to ensure that a certain number of bars have processed before the indicator begins calculation. A CurrentBar check would look something like this.

        Code:
        if (CurrentBar < 10)
            return;
        This would check to make sure that 10 bars have processed before the indicator begins it's calculations.

        See the help guide documentation below for more information.
        CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
        CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
        Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Many thanks BrandonH for your help.

          I have here anothe issue. I just want to understand what coud be the "mode" in the following ccode retrieved from mql: iADX(NULL, 0, 14, PRICE_CLOSE, MODE_MINUSDI, 0);
          What could be maning MODE_MINUSDI? Could I consider it as Low?
          In NinjaTrader we have the following: double value = ADX(Low, 20)[0];
          Could MODE_MINUSDI represent Low in this case?
          Thanks!

          Comment


            #6
            Hello Stanfillirenfro,

            Thank you for your note.

            After a quick google search, I see the MODE_MINUSDI in MQL4 refers to the -DI indicator line (lower line) of the iADX() indicator. Please reach out to MetaTrader 4 to confirm if this is correct.

            See this publicly available link - https://docs.mql4.com/constants/indi...onstants/lines

            In NinjaTrader, the lower line of the ADX indicator cannot be referenced in a custom script. You would need to make a copy of the ADX indicator and change the Lines (AddLine()) to Plots (AddPlot()) so that it could be referenced.

            Below is a link to a video that demonstrates making a copy of a script.
            https://www.youtube.com/watch?v=BA0W...utu.be&t=8m15s

            See the help guide documentation below for more information.
            AddPlot() - https://ninjatrader.com/support/help...t8/addplot.htm
            ADX - https://ninjatrader.com/support/help..._index_adx.htm

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Many thanks BrandonH.

              I have declared my variables direct after
              public class CashSixtySecondTrades : Indicator
              {

              #region Variables
              private double[] variable1;
              private double[] variable2;
              private double variable3 = 0;

              The initiation occured in

              else if (State == State.DataLoaded)
              {
              variable1 = new double[0];
              variable2= new double[0];
              }

              After compilation and attachment on the chart, I am not having anything.

              What could be going wrong here?


              Should I declare and initialize my variable as above?

              Thanks!

              Comment


                #8
                Hello Stanfillirenfro,

                Thank you for your note.

                Are you wanting to create a Series<double> variable? Or, are you wanting to create a normal double variable?

                If you are wanting to create a Series<double> variable, you would need to call 'private Series<double> variable1;' instead of 'private double[] variable1;'. Then, you would need to instantiate the Series<double> in State.DataLoaded like so, varaible1 = new Series<double>(this, MaximumBarsLookBack.Infinite);.

                See this help guide documentation for more information on creating a Series<double> variable - https://ninjatrader.com/support/help...t8/seriest.htm

                If you are wanting to create a normal double variable, you would need to call 'private double variable1;'.

                Let us know if we may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Many thanks BrandonH for your help. It is moving in the right direction, but I still have a way to go. Please help!

                  I am using a loop to collect my ploted dots, but until now nothing is appearing on the chart. What am I doing wrong?

                  I have prceeded as followed:

                  for (int li_4 = 300; li_4 >= 0; li_4--)
                  {
                  double val1 = ADX(High, ADXbars)[li_4 - 1];
                  douvle val2 = ADX(Low, ADXbars)[li_4 - 1];

                  if(val1 > val2)
                  {
                  variable1[li_4] = Low[li_4];
                  }

                  else if(val1 < val2)
                  {
                  variable2[li_4] = High[li_4];
                  }

                  Values[0][0] = gda_84[li_4];
                  Values[1][0] = gda_88[li_4];

                  }

                  Comment


                    #10
                    Hello Stanfillirenfro,

                    Thank you for your note.

                    To understand why the script is behaving as it is, such as not plotting objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

                    In the indicator add prints (outside of any conditions) that print the values of every variable used along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

                    Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
                    https://ninjatrader.com/support/foru...121#post791121

                    Please let me know if I may further assist
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Many thanls BrandonH for yyour help.
                      I have the following error message from output:
                      "Indicator 'myIndicator': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

                      I have in my code the following conditions:

                      int CountBars = 300

                      if(CountBars >= CurrentBar)
                      {
                      CountBars = CurrentBar;
                      }


                      if (CurrentBar < 0)
                      return;

                      if (CurrentBar < 1)
                      {
                      for (int li_0 = 1; li_0 <= CountBars; li_0++)
                      {
                      variable1[CountBars - li_0] = 0;
                      }

                      for (int li_0 = 1; li_0 <= CountBars; li_0++)
                      {
                      variable2[CountBars - li_0] = 0;
                      }


                      }


                      Are these conditions appropriate here? What is wrong here?

                      If not which condition should I put here to solve the problem?

                      Thanks!

                      Comment


                        #12
                        Hello Stanfillirenfro,

                        Thank you for your inquiry.

                        This error will be displayed if you try to use a BarsAgo value when it is not valid. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

                        Something you could do when debugging is to print out the CurrentBar that is processing at the beginning of OnBarUpdate() along with adding prints for your variables and conditions to see where your logic is accessing a BarsAgo value that is not valid.

                        If your indicator requires 300 bars for its calculations, you would need to use a CurrentBar check at the beginning of OnBarUpdate() to ensure that there are at least 300 bars loaded. The CurrentBar check would look like this.

                        if (CurrentBar < 300)
                        return;

                        See the help guide documents linked in post #4 for more information about making sure you have enough bars loaded for your script to process.

                        Please let us know if we may assist further.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #13
                          Mny thanks BrandonH for our help.

                          It is not impr0ving unfortunately.

                          I have testet wit CurrenBar < 350 without sccees. Even by increasing the number up to 750 there is not improvment.
                          I have the following message:

                          Indicator 'myIndicator': Error on calling 'OnBarUpdate' method on bar 350: Index was outside the bounds of the array.

                          Coud the problem be somewhere else than this condition? I am suspectig the loop to be the problem, but I do ot know where exactly.

                          Any help please?

                          Thanks!

                          Comment


                            #14
                            Hello Stanfillirenfro,

                            Thank you for your note.

                            Please send us a reduced copy of your script that demonstrates the issue so we may further investigate.

                            I look forward to assisting further.
                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #15
                              Many thanks BrandonH for yur help.

                              below please is a reduced copy of my code.

                              I will ver appreciate your help.

                              Many thanks again.

                              {
                              public class myIndicator : Indicator
                              {

                              #region Variables
                              private Series<double> variable1;
                              private Series<double> variable2;
                              private double val1 = 0;
                              private double val2 = 0;

                              #endregion

                              protected override void OnStateChange()
                              {
                              if (State == State.SetDefaults)
                              {
                              Description = @"Enter the description for your new custom Indicator here.";
                              Name = "myIndicator";
                              Calculate = Calculate.OnBarClose;
                              IsOverlay = true;
                              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;
                              ADXbars = 14;
                              CountBars = 350;
                              AddPlot(new Stroke(Brushes.Turquoise, 2), PlotStyle.Dot, "Gda_84");
                              AddPlot(new Stroke(Brushes.Fuchsia, 2), PlotStyle.Dot, "Gda_88");
                              }
                              else if (State == State.DataLoaded)
                              {

                              variable1 = new Series<double>(this);
                              variable2 = new Series<double>(this);
                              }
                              }

                              protected override void OnBarUpdate()
                              {
                              if(CurrentBar < 350) return;
                              return;

                              for (int li_4 = CountBars; li_4 >= 0; li_4--)
                              {
                              double val1 = ADX(High, ADXbars)[li_4 - 1];
                              double val2 = ADX(Low, ADXbars)[li_4 - 1];

                              if(val1 > val2)
                              {
                              variable1[li_4] = Low[li_4];
                              }

                              else if(val1 < val2)
                              {
                              variable2[li_4] = High[li_4];
                              }

                              Values[0][0] = Variable1[li_4];
                              Values[1][0] = variable2[li_4];

                              }

                              }
                              Last edited by Stanfillirenfro; 05-03-2021, 02:17 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ct, Today, 01:53 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post ct
                              by ct
                               
                              Started by maiyudse, Today, 12:57 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post maiyudse  
                              Started by SmartArtsStudio, Yesterday, 11:24 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post SmartArtsStudio  
                              Started by kenz987, Yesterday, 10:06 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post kenz987
                              by kenz987
                               
                              Started by AaronKoRn, Yesterday, 07:24 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post AaronKoRn  
                              Working...
                              X