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

Bars Since Pivot High or Pivot Low

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

    Bars Since Pivot High or Pivot Low

    I'm attempting to make a filter for identifying a number of bars since a pivot high or low. I have provided the code below. The issue is that currently I have not figured out the logic that properly identifies the pivot high or pivot low and to start counting from that pivot high or pivot low. Any suggestions?

    Vars
    private int BarsSinceHigh = 0;
    private int BarsSinceLow = 0;
    private bool BarCount1 = true;
    private bool BarCount2 = true;

    OBU()

    if(MIN(Low,16)[0] < Low[0]) //How do instead create a condition to identify the pivot low?
    {
    BarsSinceLow=0;
    BarCount1=false;

    }
    else BarsSinceLow++;

    if(BarsSinceLow >= 8)
    BarCount1 = true;


    if(MAX(High,16)[0] > High[0]) How do instead create a condition to identify the pivot High?
    {
    BarsSinceHigh=0;
    BarCount2=false;

    }

    else BarsSinceHigh++;

    if(BarsSinceHigh >= 8)
    BarCount2 = true;

    #2
    HI BaseHeadz,

    You may want to look into MRO, LRO for this. They expressthe number of bars since a condition.





    You can also custom code it. This can be done by capturing CurrentBar at the time of a condition, and then taking the difference of CurrentBar & this captured value.

    Code:
    #region Variables
    private int myConditionBar;
    #endregion
    
    protected override void OnBarUpdate()
    {
         if (Close[0] > Open[0])
         myConditionBar = CurrentBar;
    
         int barsSinceUpClose = CurrentBar - myConditionBar;	
     }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Baseheadz View Post
      I'm attempting to make a filter for identifying a number of bars since a pivot high or low. I have provided the code below. The issue is that currently I have not figured out the logic that properly identifies the pivot high or pivot low and to start counting from that pivot high or pivot low. Any suggestions?

      Vars
      private int BarsSinceHigh = 0;
      private int BarsSinceLow = 0;
      private bool BarCount1 = true;
      private bool BarCount2 = true;

      OBU()

      if(MIN(Low,16)[0] < Low[0]) //How do instead create a condition to identify the pivot low?
      {
      BarsSinceLow=0;
      BarCount1=false;

      }
      else BarsSinceLow++;

      if(BarsSinceLow >= 8)
      BarCount1 = true;


      if(MAX(High,16)[0] > High[0]) How do instead create a condition to identify the pivot High?
      {
      BarsSinceHigh=0;
      BarCount2=false;

      }

      else BarsSinceHigh++;

      if(BarsSinceHigh >= 8)
      BarCount2 = true;
      I would use the Swing indicator instead as a processer, and call and use the values from it, in this indicator. The Swing indicator identifies the swing bar, and allows you to define the conditions (bars each side), that constitute a valid swing.

      Comment


        #4
        Thanks Koganam. Would it be a good idea to try the zig zag indicator instead?
        If I did use the ZigZag, how would I know when I am at least 8 bars from the swing high?

        (ZigZag(DeviationType.Percent, 0.1, false).ZigZagHigh[0]

        Comment


          #5
          Originally posted by Baseheadz View Post
          Thanks Koganam. Would it be a good idea to try the zig zag indicator instead?
          If I did use the ZigZag, how would I know when I am at least 8 bars from the swing high?

          (ZigZag(DeviationType.Percent, 0.1, false).ZigZagHigh[0]
          There is usually more than one way to program anything; it is just a matter of preferences. So, I suppose that you could use the ZigZag indicator instead. tThat will give you the swing points. After you have that, you will then run a while loop to determine on what bar the swing occured.

          It seems less programming effort and computing resources will be required/used if the called indicator can already return both pieces of information: the swing point, and the bar on which it occured. The Swing indicator does that. Your choice.

          Comment


            #6
            yes, I took a better look at the zigzag and swing indicators and I agree that the swing indicator could be more useful. I'll let you know how that goes.

            Comment


              #7
              Originally posted by koganam View Post
              I would use the Swing indicator instead as a processer, and call and use the values from it, in this indicator. The Swing indicator identifies the swing bar, and allows you to define the conditions (bars each side), that constitute a valid swing.
              Koganam,

              I'm looking into the swing indicator now. How could I identify 8 bars after the swinghigh?

              Swing(9).SwingHigh[0]

              Comment


                #8
                Originally posted by Baseheadz View Post
                Koganam,

                I'm looking into the swing indicator now. How could I identify 8 bars after the swinghigh?

                Swing(9).SwingHigh[0]
                The NT Help should tell you all that you want to know.

                ref: http://www.ninjatrader.com/support/h...html?swing.htm

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by suroot, 04-10-2017, 02:18 AM
                4 responses
                3,021 views
                0 likes
                Last Post truepenny  
                Started by Stanfillirenfro, Today, 07:23 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                2 responses
                22 views
                0 likes
                Last Post cmtjoancolmenero  
                Started by olisav57, Yesterday, 07:39 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by cocoescala, 10-12-2018, 11:02 PM
                7 responses
                944 views
                0 likes
                Last Post Jquiroz1975  
                Working...
                X