In point A, the output of the indicator should be half the length of the rectangle: I count about 14 bars in the rectangle, so at point A it should be 7, then as we move from point A to point B, every 2 bars I need to add 1 to the period, so if it's 7 at A, and B is about 10 bars later than point A, the output at B should be 12 (7+(10/2)), and it should gradually increase from 7 to 12 (+1 every 2 bars). Then if we move from B to C, it has to stay constant at 12.
So far you're talking gibberish.
WHY is it supposed to be 7 at A. WHY is it supposed to be 12 at B. And WHY is it constant from B to C. Until you can concretely describe your WHY, you have no chance at coding it.
- Your Oscillator [Sum(short term MAs) - Sum(long term MAs)] is not adjustable.
- "output should be half the length of the rectangle" Why, because that was the Oscillator wave length/2? (Current point, lowest low, highest high, cross back below current point)
- If that's true then the wave length at B in infinite since you're at a all time high (There is no low and recross above current level.)
- Or, it should point B be 3 since thats 1/2 OSC peek (B) to OSC peek (between A/B)
Hi WHRoeder,
thanks for your response. Indeed, if it was just a coding problem I would simply pay someone, but it's a logic/idea problem...
"WHY is it supposed to be 7 at A. WHY is it supposed to be 12 at B. And WHY is it constant from B to C. Until you can concretely describe your WHY, you have no chance at coding it."
Because if I take those values as input for my filter I get the desired behavior (smooth, responsive lines). So I need to create an indicator that gives me those values.
"Your Oscillator [Sum(short term MAs) - Sum(long term MAs)] is not adjustable."
No it is not. It's the window of my filter that will be adjustable, not the oscillator.
""output should be half the length of the rectangle" Why, because that was the Oscillator wave length/2?"
Yes. That is the size of the "swing", or of half the wave length.
"If that's true then the wave length at B in infinite since you're at a all time high (There is no low and recross above current level.)"
Not necessarily if you use past periods as reference: you simply increase and keep increasing as you see that the wave length goes up and the oscillator makes new highs, and then when the line comes back, you keep it the same because you are thinking in terms of sinusoids: overlap does not necessarily mean a decrease in period: I guess it depends on when the overlap starts, and how long it lasts before you adjust the period. If for a wave of 10 the required output is 5, and for a wave of 20 it is 10, then if you go from 10 to 20, you have to do +1 for every 2 bars as you make the move for it to be up-to-date with the current wavelength if the increase is gradual.
I have attached 2 indicators: one that "looks to the left", the idea behind it is that it draws an imaginary horizontal line on the chart, and it counts the number of bars since the close price was at the same level. I need to tweak it some way to get to this desired behavior, but not sure how: I think I need to combine it with the second one that keeps track of the largest absolute change. Use the output of 1 as the input for the window of the other somehow... (these are calculated on the close, but I simply uploaded them to illustrate the logic).
To more precisely answer your important question: ""WHY is it supposed to be 7 at A. WHY is it supposed to be 12 at B. And WHY is it constant from B to C. Until you can concretely describe your WHY, you have no chance at coding it."
Because if you looked at a number of sinusoids with different period (say 4 to 100), and you would cut out the best fitting piece that most closely resembles the shape of the last part of the oscillator from that sinusoid, then that would be that sinusoid's period.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I have a great filter. It has essentially zero lag, and is smoother than other known alternatives (JMA, ZLMA, ...). I have 1 problem though: that is the windowing function (the function that decides how many periods back it has to look to calculate the smoothed value in the current bar). I think that continually changing the length of the window over which the filter is calculated is crucial, because the market is not periodic: sometimes it makes large swings, sometimes really short ones (most people call that trend or range). I would like to create an indicator that will be the input for my filter: so this indicator returns a positive integer number >=2, which is the look-back length for my filter, that will result in the desired behavior of the filter. Please take a look at the image below:
In point A, the output of the indicator should be half the length of the rectangle: I count about 14 bars in the rectangle, so at point A it should be 7, then as we move from point A to point B, every 2 bars I need to add 1 to the period, so if it's 7 at A, and B is about 10 bars later than point A, the output at B should be 12 (7+(10/2)), and it should gradually increase from 7 to 12 (+1 every 2 bars). Then if we move from B to C, it has to stay constant at 12.
So the gray line is a sort of oscillator on which I calculate my filter (it's not mine but I forgot where I found it). The idea behind this is that inside the rectangle, the gray line resembles a sinusoid. My filter works the best if its look-back window is the length of the sinusoid divided by 2. If you go from A to B, it's like a part of a sinusoid with an increasing length, so you also have to increase the look-back period of the filter, and then from B to C it's like the period of the sinusoid stays constant. So in this scenario, it's like the "period" of the sinusoid increases. I also have to find a solution for the scenario of a "decreasing period". My biggest issue is that the "amplitude" of the swings is irrelevant: only the "period" matters.
I have been struggling with this problem for a long time, and will be more than happy to share the solution with anyone who can help me or offer ideas that lead to a solution.