TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file ADX.php

Documentation is available at ADX.php

  1. <?php
  2.  
  3. /**
  4.  * ADX class
  5.  *
  6.  * Description: ADX Function
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage functions
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.  class ADX extends Functions {
  17.  
  18.     private $iDMDown;
  19.     private $iDMUp;
  20.     private $interpolate true;
  21.     private $factor 4;
  22.  
  23.     // Interceptors
  24.     function __get$property {
  25.       $method ="get{$property}";
  26.       if method_exists$this$method ) ) {
  27.         return $this->$method();
  28.       }
  29.     }
  30.  
  31.     function __set $property,$value {
  32.       $method ="set{$property}";
  33.       if method_exists$this$method ) ) {
  34.         return $this->$method($value);
  35.       }
  36.     }
  37.  
  38.     public function ADX($c=null{
  39.         parent::Functions($c);
  40.         
  41.         $this->dPeriod = 14;
  42.         $this->SingleSource = true;
  43.         $this->HideSourceList = true;
  44.  
  45.         $this->iDMDown new FastLine();
  46.         $this->HideSeries($this->iDMDown);
  47.         $tmpColor new Color(255,0,0);  // RED
  48.         $this->iDMDown->setColor($tmpColor);
  49.  
  50.         $this->iDMUp new FastLine();
  51.         $this->HideSeries($this->iDMUp);
  52.         $this->iDMUp->setColor(new Color(0,128,0));  // GREEN
  53.     }
  54.  
  55.         /// Access characteristics of the DMDown line (a FastLineSeries).
  56.         /// DMDown is a sub-series (of type FastLine) of ADX function.
  57.     public function getDMDown({
  58.         return $this->iDMDown;
  59.     }
  60.  
  61.         /// Access characteristics of the DMUp line (a FastLineSeries).
  62.         /// DMUp is a sub-series (of type FastLine) of ADX function.
  63.     public function getDMUp({
  64.         return $this->iDMUp;
  65.     }
  66.  
  67.         /// The pen used to draw the upper ADX line.
  68.         /// Corresponds to DMUp.Pen property.
  69.         /// <code>
  70.         /// aDX.getUpLinePen().setColor(Color.Blue);
  71.         /// </code>
  72.     public function getUpLinePen({
  73.         return $this->iDMUp->getLinePen();
  74.     }
  75.  
  76.         /// The pen used to draw the lower ADX line.
  77.         /// Corresponds to DMDown.Pen property.
  78.     public function getDownLinePen({
  79.         return $this->iDMDown->getLinePen();
  80.     }
  81.  
  82.     public function isValidSourceOf($value{
  83.         return $value instanceof OHLC;
  84.     }
  85.  
  86.     private function prepareSeries($series{
  87.         $series->setChart($this->getSeries()->getChart());
  88.         $series->setCustomVertAxis($this->getSeries()->getCustomVertAxis());
  89.         $series->setVerticalAxis($this->getSeries()->getVerticalAxis());
  90.         $series->getXValues()->setDateTime($this->getSeries()->getXValues()->
  91.                                          $this->getDateTime());
  92.  
  93. /* TODO        $series->addSeriesPaintListener( new SeriesPaintAdapter() {
  94.             public function seriesPainting($e) {
  95.                 $this->ADX->this->getSeries()->doBeforeDrawChart();
  96.             };
  97.  
  98.             public function seriesPainted($e) {
  99.                 $this->ADX->this->getSeries()->doBeforeDrawChart();
  100.             };
  101.         });
  102. */
  103.     }
  104.  
  105.     private function calcADX($Index{
  106.          $tmpIndex $Index MathUtils::round($this->getPeriod());
  107.          $result (100 *
  108.                          abs($this->iDMUp->getYValues()->getValue($tmpIndex-
  109.                                   $this->iDMDown->getYValues()->getValue($tmpIndex)) /
  110.                          ($this->iDMUp->getYValues()->getValue($tmpIndex+
  111.                           $this->iDMDown->getYValues()->getValue($tmpIndex)));
  112.         return $result;
  113.     }
  114.  
  115.         ///Gets all points from Source series, performs a function operation and stores results in ParentSeries.
  116.     public function addPoints($source{
  117.          $tmpTR=Array();
  118.          $tmpDMUp=Array();
  119.          $tmpDMDown=Array();
  120.          $tmpClose;
  121.          $tmpX;
  122.         //    base.AddPoints (source);
  123.         if (!$this->updating// 5.02
  124.             if ($source != null{
  125.                 if (sizeof($source0{
  126.                     $this->getSeries()->clear();
  127.                      $s $source->offsetget(0);
  128.                     if ($s->getCount(0{
  129.                         if ($this->getPeriod(2{
  130.                             return;
  131.                         }
  132.  
  133.                         $this->iDMUp->clear();
  134.                         $this->iDMDown->clear();
  135.                         $this->prepareSeries($this->iDMUp);
  136.                         $this->prepareSeries($this->iDMDown);
  137.  
  138.                         if ($s->getCount(>= ($this->getPeriod())) {
  139.                             $this->Closes $s->getCloseValues();
  140.                             $this->Highs $s->getHighValues();
  141.                             $this->Lows $s->getLowValues();
  142.  
  143.                             $tmpTR[$s->getCount();
  144.                             $tmpDMUp[$s->getCount();
  145.                             $tmpDMDown[$s->getCount();
  146.  
  147.                             for $t 1$t $s->getCount()++$t{
  148.                                 $tmpClose $this->Closes->getValue($t 1);
  149.                                 $tmpTR[$t$this->Highs->getValue($t$this->Lows->getValue($t);
  150.                                 $tmpTR[$tmax($tmpTR[$t],
  151.                                         abs($this->Highs->getValue($t$tmpClose));
  152.                                 $tmpTR[$tmax($tmpTR[$t],
  153.                                         abs($this->Lows->getValue($t$tmpClose));
  154.  
  155.                                 if (($this->Highs->getValue($t$this->Highs->getValue($t 1)) >
  156.                                     ($this->Lows->getValue($t 1$this->Lows->getValue($t))) {
  157.                                     $tmpDMUp[$tmax(0,
  158.                                             $this->Highs->getValue($t-
  159.                                             $this->Highs->getValue($t 1));
  160.                                 else {
  161.                                     $tmpDMUp[$t0;
  162.                                 }
  163.  
  164.                                 if (($this->Lows->value[$t 1$this->Lows->value[$t]>
  165.                                     ($this->Highs->value[$t$this->Highs->value[$t 1])) {
  166.                                     $tmpDMDown[$tmax(0,
  167.                                             $this->Lows->getValue($t 1-
  168.                                             $this->Lows->getValue($t));
  169.                                 else {
  170.                                     $tmpDMDown[$t0;
  171.                                 }
  172.                             }
  173.  
  174.                              $tmpTR2 0;
  175.                              $tmpUp2 0;
  176.                              $tmpDown2 0;
  177.  
  178.                              $tmp MathUtils::round($this->getPeriod());
  179.  
  180.                             for $t $tmp$t $s->getCount()++$t{
  181.                                 if ($t == $tmp{
  182.                                     for $tt 1;
  183.                                                   $tt <= MathUtils::round($this->getPeriod());
  184.                                                   ++$tt{
  185.                                         $tmpTR2 $tmpTR2 $tmpTR[$tt];
  186.                                         $tmpUp2 $tmpUp2 $tmpDMUp[$tt];
  187.                                         $tmpDown2 $tmpDown2 $tmpDMDown[$tt];
  188.                                     }
  189.                                 else {
  190.                                     $tmpTR2 $tmpTR2 ($tmpTR2 $this->getPeriod()) +
  191.                                              $tmpTR[$t];
  192.                                     $tmpUp2 $tmpUp2 ($tmpUp2 $this->getPeriod()) +
  193.                                              $tmpDMUp[$t];
  194.                                     $tmpDown2 $tmpDown2 ($tmpDown2 $this->getPeriod()) +
  195.                                                $tmpDMDown[$t];
  196.                                 }
  197.                                 $tmpX $s->getXValues()->getValue($t);
  198.                                 $this->iDMUp->add($tmpX100 ($tmpUp2 $tmpTR2));
  199.                                 $this->iDMDown->add($tmpX100 ($tmpDown2 $tmpTR2));
  200.                             }
  201.  
  202.                             $tmpTR[]Array();
  203.                             $tmpDMUp Array();
  204.                             $tmpDMDown Array();
  205.                             $tmpADX 0;
  206.  
  207.                             $tmp MathUtils::round(($this->getPeriod()) 2);
  208.  
  209.                             for $t $tmp$t $s->getCount()++$t{
  210.                                 if ($t == $tmp{
  211.                                     $tmpADX 0;
  212.                                     for $tt MathUtils::round($this->getPeriod());
  213.                                                   $tt <= $tmp++$tt{
  214.                                         $tmpADX $tmpADX $this->calcADX($tt);
  215.                                     }
  216.                                     $tmpADX $tmpADX ($this->getPeriod(1);
  217.                                 else {
  218.                                     $tmpADX (($tmpADX ($this->getPeriod(1)) +
  219.                                               ($this->calcADX($t))) $this->getPeriod();
  220.                                 }
  221.  
  222.                                 $this->getSeries()->add($s->getXValues()->getValue($t),
  223.                                                 $tmpADX);
  224.                             }
  225.                         }
  226.                     }
  227.                 }
  228.             }
  229.         }
  230.     }
  231.  
  232.     private function HideSeries($ASeries{
  233.         $ASeries->setShowInLegend(false);
  234.         $ASeries->InternalUse true;
  235.     }
  236.  
  237.     protected function dispose($disposing{
  238.         $this->iDMDown->dispose();
  239.         $this->iDMUp->dispose();
  240.         $this->dispose($disposing);
  241.     }
  242.  
  243.         /**
  244.           * Gets descriptive text.
  245.           *
  246.           * @return String 
  247.           */
  248.     public function getDescription({
  249.         return Language::getString("FunctionADX");
  250.     }
  251. }
  252.  
  253. ?>

Documentation generated on Wed, 16 Jun 2010 12:02:24 +0200 by phpDocumentor 1.4.1