NexusFi: Find Your Edge


Home Menu

 





highest bar close occuring within the last X number of bars . . . .


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Loukas with 16 posts (0 thanks)
    2. looks_two forrestang with 12 posts (8 thanks)
    3. looks_3 jmejedi with 6 posts (0 thanks)
    4. looks_4 Fat Tails with 2 posts (1 thanks)
    1. trending_up 23,168 views
    2. thumb_up 10 thanks given
    3. group 4 followers
    1. forum 37 posts
    2. attach_file 5 attachments




 
Search this Thread

highest bar close occuring within the last X number of bars . . . .

  #1 (permalink)
 
jmejedi's Avatar
 jmejedi 
Lilburn, GA
 
Experience: Beginner
Platform: NinjaTrader
Broker: VelocityFutures/TT
Trading: ES
Posts: 62 since Jan 2011
Thanks Given: 13
Thanks Received: 4

sorry in advance if this already exists within this forum, but at least I can't find it and that's why I'm posting this as a new thread . . . . . . . . . . . . . . Here's the Q:

How would I accomplish the below in NinjaScript . . . . . .

// if CURRENT-BAR-CLOSE > HIGHEST-BAR-CLOSE within last 10 bars THEN enterLong()
//
// if CURRENT-BAR-CLOSE < LOWEST-BAR-CLOSE within last 10 bars THEN enterShort()
//
//


I'm thinking it would look something like this:

if ( Close[0] > INSERT-CODE-HERE-TO-DETERMINE-BAR-WITH-ITS-CLOSE-BEING-HIGHEST-AMONG-THE-#-OF-BARS-AGO )



Any help with this would be greatly appreciated !

Thanks in advance,

Jimmy

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Futures True Range Report
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #3 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,609 since Aug 2009
Thanks Given: 11,328
Thanks Received: 2,743



jmejedi View Post
sorry in advance if this already exists within this forum, but at least I can't find it and that's why I'm posting this as a new thread . . . . . . . . . . . . . . Here's the Q:

How would I accomplish the below in NinjaScript . . . . . .

// if CURRENT-BAR-CLOSE > HIGHEST-BAR-CLOSE within last 10 bars THEN enterLong()
//
// if CURRENT-BAR-CLOSE < LOWEST-BAR-CLOSE within last 10 bars THEN enterShort()
//
//

Is this what you need?
From NT7 Help File:

 
Code
// Prints the highest  high value over the last 20 periods
double value = MAX(High, 20)[0]; Print("The current MAX value is " + value.ToString());
// Prints the lowest low value over the last 20 periods double value = MIN(Low, 20)[0]; Print("The current MIN value is " + value.ToString());

Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on Twitter Reply With Quote
  #4 (permalink)
 
jmejedi's Avatar
 jmejedi 
Lilburn, GA
 
Experience: Beginner
Platform: NinjaTrader
Broker: VelocityFutures/TT
Trading: ES
Posts: 62 since Jan 2011
Thanks Given: 13
Thanks Received: 4

i don't think this is working . . . . .


// if CURRENT-BAR-CLOSE > HIGHEST-BAR-CLOSE within last 10 bars THEN enterLong()
if ( Close[0] > MAX(Close, 20)[0] ) {EnterLong();}
//
// if CURRENT-BAR-CLOSE < LOWEST-BAR-CLOSE within last 10 bars THEN enterShort()
if ( Close[0] < MIN(Close, 20)[0] ) {EnterShort();}
//


............... this code has got to be executed at some time,,,, I'm running back-testing on it............ & the back testing isn't resulting in any entries........... strange, b/c this situation happens all day, anytime, any day....



Please help ?

Started this thread Reply With Quote
  #5 (permalink)
 
jmejedi's Avatar
 jmejedi 
Lilburn, GA
 
Experience: Beginner
Platform: NinjaTrader
Broker: VelocityFutures/TT
Trading: ES
Posts: 62 since Jan 2011
Thanks Given: 13
Thanks Received: 4

this code is executed within the method

OnBarUpdate()


.... furthermore,,,,,, I'm testing this on

6e

instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Started this thread Reply With Quote
  #6 (permalink)
 
jmejedi's Avatar
 jmejedi 
Lilburn, GA
 
Experience: Beginner
Platform: NinjaTrader
Broker: VelocityFutures/TT
Trading: ES
Posts: 62 since Jan 2011
Thanks Given: 13
Thanks Received: 4

alright, I think I found it:



"

NinjaScript > Language Reference > Data >
HighestBar()

Definition
Returns the number of bars ago the highest price value occurred for the lookback period.

Method Return Value
An int value that represents number of bars ago.

Syntax
HighestBar(IDataSeries series, int lookBackPeriod)

Parameters
lookBackPeriod
Number of bars back to include in the calculation
series
Any DataSeries type object such as an indicator, Close, High, Low, etc...


Examples
// Prints out the number of bars ago for the highest close of the current session
Print(HighestBar(Close, Bars.BarsSinceSession - 1).ToString());

"






please confirm this is correct as per my definition in my first post above ?

Started this thread Reply With Quote
  #7 (permalink)
 
jmejedi's Avatar
 jmejedi 
Lilburn, GA
 
Experience: Beginner
Platform: NinjaTrader
Broker: VelocityFutures/TT
Trading: ES
Posts: 62 since Jan 2011
Thanks Given: 13
Thanks Received: 4

wait . . . . . . . . actually the above is wrong,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, what I really want is:



Close[HighestBar(Close, 10)]



, , , , , , Right ??

Started this thread Reply With Quote
  #8 (permalink)
 
jmejedi's Avatar
 jmejedi 
Lilburn, GA
 
Experience: Beginner
Platform: NinjaTrader
Broker: VelocityFutures/TT
Trading: ES
Posts: 62 since Jan 2011
Thanks Given: 13
Thanks Received: 4

Apparently, that isn't right neither . . . . . . namely this:


// if CURRENT-BAR-CLOSE > HIGHEST-BAR-CLOSE within last 10 bars THEN enterLong()
if ( Close[0] > Close[HighestBar(Close, 10)] ) {EnterLong();}
//
// if CURRENT-BAR-CLOSE < LOWEST-BAR-CLOSE within last 10 bars THEN enterShort()
if ( Close[0] < Close[LowestBar(Close, 10)] ) {EnterShort();}
//


........... this code never gets executed during the course of the trading . . . . . . . . . . . . . I'm really losing it,,,,, anyone please help out ?


Thanks in advance,

Jimmy Espana

Started this thread Reply With Quote
  #9 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2

Hi All,

Do you have any ideas why this is not working? if (CrossAbove(Close,MAX(High,5)[1],1))
I want a conbition which is will do something when the close price cross above the highest price of the previous 5 period

Thanks

Reply With Quote
  #10 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047



Loukas View Post
Hi All,

Do you have any ideas why this is not working? if (CrossAbove(Close,MAX(High,5)[1],1))
I want a conbition which is will do something when the close price cross above the highest price of the previous 5 period

Thanks

Not sure what your intent is, but try this out. Of course you'll have to declare these two dataSeries above I added called 'temp' and 'temp1'. But if you want to use the CrossAbove function, I don't think you can index two different bars, from two different times like you want. So here i've captured into a DataSeries the PRIOR bar into the current bar... if that makes any sense?

 
Code
			temp[0] = MAX(High, 5)[0];
			temp1[0] = temp[1];
			if (CrossAbove(Close, temp1, 1)  )
			{
				DrawArrowUp("arrow"+CurrentBar, true, 0, Low[0]-12*TickSize, Color.Green);
			}

Attached Thumbnails
Click image for larger version

Name:	Prime2011-09-03_194602.jpg
Views:	399
Size:	31.5 KB
ID:	48328  
Reply With Quote
Thanked by:




Last Updated on October 6, 2014


© 2024 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 - Privacy Policy - Downloads - Top
no new posts