📄 financechart.php
字号:
#/ <param name="period">The period to compute the indicator.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addAroonOsc($height, $period, $color) {
$label = "Aroon Oscillator ($period)";
$tmpArrayMath1 = new ArrayMath($this->computeAroonUp($period));
$tmpArrayMath1->sub($this->computeAroonDn($period));
$c = $this->addLineIndicator($height, $tmpArrayMath1->result(), $color, $label);
$c->yAxis->setLinearScale(-100, 100);
return $c;
}
function computeTrueRange() {
$tmpArrayMath1 = new ArrayMath($this->m_closeData);
$tmpArrayMath1->shift();
$previousClose = $tmpArrayMath1->result();
$tmpArrayMath1 = new ArrayMath($this->m_highData);
$tmpArrayMath1->sub($this->m_lowData);
$ret = $tmpArrayMath1->result();
$temp = 0;
for($i = 0; $i < count($this->m_highData); ++$i) {
if (($ret[$i] != NoValue) && ($previousClose[$i] != NoValue)) {
$temp = abs($this->m_highData[$i] - $previousClose[$i]);
if ($temp > $ret[$i]) {
$ret[$i] = $temp;
}
$temp = abs($previousClose[$i] - $this->m_lowData[$i]);
if ($temp > $ret[$i]) {
$ret[$i] = $temp;
}
}
}
return $ret;
}
#/ <summary>
#/ Add an Average Directional Index indicators chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period">The period to compute the indicator.</param>
#/ <param name="posColor">The color of the Positive Directional Index line.</param>
#/ <param name="negColor">The color of the Negatuve Directional Index line.</param>
#/ <param name="color">The color of the Average Directional Index line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addADX($height, $period, $posColor, $negColor, $color) {
#pos/neg directional movement
$tmpArrayMath1 = new ArrayMath($this->m_highData);
$tmpArrayMath1->delta();
$pos = $tmpArrayMath1->selectGTZ();
$tmpArrayMath1 = new ArrayMath($this->m_lowData);
$tmpArrayMath1->delta();
$tmpArrayMath1->mul(-1);
$neg = $tmpArrayMath1->selectGTZ();
$tmpArrayMath1 = new ArrayMath($pos->result());
$tmpArrayMath1->sub($neg->result());
$delta = $tmpArrayMath1->result();
$pos->selectGTZ($delta);
$neg->selectLTZ($delta);
#pos/neg directional index
$tr = $this->computeTrueRange();
$financeDivObj = $pos->financeDiv($tr, 0.25);
$mulObj = $financeDivObj->mul(100);
$mulObj->expAvg(2.0 / ($period + 1));
$financeDivObj = $neg->financeDiv($tr, 0.25);
$mulObj = $financeDivObj->mul(100);
$mulObj->expAvg(2.0 / ($period + 1));
#directional movement index ??? what happen if division by zero???
$tmpArrayMath1 = new ArrayMath($pos->result());
$tmpArrayMath1->add($neg->result());
$totalDM = $tmpArrayMath1->result();
$tmpArrayMath1 = new ArrayMath($pos->result());
$tmpArrayMath1->sub($neg->result());
$tmpArrayMath1->abs();
$tmpArrayMath1->financeDiv($totalDM, 0);
$tmpArrayMath1->mul(100);
$dx = $tmpArrayMath1->expAvg(2.0 / ($period + 1));
$c = $this->addIndicator($height);
$label1 = "+DI ($period)";
$label2 = "-DI ($period)";
$label3 = "ADX ($period)";
$this->addLineIndicator2($c, $pos->result(), $posColor, $label1);
$this->addLineIndicator2($c, $neg->result(), $negColor, $label2);
$this->addLineIndicator2($c, $dx->result(), $color, $label3);
return $c;
}
#/ <summary>
#/ Add an Average True Range indicators chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period">The period to compute the indicator.</param>
#/ <param name="color1">The color of the True Range line.</param>
#/ <param name="color2">The color of the Average True Range line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addATR($height, $period, $color1, $color2) {
$trueRange = $this->computeTrueRange();
$c = $this->addLineIndicator($height, $trueRange, $color1, "True Range");
$label = "Average True Range ($period)";
$tmpArrayMath1 = new ArrayMath($trueRange);
$tmpArrayMath1->expAvg(2.0 / ($period + 1));
$this->addLineIndicator2($c, $tmpArrayMath1->result(), $color2, $label);
return $c;
}
#/ <summary>
#/ Add a Bollinger Band Width indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period">The period to compute the indicator.</param>
#/ <param name="width">The band width to compute the indicator.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addBollingerWidth($height, $period, $width, $color) {
$label = "Bollinger Width ($period, $width)";
$tmpArrayMath1 = new ArrayMath($this->m_closeData);
$tmpArrayMath1->movStdDev($period);
$tmpArrayMath1->mul($width * 2);
return $this->addLineIndicator($height, $tmpArrayMath1->result(), $color, $label);
}
#/ <summary>
#/ Add a Community Channel Index indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period">The period to compute the indicator.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <param name="range">The distance beween the middle line and the upper and lower threshold lines.</param>
#/ <param name="upColor">The fill color when the indicator exceeds the upper threshold line.</param>
#/ <param name="downColor">The fill color when the indicator falls below the lower threshold line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addCCI($height, $period, $color, $range, $upColor, $downColor) {
#typical price
$tmpArrayMath1 = new ArrayMath($this->m_highData);
$tmpArrayMath1->add($this->m_lowData);
$tmpArrayMath1->add($this->m_closeData);
$tmpArrayMath1->div(3);
$tp = $tmpArrayMath1->result();
#simple moving average of typical price
$tmpArrayMath1 = new ArrayMath($tp);
$tmpArrayMath1->movAvg($period);
$smvtp = $tmpArrayMath1->result();
#compute mean deviation
$movMeanDev = array_pad(array(), count($smvtp), 0);
for($i = 0; $i < count($smvtp); ++$i) {
$avg = $smvtp[$i];
if ($avg == NoValue) {
$movMeanDev[$i] = NoValue;
} else {
$currentIndex = $i;
$count = $period - 1;
$acc = 0;
while (($count > 0) && ($currentIndex >= $count)) {
$currentIndex = $currentIndex - 1;
$currentValue = $tp[$currentIndex];
if ($currentValue != NoValue) {
$count = $count - 1;
$acc = $acc + abs($avg - $currentValue);
}
}
if ($count > 0) {
$movMeanDev[$i] = NoValue;
} else {
$movMeanDev[$i] = $acc / $period;
}
}
}
$c = $this->addIndicator($height);
$label = "CCI ($period)";
$tmpArrayMath1 = new ArrayMath($tp);
$tmpArrayMath1->sub($smvtp);
$tmpArrayMath1->financeDiv($movMeanDev, 0);
$tmpArrayMath1->div(0.015);
$layer = $this->addLineIndicator2($c, $tmpArrayMath1->result(), $color, $label);
$this->addThreshold($c, $layer, $range, $upColor, -$range, $downColor);
return $c;
}
#/ <summary>
#/ Add a Chaikin Money Flow indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period">The period to compute the indicator.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addChaikinMoneyFlow($height, $period, $color) {
$tmpArrayMath1 = new ArrayMath($this->m_highData);
$tmpArrayMath1->sub($this->m_lowData);
$range = $tmpArrayMath1->result();
$tmpArrayMath1 = new ArrayMath($this->m_volData);
$tmpArrayMath1->movAvg($period);
$volAvg = $tmpArrayMath1->result();
$label = "Chaikin Money Flow ($period)";
$tmpArrayMath1 = new ArrayMath($this->m_closeData);
$tmpArrayMath1->mul(2);
$tmpArrayMath1->sub($this->m_lowData);
$tmpArrayMath1->sub($this->m_highData);
$tmpArrayMath1->mul($this->m_volData);
$tmpArrayMath1->financeDiv($range, 0);
$tmpArrayMath1->movAvg($period);
$tmpArrayMath1->financeDiv($volAvg, 0);
return $this->addBarIndicator($height, $tmpArrayMath1->result(), $color, $label);
}
#/ <summary>
#/ Add a Chaikin Oscillator indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addChaikinOscillator($height, $color) {
#first compute acc/dist line
$tmpArrayMath1 = new ArrayMath($this->m_highData);
$tmpArrayMath1->sub($this->m_lowData);
$range = $tmpArrayMath1->result();
$tmpArrayMath1 = new ArrayMath($this->m_closeData);
$tmpArrayMath1->mul(2);
$tmpArrayMath1->sub($this->m_lowData);
$tmpArrayMath1->sub($this->m_highData);
$tmpArrayMath1->mul($this->m_volData);
$tmpArrayMath1->financeDiv($range, 0);
$tmpArrayMath1->acc();
$accdist = $tmpArrayMath1->result();
#chaikin osc = exp3(accdist) - exp10(accdist)
$tmpArrayMath1 = new ArrayMath($accdist);
$tmpArrayMath1->expAvg(2.0 / (11));
$expAvg10 = $tmpArrayMath1->result();
$tmpArrayMath1 = new ArrayMath($accdist);
$tmpArrayMath1->expAvg(2.0 / (4));
$tmpArrayMath1->sub($expAvg10);
return $this->addLineIndicator($height, $tmpArrayMath1->result(), $color,
"Chaikin Oscillator");
}
#/ <summary>
#/ Add a Chaikin Volatility indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period1">The period to smooth the range.</param>
#/ <param name="period2">The period to compute the rate of change of the smoothed range.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addChaikinVolatility($height, $period1, $period2, $color) {
$label = "Chaikin Volatility ($period1, $period2)";
$tmpArrayMath1 = new ArrayMath($this->m_highData);
$tmpArrayMath1->sub($this->m_lowData);
$tmpArrayMath1->expAvg(2.0 / ($period1 + 1));
$tmpArrayMath1->rate($period2);
$tmpArrayMath1->sub(1);
$tmpArrayMath1->mul(100);
return $this->addLineIndicator($height, $tmpArrayMath1->result(), $color, $label);
}
#/ <summary>
#/ Add a Close Location Value indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addCLV($height, $color) {
#Close Location Value = ((C - L) - (H - C)) / (H - L)
$tmpArrayMath1 = new ArrayMath($this->m_highData);
$tmpArrayMath1->sub($this->m_lowData);
$range = $tmpArrayMath1->result();
$tmpArrayMath1 = new ArrayMath($this->m_closeData);
$tmpArrayMath1->mul(2);
$tmpArrayMath1->sub($this->m_lowData);
$tmpArrayMath1->sub($this->m_highData);
$tmpArrayMath1->financeDiv($range, 0);
return $this->addLineIndicator($height, $tmpArrayMath1->result(), $color,
"Close Location Value");
}
#/ <summary>
#/ Add a Detrended Price Oscillator indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period">The period to compute the indicator.</param>
#/ <param name="color">The color of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -