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)
I am new to NinjaTrader but know C# and need some advice.
I want to run a strategy that relies on the previous 2 5000 tick bars. However I don't really want to do it by bar, I want to have a moving window of the last 5000 ticks and the 5000-10000th ticks. So what I was doing is just keeping a list of my own of these ticks.
Will this just keep the last 2 windows of ticks and find their middle price?
Thanks
-Jeff
Can you help answer these questions from other members on NexusFi?
well you generally don't need to copy and then sort 10k-sized lists on every tick when all you want is the average of their largest and smallest values. As a first step you can just scan the list and locate the high and low in O(n) time. If you'd like to do better than that, I've written up an algorithm for maintaining a sorted sliding window with expected O(n/2) performance, which is article #5 on this page: Move the Markets| Articles.
I guess I wasn't totally clear on if you wanted the median, or the midpoint. Assuming the latter, then you'd want (H+L)/2... but as far as I can tell your code doesn't do that. It seems to be calculating Min(L, L + Abs(L - H))... which would always evaluate to L.