Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Flat indicators

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

    Flat indicators

    Hello
    Is there a way I can't think of to capture the flat parts of an indicator as one single reading?
    Something like:

    if DMI1[1] < DMI1[2] && DMI1[2] = DMI1[3] = ...= DMI1[x] && DMI1[x] > DMI1[x-1]

    then DMI1SwingHigh[0] = DMI1[2]
    Last edited by itrader46; 12-02-2019, 09:32 AM.

    #2
    Hello itrader46,

    Thanks for your post.

    I would suggest printing out the values of the indicator on a bar by bar basis and then checking the values in the areas you perceive as flat to valid your concept of equality (IE: DMI1[2] == DMI1[3]). As the indicator is a result of calculations and is of double type, you may find that what shows as flat on the chart may not actually be flat (or exactly equal).

    You may want to look at using the Slope() method: https://ninjatrader.com/support/help...nt8/?slope.htm

    Other alternatives would be to define a range of indicator movement that you can define as flat and check however many bars back to see if the indicator is ranging between the high and low values you establish as the flat range. You would use the MIN() and MAX() methods for this:


    Comment


      #3
      I found the code below kindda gives me the data I need, but I'm struggling to find the value of DMI at the first bar it occurred (flatDMIbar), as the Get value method gives me the error below.

      Code:
      if (IsFirstTickOfBar)
                          {                    
                              if (Math.Abs(DMI1[1] - DMI1[2]) < 0.0001)   // If DMI[1] = DMI[2] start recording DMI flat parts
                              {
                                  FlatDMI[0] = DMI1[1];                            
                                  FlatInd = true;
                                  if (!FlatIndBar)
                                  {
                                      flatDMIbar = CurrentBar - 2;
                                      FlatIndBar = true;                                
                                  }          
      Print(string.Format(@"
      Flat DMI Bar = {0}, Flat Ind = {1}, FlatDMI[0] = {2 :F4}, FlatDMI[i-1] = {3 :F4}
      i = {4}, CurrentBar = {5}, CurrentBar - 1 = {6}, FlatDMI[1] = {7 :F4}, CurrentBar - i = {8}, DMI[flatDMIBar] = {9 :F4}
      ", flatDMIbar, FlatInd, FlatDMI[0], FlatDMI[i-1], i, CurrentBar, CurrentBar - 1, FlatDMI[1]/*, DMI(14).GetValueAt(flatDMIbar)*/)); // GetValue Error on calling 'OnBarUpdate' method on bar 4518: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
                                     i++;
                              }
                              else
                              {    // Reset the search on first DMI[1] != DMI[2]
                                  FlatInd = false;
                                  FlatIndBar = false;
                                  i = 1;                            
                              }
      ....
                          }

      Comment


        #4
        Hello itrader46,

        Thanks for your reply.

        The error message is advising that the variable value of flatDMIbar must be greater than or equal to 0 and less than the CurrentBar. I would suggest printing the value determined to be flatDMIbar before your print statement.

        Comment


          #5
          The flatFMIbar reading prints OK. The error comes only when I inserted the commented part (
          DMI(14).GetValueAt(flatDMIbar)*/)) in the Print

          Comment


            #6
            Hello itrader46,

            Thanks for your reply.

            You are setting the variable here: flatDMIbar = CurrentBar - 2;

            Is there anywhere else that you are setting the variable value?

            Using Print (DMI(14).GetValueAt(CurrentBar-2).ToString()); I do not get any errors, do you?

            Comment


              #7
              Got it... sort of: I was missing a print argument - trying to print 10 bits of data when I had defined only 9, which probably gave the "Index (zero based) must be greater than or equal to zero and less than the size of the argument list" error.

              The problem is now that, DMI(14).GetValueAt(flatDMIbar is not printing the DMI value at Flat DMI Bar, but the price close (CL 01-20, 25.11.2019, 05:15am bar 902 or 06:00 bar 911 - I am using market replay, obviously) at that bar, as you can see from below:



              Flat DMI Bar = 902, Flat Ind = True, FlatDMI[0] = -0.7778, FlatDMI[i-1] = -0.7778
              i = 1, CurrentBar = 904, CurrentBar - 1 = 903, FlatDMI[1] = 0.0000, CurrentBar - i = 903, DMI[flatDMIBar] = 57.8300
              ...
              Flat DMI Bar = 911, Flat Ind = True, FlatDMI[0] = 0.3684, FlatDMI[i-1] = 0.3684
              i = 1, CurrentBar = 913, CurrentBar - 1 = 912, FlatDMI[1] = 0.0000, CurrentBar - i = 912, DMI[flatDMIBar] = 57.9200

              Flat DMI Bar = 911, Flat Ind = True, FlatDMI[0] = 0.3684, FlatDMI[i-1] = 0.3684
              i = 2, CurrentBar = 914, CurrentBar - 1 = 913, FlatDMI[1] = 0.3684, CurrentBar - i = 912, DMI[flatDMIBar] = 57.9200

              Then I thought the DMI was actually applied to a secondary 5 min series ...

              Code:
              else if (State == State.Configure)                
                          {
                              AddDataSeries(Data.BarsPeriodType.Tick, 1);
                              AddDataSeries(Data.BarsPeriodType.Minute, 5);               
                          }
              So I replaced DMI(14).GetValueAt(flatDMIbar) with DMI(Closes[2], Convert.ToInt32(DmiPeriod)).GetValueAt(flatDMIbar) in my prints and the result is... unchanged:

              Flat DMI Bar = 902, Flat Ind = True, FlatDMI[0] = -0.7778, FlatDMI[i-1] = -0.7778
              i = 1, CurrentBar = 904, CurrentBar - 1 = 903, FlatDMI[1] = 0.0000, CurrentBar - i = 903, DMI[flatDMIBar] = 57.8300

              Why on Earth is it doing THAT?!?

              Comment


                #8
                Fixed it: DMI(Closes[2], Convert.ToInt32(DmiPeriod)).Values [0].GetValueAt(flatDMIbar) gives me the DMI value at flatDMIbar.

                I still don't understand why DMI(Closes[2], Convert.ToInt32(DmiPeriod)).GetValueAt(flatDMIbar) prints the price close, though!

                That is from the Help guide - Language reference - Common - ISeries<T> - GetValuaAt().

                Can you please tell me what does "(Input as Indicator).Values[0].GetValueAt(123) // passed in indicator value" mean? What exactly is "passed in value"?

                Comment


                  #9
                  Hello itrader46,

                  Thanks for your reply.

                  "I still don't understand why DMI(Closes[2], Convert.ToInt32(DmiPeriod)).GetValueAt(flatDMIbar) prints the price close, though!" As the help guide advises, it will return the bar data which is the input (by default is the close data series)

                  As you observed and according to the help guide, using .Values[] pulls the indicator value.

                  Can you please tell me what does "(Input as Indicator).Values[0].GetValueAt(123) // passed in indicator value" mean? What exactly is "passed in value"? If the input series to the script was an indicator (instead of a bar series), then .Values[] would return the indicator value that was the input.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  38 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  124 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  64 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  41 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X