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 quantismo, 04-17-2024, 05:13 PM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by proptrade13, Today, 11:06 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        34 views
        0 likes
        Last Post love2code2trade  
        Started by cls71, Today, 04:45 AM
        2 responses
        10 views
        0 likes
        Last Post eDanny
        by eDanny
         
        Started by kulwinder73, Today, 10:31 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X