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)
Efficient Code for finding highest high and lowest lows of a range of bars.
Hi
I'm quite new to C# and ninja script and am convinced there must be a better way to do this...
I'm trying to find the lowest low and highest high for a range of bars - (let's say 9 for the sake of argument) - e.g. so I can code a Tenkan Sen Ichimoku line. At the moment I'm doing it by looping through the indexes of the last nine Bars in like this:
int Period = 9; //define the number of bars to check back
double HighestH = 0;
double LowestL = 0;
for (int i=0; i < Period; i++)
{ if(High[i] > HighestH)
HighestH = High[i];
if (Low[i] == 0)
{
LowestL = Low[i];
}else
if(Low[i] < LowestL)
LowestL = Low[i];
}
Whilst this works, I can't imagine it's the neatest/most compact code. Maybe it's because I've spent most of my life using Excel and using functions like = Max(A1:A9) to effectively do the same thing.
Anyone got any suggestions of code to neaten this up.
When creating a new thread, note which subforum you are in. Here is a short list of suggestions:
- Topic: Anything to do with an Elite indicator -> Subforum: The Elite Circle
- Topic: Looking for an existing indicator, or how-to use an indicator -> Subforum: (the platform)
- Topic: Programmer needing help with non-Elite indicator -> Subforum: (the platform) - Programming
- Topic: Want an indicator created/modified -> Reply to "Want indicator created free" in Elite Circle
- Topic: Vendors (trading rooms, commercial indicators) -> Subforum: Vendors/Product Reviews
- Topic: Discussion of Forex or Currency trading -> Subforum: Forex and Currency Trading
- Topic: Journals of your trading -> Subforum: Trading Journals or Elite Trading Journals
- Topic: General trading related discussions -> Subforum: Traders Hideout
- Topic: Discussion of a trading method -> Subforum: Traders Hideout
- Topic: Automated Trading -> Subforum: Elite Automated Trading
Last, any Elite Member may create more or less any of these topics in The Elite Circle at your own discretion (your support is appreciated).
This is just a short general list and doesn't cover everything. If you are unsure where to create your new thread, just create it in Traders Hideout and a moderator will move it if necessary.
I'm not sure of the implication of this. Does this mean if I take say 2 of my custom indicators and they have common code, then I put this common code in a UserDefinedMethod and call it from my indicators, they will run slower?
- Code called locally for things like min,max will be much faster if you don't use the "indicators" MIN, MAX as those have to maintain separate dataseries and indexes, while a local function does not.
@Zondor has lots to say on this subject and I don't use NT right now, so hopefully he can help you out.
Assuming your building a strategy: In order to use FirstTickOfBar, Calculate on Bar Close must be set to false.
From NT Help Section:
Indicates if the incoming tick is the first tick of a new bar. This property is only of value in strategies that run tick by tick which is when the [COLOR=#0066cc][I]CalculateOnBarClose[/I][/COLOR] property is set to false.
Online Help Guide: NinjaTrader Version 7
This can also be accessed from with NT Control Center under Help Menu.
Search on: FirstTickOfBar
Also if you want to limit it to the 'x' number of last bars the code will need some tweaks, or limit it to daily high or low need to reset on new session.
Assuming your building a strategy: In order to use FirstTickOfBar, Calculate on Bar Close must be set to false.
From NT Help Section:
Indicates if the incoming tick is the first tick of a new bar. This property is only of value in strategies that run tick by tick which is when the CalculateOnBarClose property is set to false.
If calculate on bar close is false, FirstTickOfBar is always true and the instance of the MAX function will be called once per bar, just like it is supposed to be.