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

Consecutive number of bars up / down

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

    Consecutive number of bars up / down

    Hi,

    I'm looking for an indicator that shows me the number of bars up / down up to the current moment from a variable timespan.

    So if up to today we have 4 consecutive updays, i want the indicator to show the number 4. If we have 4 up days, followed by one down day i want the indicator to show -1. If we have 5 up days, followed by 3 downdays, followed by 1 up day, i want the indicator to show 1.

    So basically when an up day is followed by a down day, the indicator is reset and the most recent direction prevails.

    I've tried building it with NBarsUp / NBarsDown but so far unsuccesfull.

    Maybe somebody can help me out.

    Thanks

    #2
    siroki, I'm not really aware of a similar study besides the N Bars Up / Dn. Perhaps something like the below snippet could serve as starting point in this area?

    Code:
    protected override void OnBarUpdate()
            {
    			if (CurrentBar < 1) return;
    			
    			if (Close[0] > Open[0] && Close[1] > Open[1])
    				upCount++;
    			
    			if (Close[0] < Open[0] && Close[1] < Open[1])
    				dnCount++;
    			
    			if (Close[0] > Open[0])
    				dnCount = 0;
    			
    			if (Close[0] < Open[0])
    				upCount = 0;
    			
                            Plot0.Set(upCount + dnCount);
    	}
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for your help Bertrand, as always.

      I solved it by using the following code.
      Note that I use a multitimeframe. So just replace the Closes[1] with Close and you'll be fine in a single timeframe. Then also leave out the BarsInProgress, or change to 0.

      Code:
      			if(BarsInProgress == 1) {
      				if(Closes[1][0] > Opens[1][0]) {
      					if(iSwingDays >= 0) {
      						iSwingDays = iSwingDays+1;
      					} else {
      						iSwingDays = 1;
      					}
      				}
      				if(Closes[1][0] < Opens[1][0]) {
      					if(iSwingDays <= 0) {
      						iSwingDays = iSwingDays-1;
      					} else {
      						iSwingDays = -1;
      					}
      				}				
      			}
      
      Plot0.Set(iSwingDays);
      Last edited by siroki; 09-18-2014, 11:09 AM.

      Comment


        #4
        You're welcome, I'm glad to hear - thanks for sharing here.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,610 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        16 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X