int extern int Window.Length = 10; : SetIndexDrawBegin(0, Window.Length+1); : int counted = IndicatorCounted(); if (counted <= Window.Length) counted = Window.Length+1; // Look back for(int iBar = Bars - 1 - counted; iBar >= 0; iBar--){ sum[iBar]=0; for (int iWin = iBar + Window.Length - 1; iWin >= iBar; iWin--) if (Close[iWin] > Close[iWin+1]) sum[iBar] += 1; else sum[iBar] -= 1; }
Make it 100. How inefficient is it to test 100 values and increment/decrement 100 times per tick? Unnoticeable on a MHz machine and I'll bet yours is a GHz. Don't optimize until you know you have a problem. Then don't update bar zero (ibar >= 0 becomes iBar > 0). Now your testing/incrmenting once per new bar.
That's true. I just hate the idea of inefficient code when all you need to do is add the new one and subtract the old one. I was brought up with punched cards, operating systems on mylar tape, and trying to fit code into the 1K memory of a ZX81! It's hard for me to code things non-optimally :-)
And even then on my dual core GHz machine my indicators run too slowly, lagging behind the market noticeably, and I have been thinking about upgrading to a ram-disk hard drive to speed things up.
EDIT: and of course when you change profiles, or change accounts, or change timeframe, and the indicator recalculates from scratch, this part of the calculation would then be 50x longer with the simple "unoptimized" method.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to create a moving sum of the sign of the bars: an up bar is +1, a down bar is -1, on a window of adjustable size: how do I work with a window? should be extern int window=10; and then??