Efficient Code for finding highest high and lowest lows of a range of bars. - NinjaTrader Programming | futures io social day trading
futures io futures trading


Efficient Code for finding highest high and lowest lows of a range of bars.
Updated: Views / Replies:8,456 / 18
Created: by xigreek Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Efficient Code for finding highest high and lowest lows of a range of bars.

  #11 (permalink)
Elite Member
AB, CA
 
Futures Experience: None
Platform: MC
Favorite Futures: es
 
Posts: 3 since Nov 2009
Thanks: 24 given, 1 received


Zondor View Post
In the variables region, declare an instance, maxH of the MAX class:

 
Code
private MAX maxH;
In OnStartUp(), define the instance of the MAX class:

 
Code
maxH = MAX(High, lookback);

In OnBarUpdate(), call that instance, ONLY WHEN NECESSARY:

 
Code
if( FirstTickOfBar || Input[0] > HighestH ) HighestH = maxH[0];


Thanks Zondor,

So, my dilemma is this... I've been trying to create clean, efficient code and I've seen others do two things:

1. Use Methods they have created and then call from their main indicator (UserDefinedMethods).
2. Create an indicator and then use its results similar to how you are suggesting above.

I'd like to create the fastest code possible and wonder if doing either of the above will slow my code down as opposed to keeping everything in the one indicator.
I did find a good pdf by Richard Todd, http://richardtodd.name/docs/pdf/efficientNinjaScript.pdf, that also talks about your method above.

So, for number 1, if I pull out code that is used in many different indicators and place this common code into a userdefinedmethod file, does my indicator run slower? My guess on this one is probably not.

Although number 2 appeals to me since I can create simple building blocks and use them in the main indicator, does Ninja end up using more resources? i.e. say for instance the building block utilizes a DataSeries in its code and then a variable is created in the main indicator of the building block type, as you show above, is Ninja then using twice the resources (2 DataSeries now instead of just one, compared to if I made one large indicator)?

I hope this makes sense... if not, please let me know & I'll try to explain it better. (I'm not a programmer by profession and C# is new to me.)

Thanks,

TT

Reply With Quote
The following user says Thank You to trendtrader for this post:
 
  #12 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received


Quoting 
So, my dilemma is this... I've been trying to create clean, efficient code and I've seen others do two things:

1. Use Methods they have created and then call from their main indicator (UserDefinedMethods).
2. Create an indicator and then use its results similar to how you are suggesting above.

I'd like to create the fastest code possible and wonder if doing either of the above will slow my code down as opposed to keeping everything in the one indicator.
I did find a good pdf by Richard Todd, http://richardtodd.name/docs/pdf/efficientNinjaScript.pdf, that also talks about your method above.

So, for number 1, if I pull out code that is used in many different indicators and place this common code into a userdefinedmethod file, does my indicator run slower? My guess on this one is probably not.

Richard W. Todd is an expert virtuoso programmer who knows what he is talking about. The posts he made (as user "Richard") in the code optimization thread that ZTR started on futures.io (formerly BMT) were exceptionally valuable.

The only thing that would be faster than using the predefined instances of the MAX indicator would be putting the code of the MAX indicator INSIDE your indicator as one of its custom methods. I don't think the small performance improvement would be worth the trouble. You DO want to call the MAX function as infrequently as possible since it will sometimes iterate through a loop.

Ninjatrader's new improved version of MAX, which was suggested to them by RWT, does not do that nearly as often as the old one did. It uses logic tests to avoid unnecessary looping. But it's better to not do even those when a call to MAX is not needed at all.

If you send me your code in a PM, I will review it.


Last edited by Zondor; January 3rd, 2012 at 05:35 AM.
Reply With Quote
 
  #13 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Interactive Brokers
Favorite Futures: forex
 
Posts: 38 since Aug 2011
Thanks: 9 given, 25 received



Big Mike View Post
Multiple ways.

Another:

HighestH = MAX(High, lookback)[0];

You can easily put max and min into your local indicator as a function instead of calling it externally, speeding it up quite a bit.

Mike

I'm the biggest fan of using functions instead of indicators. You can get great performance improvement.

Reply With Quote
 
  #14 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Interactive Brokers
Favorite Futures: forex
 
Posts: 38 since Aug 2011
Thanks: 9 given, 25 received


Zondor View Post
Richard W. Todd is an expert virtuoso programmer who knows what he is talking about. The posts he made (as user "Richard") in the code optimization thread that ZTR started on futures.io (formerly BMT) were exceptionally valuable.

The only thing that would be faster than using the predefined instances of the MAX indicator would be putting the code of the MAX indicator INSIDE your indicator as one of its custom methods. I don't think the small performance improvement would be worth the trouble. You DO want to call the MAX function as infrequently as possible since it will sometimes iterate through a loop.

Ninjatrader's new improved version of MAX, which was suggested to them by RWT, does not do that nearly as often as the old one did. It uses logic tests to avoid unnecessary looping. But it's better to not do even those when a call to MAX is not needed at all.

If you send me your code in a PM, I will review it.

I don't use external indicators in my strategy at all, not even the simplest one like SMA, EMA or ZLEMA
They are all coded as functions.
Strategy is running on 28 currency pairs 6 timeframes
modules(functions): Current OHLC, PreviousDayOHL, RoundNumbers, SwingRays, FibLevels, Pivots, SMA 2 timeframes, EMA 6 timeframes, ZLEMA, CurrencyMeter, New High/Lows

Strategy is running darn fast, and absolutely NO Freezing, NADA

Reply With Quote
The following user says Thank You to BankRobberNT for this post:
 
  #15 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received


BankRobberNT View Post
I don't use external indicators in my strategy at all, not even the simplest one like SMA, EMA or ZLEMA
They are all coded as functions.
Strategy is running on 28 currency pairs 6 timeframes
modules(functions): Current OHLC, PreviousDayOHL, RoundNumbers, SwingRays, FibLevels, Pivots, SMA 2 timeframes, EMA 6 timeframes, ZLEMA, CurrencyMeter, New High/Lows

Strategy is running darn fast, and absolutely NO Freezing, NADA

Let me get this totally straight: you write the code into your Strategy for those indicators? Or do you write it into User Defined Functions?

If you write it into your Strategy, don't you have a headache when you have 10 strategies in development and you want to change one indicator that's in all of them?

You can discover what your enemy fears most by observing the means he uses to frighten you.
Reply With Quote
 
  #16 (permalink)
 Vendor: www.coroin.com 
Galveston ,TX
 
Futures Experience: Intermediate
Platform: NT7
Broker/Data: Zaner
Favorite Futures: Futures
 
Posts: 386 since Mar 2010
Thanks: 364 given, 433 received


trendtrader View Post
I did find a good pdf by Richard Todd, http://richardtodd.name/docs/pdf/efficientNinjaScript.pdf, that also talks about your method above.

anyone have a copy of the pdf and/or an updated link to the pdf?

cheers,
-e

Reply With Quote
 
  #17 (permalink)
Elite Member
Puyallup, Washington State
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: NINJATRADER/CQG
Favorite Futures: NQ, CL, ES, YM
 
echoeversky's Avatar
 
Posts: 115 since Sep 2009
Thanks: 113 given, 48 received


eman View Post
anyone have a copy of the pdf and/or an updated link to the pdf?

cheers,
-e


No but he's baaaaaaaaack...
richardwesleytodd.blogspot.com/2013/05/starting-another-in-long-line-of-new.html

Reply With Quote
 
  #18 (permalink)
 Vendor: www.probabletrades.com 
OC, California, USA
 
Futures Experience: Advanced
Platform: IB/TWS, NinjaTrader, thinkorswim
Favorite Futures: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,859 since Jun 2009
Thanks: 480 given, 3,254 received

If you REALLY want faster...

Answer
This post has been selected as an answer to the original posters question Answer

You should keep your recent highs/low in a queue implemented as arrays, on bar update take out the oldest number, put on the newest number and iterate through them to get the high/low of the lookback period. Anytime you use indexers on DataSeries you are actually calling get() methods/functions on enumerable objects, which involves popping and pushing variables onto the stack, setting up function pointers and contexts, more garbage collection cycles, etc.

double[] arrays sit on the heap because "double" is a value type, not a reference type, and no methods are called to read/write arrays.

Sorry I'm not including sample code, too busy coding other things for other people right now, but maybe someone else can supply something.

Reply With Quote
The following user says Thank You to shodson for this post:
 
  #19 (permalink)
Elite Member
San Isidro Lima / Peru
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Stocks
 
Posts: 2 since Nov 2012
Thanks: 0 given, 0 received

I'm trying to find the bar number of the highest bar of my current session, but when I try something like this:

numBarHigh = HighestBar(High, Bars.BarsSinceSession);

it has trouble when the highest bar is the 1st bar of the session.
Any advice?

Reply With Quote

Reply



futures io > > > > > Efficient Code for finding highest high and lowest lows of a range of bars.

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
highest bar close occuring within the last X number of bars . . . . jmejedi NinjaTrader Programming 37 October 6th, 2014 01:52 AM
The Highest, High-Probability-Trade tigertrader Traders Hideout 38 May 22nd, 2014 11:39 AM
Converting code from Tradestation/ Plots Swing Point Highs/Lows wbtrader NinjaTrader Programming 4 May 14th, 2013 09:20 PM
Lowest Bar with the largest range kaywai NinjaTrader Programming 3 May 8th, 2011 06:36 PM
On finding the optimal settings for a range interval trendisyourfriend The Elite Circle 5 December 7th, 2010 02:53 PM


All times are GMT -4. The time now is 10:31 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-10 in 0.16 seconds with 37 queries on phoenix via your IP 54.221.73.186