[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: median calculation



PureBytes Links

Trading Reference Links

Hi to all,

I want to thank everyone who's responded for their help - I really do appreciate the fact that you've been willing to take the time to help with this.

But there's been some confusion as to the nature of my median calculation request, so I'm posting this in an attempt to better define the nature of the problem.

For those who are familiar with Joe Dinapoli's Oscillator Predictor, that is what I'm attempting to recreate in AFL. For those who are not familiar with it, his Predictor calculates a price at which one would take profits in a highly overbought or oversold condition, based on the average overbought or oversold level of an oscillator. In other words, if a person knows ahead of time the price at which a market would be highly overbought or oversold, a pre-placed order to exit at that price will catch spike moves and get one out BEFORE the market takes back the profits one has. Using only daily charts, Joe looks for the average value of the three highest peaks to determine a reasonable approximation of the average realistic overbought level. He does the same for the three lowest troughs to determine the average realistic oversold level.

*** I prefer to use the median value of the last four peaks (or troughs) in order to eliminate the most extreme values from the calculation. ***

His lookback range is roughly six months (120 bars) or so. The oscillator he uses is non-normalized, so the troughs will ALL be negative values.

For my purposes, I define a peak in the oscillator as the highest value reached during an excursion above zero. A trough is the lowest value reached during an excursion below zero. With that in mind, I have already created two arrays; one array contains all the peaks, the other contains the troughs. If a given day in either array is NOT a peak or trough based on the above definition, then that day's array element = ZERO. So here's an example of what my trough array would look like over the last 20 bars:

0, 0, -11, 0, 0, 0, -13, 0, -7, 0, -9, 0, 0, 0, -4, 0, -12, 0, 0, -2

Here is the brainteaser (to me):

Let's assume my lookback range is just these last 20 bars; obviously, the four lowest troughs are -11, -13, -9, and -12. I need to find a way to pick those four values out of the array in order to find the median value (which will equal -11.5).

That's IT - that's ALL I'm trying to do - I'm pretty sure I can figure out everything else I need to do.

Now I know it's possible to allow the user to input the number manually, by way of "Param", and that's all well and good. But I want to program it for user convenience (as well as cutting down on user error), and also be able to plot the resulting OB/OS price predictions as bands on the price chart (which will be all the more effective when Tomasz gets around to allowing plotting of indicators beyond the last bar!).

Anyway, again, ALL I need is a bit of direction on the median calculation in order to have the formula handle everything in the Oscillator Predictor's output.

If I ever get this figured out, or someone else does, I'll be sure to post it to the AFL library - this could be a very useful tool for capturing profits, especially if the output correlates with some other projection method, like Cardwell's positive and negative reversals in the RSI, or Fibonacci projections, or whatever other tool.

If you've managed to read this far, then...

Thanks again & best regards,

DC

[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/