NexusFi: Find Your Edge


Home Menu

 





Highest bar between 20 and 40 bars ago


Discussion in NinjaTrader

Updated
    1. trending_up 3,934 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 209

Hi -

I am aware of how to get the highest high/lowest low within the last X number of bars AND how to determine how many bars back each of those is.

What I'd like to do is find the highest high within X number of bars PRIOR to the highest high within X number of bars.

Huh, you say?

So, let's say I use MAX(High, 20)[1].
That tells me what the highest high in the last 20 bars was.
Then I use HighestBar(High, 20) and that tells me the actual value of that highest high.

Now, I want to find the highest high within the 20 bars prior to the high I just found, above.

Can anyone suggest code to do this? Or point to someone else's solution?

Thanks, in advance.

(My intention is to home in on the high/low cycles within a trading range, figuring out the width of the range and how many bars apart the highs and lows are.)


Follow me on X Started this thread Reply With Quote

 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639


DavidBodhi,

one approach would be to loop over the desired bars once you have the bar number of the highest high.
You could adjust the code in the first post here, to loop over the 20 bars to the left of the bar that returned the highest high:


As you are using Max in your code already, you should also be able to get the value using:
 
Code
int barsAgo = HighestBar(High, 20);
double HighestH2 = MAX(High, 20)[barsAgo+1];
Regards,

ABCTG


Follow me on X Reply With Quote
Thanked by:
  #4 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 209


ABCTG View Post
DavidBodhi,

one approach would be to loop over the desired bars once you have the bar number of the highest high.
You could adjust the code in the first post here, to loop over the 20 bars to the left of the bar that returned the highest high:


As you are using Max in your code already, you should also be able to get the value using:
 
Code
int barsAgo = HighestBar(High, 20);
double HighestH2 = MAX(High, 20)[barsAgo+1];
Regards,

ABCTG

Thanks, ABCTG. That will work well for the value of the previous high.

I'll also need the number of bars back that previous high occurred. I'm not much of a programmer, or I'm sure I'd see immediately how to look at all the prior closes from [1] to [barsAgo+1], but that code isn't clear to me. I'll do some research on that, unless you can offer another concise method.

Thanks, again.


Follow me on X Started this thread Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

DavidBodhi,

you are welcome. This would be something you can accomplish with the loop from the link, too. While you loop over the bars, save the high into your variable in case it's higher than the currently found highest high and save the number of bars this high is back in another variable.

Regards,

ABCTG


Follow me on X Reply With Quote
  #6 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 209


ABCTG View Post
DavidBodhi,

you are welcome. This would be something you can accomplish with the loop from the link, too. While you loop over the bars, save the high into your variable in case it's higher than the currently found highest high and save the number of bars this high is back in another variable.

Regards,

ABCTG

Thanks, again.

I'll look into that.


Follow me on X Started this thread Reply With Quote




Last Updated on August 25, 2017


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts