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

Re: [amibroker] Re: median calculation



PureBytes Links

Trading Reference Links

Hi Bill,

Well, uh, thanks, but...

It's not the median of the last four peaks or troughs I'm after... I want to calculate the median of the four highest peaks and the median of the four lowest troughs, which won't necessarily be the last four peaks or troughs.

DC
  ----- Original Message ----- 
  From: Bill Barnard 
  To: amibroker@xxxxxxxxxxxxxxx 
  Sent: Saturday, November 06, 2004 2:14 AM
  Subject: [amibroker] Re: median calculation



  --- In amibroker@xxxxxxxxxxxxxxx, <dennisconn@xxxx> wrote:
  > My dictionary defines it as the average of the two middle values
  when the number sequence contains an even number of values. If the
  sequence contains an odd number of values, the middle value would be
  the median.
  > 
  > I'm just having a heck of a time trying to figure out how to get AB
  to segregate the four highest and four lowest values out of the entire
  array in order to obtain the medians...
  > 
  > Any ideas?
  > 


  Amibroker's Peak and Trough functions identify extreme points which
  are  characterized by a reversal of a certain percentage. If this is
  how you identified your points of interest, then the following code
  would find the medians of the last four peaks and the last four
  troughs.

  // Code Start

  Osc = 100*(EMA((C - EMA(C, 50)) / C, 20)); // <<< example oscillator

  reversalPcnt = 5; // <<<< percent to define peak or trough

  // Peak and trough functions work correctly only on arrays 
  // containing data greater than zero, so for an oscillator,
  // if it goes below zero, add a constant before finding 
  // peaks and troughs. Later subtract it from the results.

  Const = IIf(Lowest(Osc) < 0, -1*Lowest(Osc), 0);

  p1 = Peak(Osc+Const, reversalPcnt, 1) - Const;
  p2 = Peak(Osc+Const, reversalPcnt, 2) - Const;
  p3 = Peak(Osc+Const, reversalPcnt, 3) - Const;
  p4 = Peak(Osc+Const, reversalPcnt, 4) - Const;

  biggestP  = Max(p4, Max(p3, Max(p2, p1)));
  smallestP = Min(p4, Min(p3, Min(p2, p1)));
  MedianP   = (p1 + p2 + p3 + p4 - biggestP - smallestP) / 2;

  t1 = Trough(Osc+Const, reversalPcnt, 1) - Const;
  t2 = Trough(Osc+Const, reversalPcnt, 2) - Const;
  t3 = Trough(Osc+Const, reversalPcnt, 3) - Const;
  t4 = Trough(Osc+Const, reversalPcnt, 4) - Const;

  biggestT  = Max(t4, Max(t3, Max(t2, t1)));
  smallestT = Min(t4, Min(t3, Min(t2, t1)));
  MedianT   = (t1 + t2 + t3 + t4 - biggestT - smallestT) / 2;

  Plot(Osc, "osc", 32);

  _TRACE("DBGVIEWCLEAR");
  _TRACE("const  = "+ Const);
  _TRACE("p1 = "+ p1);
  _TRACE("p2 = "+ p2);
  _TRACE("p3 = "+ p3);
  _TRACE("p4 = "+ p4);
  _TRACE("biggestP= "+ biggestP);
  _TRACE("smallestP= "+ smallestP);
  _TRACE("MedianP = "+ MedianP);
  _TRACE("t1 = "+ t1);
  _TRACE("t2 = "+ t2);
  _TRACE("t3 = "+ t3);
  _TRACE("t4 = "+ t4);
  _TRACE("biggestT= "+ biggestT);
  _TRACE("smallestT= "+ smallestT);
  _TRACE("MedianT = "+ MedianT);

  // Code End





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

  Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 


        Yahoo! Groups Sponsor 
              ADVERTISEMENT
             
       
       


------------------------------------------------------------------------------
  Yahoo! Groups Links

    a.. To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/
      
    b.. To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx
      
    c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 





------------------------------------------------------------------------------

  Message transport security by GatewayDefender
  2:15:43 AM ET - 11/6/2004

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



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/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/