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)
Yeah, it's faster, and it keeps you from repeating the arguments every time. Just all-around better. It's too bad ninja encourages the style that they do.
Another big source of inefficiency are indicators using MAX and MIN either directly or indirectly. I also have an article with an online algorithm for maintaining a sorted sliding window, which is much faster than doing an Array.Sort() every time OnBarUpdate is called (think about it... last bar you had a sorted window for everything but the newest value... make use of it rather than throw the almost correct answer away!). Much better for median filters and interquartile ranges, etc. There are other easy things to do, but I haven't had time to write them up. I'm kinda lazy about writing.
Richard, this is great! I optimized several custom indicators using this approach and the performance improvement is tremendous. Posted in the Elite Section is the optimized version of the Big Mike CMA Envelope Bands.. it loads in a split second. Thanks so much!
Sometimes the definitions of the external indicators include parameters that are updated dynamically. Whenever that happens, the definition of the external indicator must also be updated. Here is an example:
To account for price and volume you could apply the TSF to the Tick Money Flow instead of to the price. Or you could just apply it to the Cumulative Delta. (Assuming you are using NT7 which allows you to apply an indicator to an indicator)
The TSF TC …
For this reason, and also to avoid problems with NT6.5, I prefer to define the external indicators in a procedure module such as OnBarUpdate() rather than in OnStartUp().
Is there anything we can do about MAX and MIN? One particular custom indicator that uses them a lot is painfully slow to load. (BetterBuySellVolume, part of double Z trading package)
If you want a dataseries to capture the SMA of the MACD: (Note... MACD12 should have been MyNewMACD)
in Variables:
private DataSeries myMacdAvg;
private bool init = false;
private MACD MyNewMACD
private SMA SMAofMACD
in Initialize():
myMacdAvg = new DataSeries(this);
in OnBarUpdate();
if(!init)
{
MyNewMACD= MACD(12,26,9);
SMAofMACD=SMA(MyNewMACD, 7); // 7 period SMA of MACD(12,26,9)
init = true;
}
MyMacdAvg.Set(SMAofMACD[0]);
if(MyMacdAvg[0] > 0) // if current value of 7 period SMA of MACD(12,26,9)>0
(
Print("Hello Vorld");
FabianCancellera.WinWorldTimeTrialChampionship;
)
Very nice (except I don't see where MACD12 comes in or is actually used). In my previous example, which would be better in accomplishing the same result, using a DataSeries or not using a DataSeries? That is my question which might be better left to Richard.
The main thing is to remember a reference to the indicator, so that you don't have to ask ninja to look it up again. The number of DataSeries you need to look at isn't a factor.
So, your second example--just referencing myMacd.Avg[0]--is the one I'd use. Putting the information in an additional DataSeries isn't a necessary step, and wastes time and memory.
If you really just want a reference to the Avg part of the MACD indicator, you should be able to do that like this, though:
.. but you lose easy access to the rest of the MACD that way, and the performance increase would be negligible.
Thanks Richard. I was trying to avoid the memory consumption of an additional DataSeries and that is why I asked. Also I could not get this to work (I was using something other than the MACD but same idea).
Yeah, I can't see the code you are posting, but just be aware that when you change the inputs you are actually creating an additional indicator that runs in parallel with the original one. So, that can easily get out of hand if you don't do some quantizing... like: instead of changing the SMA length each bar, only change it in length multiples of 5, or whatever.
There are fast algorithms for maintaining the max/min of the last n samples. As with the sliding sorted window I posted about, the key is to realize that on the previous bar you had almost the right answer. If you can just incorporate the current bar's information without just searching all over again for the maximum, you are much better off. I just haven't had time to write those up yet. Maybe soon, but I'm sure someone motivated to speed them up can work out the details. Hint: if the maximum was 3 bars ago on the last bar, then it was 4 bars ago on this bar. So if the current bar's not larger than the previous maximum, and your length is >= 4, then there's no need to do anything. The maximum hasn't changed.