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

How to Write Previous Up Bars

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

    How to Write Previous Up Bars

    Hey guys. I'm curious. How do I write a Condition to Look "If the Last 5 or More Bars are UP Bars...." Do something..... and How about "if the last 5 or more bars have Higher Lows than each previous bar.....Do something"

    I read the MIN guide, but still don't know how to do it properly. Any help is appreciated. Thank you.

    #2
    I Tested This but Its Not working right. It keeps showing arrows everywhere. even when the Last 5 bars Were NOT UP bars.

    PICTURE: http://screencast.com/t/aMYwD8pg6WN

    Code:
       #region Variables
            // Wizard generated variables
                private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Overlay				= true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 5)
    				return;
    			
    			
    			if(MIN(Close, 5)[1] > MIN(Open, 5)[1]) //The MIN displays if the Last 5 bars Close UP starting with [1] bar ago.
    				{ DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[1] + 3 * TickSize, Color.Red);	}	
    			
    			
    			 
    			
            }	//DON"T TOUCH

    Comment


      #3
      Hello ginx10k,

      Thank you for your post.

      There is no method to determine the up bars over a period. Max and Min look for the Highest or Lowest value over the period, not consistent highs or lows.

      You can implement a for loop to quickly and easily check for these conditions without multiple repeating lines of code:
      Code:
      			int count = 0;
      			for(int i = period; i >= 0; i--)
      			{
      				if(Close[i] > Open[i]
      					&& Close[i] > Close[i+1]
      					&& Low[i] > Low[i+1])
      				{
      					count++;
      				}
      			}
      			if(count == period)
      			{
      				Print("Last " + period + " bars are up.");
      			}

      Comment


        #4
        Didn't work. Thanks for quick response Patrick (as always u rock). It didn't draw any arrows anywhere.

        any ideas??

        I tried this code:

        Code:
        	int count = 0;
        						for(int i = period; i >= 0; i--)
        						{
        							if(Close[i] > Open[i]
        								&& Close[i] > Close[i+1]
        								&& Low[i] > Low[i+1])
        							{
        								count++;
        							}
        						}
        						if(count == period)
        						{
        							DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[1] + 3 * TickSize, Color.Red);
        							Print("Last " + period + " bars are up.");
        						}

        Comment


          #5
          Also tried

          I also Tried This code
          Code:
          for(int i = period; i >= 0; i--)
          						{
          							if((Close[i] > Open[i]) )
          							{
          								count++;
          							}
          						}
          and it Shows Arrows. but Still Shows arrows even in areas where we didn't get 5 consecutive UP Bars


          I don't know why its just NOT working.

          Comment


            #6
            Hello ginx10k,

            Thank you for your response.

            My mistake, the for loop should minus one from the period as the bars objects use 0 for the current bar:
            Code:
            			for(int i = period - 1; i >= 0; i--)
            			{
            				if(Close[i] > Open[i]
            					&& Close[i] > Close[i+1]
            					&& Low[i] > Low[i+1])
            				{
            					count++;
            				}
            			}

            Comment


              #7
              Hey Patrick. as always. thanks for your assistance. Worked out Great! Cheers!!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by andrewtrades, Today, 04:57 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by chbruno, Today, 04:10 PM
              0 responses
              3 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by josh18955, 03-25-2023, 11:16 AM
              6 responses
              436 views
              0 likes
              Last Post Delerium  
              Started by FAQtrader, Today, 03:35 PM
              0 responses
              7 views
              0 likes
              Last Post FAQtrader  
              Started by rocketman7, Today, 09:41 AM
              5 responses
              19 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X