Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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
Can you help answer these questions from other members on NexusFi?
// 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....
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 ?
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 ?
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
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?