📄 financechart.php
字号:
$i = $this->lastIndex($this->m_volData);
$label = "Vol";
if ($i >= 0) {
$label = sprintf("Vol: %s%s", $this->formatValue($this->m_volData[$i],
$this->m_generalFormat), $this->m_volUnit);
}
$selectedLayer = null;
if (($i < 0) || ($closeChange[$i] == 0) || ($closeChange[$i] == NoValue)) {
$selectedLayer = $flatLayer;
} else if ($closeChange[$i] > 0) {
$selectedLayer = $upLayer;
} else {
$selectedLayer = $dnLayer;
}
$dataSetObj = $selectedLayer->getDataSet(0);
$dataSetObj->setDataName($label);
return $selectedLayer;
}
#/ <summary>
#/ Add a blank indicator chart to the finance chart. Used internally to add other indicators.
#/ Override to change the default formatting (eg. axis fonts, etc.) of the various indicators.
#/ </summary>
#/ <param name="height">The height of the chart in pixels.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addIndicator($height) {
#create a new chart object
$ret = new XYChart($this->m_totalWidth, $height + $this->m_topMargin +
$this->m_bottomMargin, Transparent);
$ret->setTrimData($this->m_extraPoints);
if ($this->m_currentChart != null) {
#if there is a chart before the newly created chart, disable its x-axis, and copy
#its x-axis labels to the new chart
$this->m_currentChart->xAxis->setColors(LineColor, Transparent);
$ret->xAxis->copyAxis($this->m_currentChart->xAxis());
} else {
#no existing chart - create the x-axis labels from scratch
$this->setXLabels($ret->xAxis());
}
#the newly created chart becomes the current chart
$this->m_currentChart = $ret;
#add chart to MultiChart and update the total height
$this->addChart(0, $this->m_totalHeight, $ret);
$this->m_totalHeight = $this->m_totalHeight + $height + 1;
$this->setSize($this->m_totalWidth, $this->m_totalHeight + $this->m_topMargin +
$this->m_bottomMargin);
#configure the plot area
$plotAreaObj = $ret->setPlotArea($this->m_leftMargin, $this->m_topMargin,
$this->m_totalWidth - $this->m_leftMargin - $this->m_rightMargin, $height,
$this->m_plotAreaBgColor);
$plotAreaObj->setGridColor($this->m_majorHGridColor, $this->m_majorVGridColor,
$this->m_minorHGridColor, $this->m_minorVGridColor);
$ret->setAntiAlias($this->m_antiAlias);
#configure legend box
$box = $ret->addLegend($this->m_leftMargin, $this->m_topMargin, false, $this->m_legendFont,
$this->m_legendFontSize);
$box->setBackground($this->m_legendBgColor);
$box->setMargin2(5, 0, 2, 0);
$box->setSize($this->m_totalWidth - $this->m_leftMargin - $this->m_rightMargin, 0);
#configure x-axis
$a = $ret->xAxis;
$a->setIndent(true);
$a->setTickLength(2, 0);
$a->setLabelStyle($this->m_xAxisFont, $this->m_xAxisFontSize, $this->m_xAxisFontColor,
$this->m_xAxisFontAngle);
#configure y-axis
$ret->setYAxisOnRight($this->m_axisOnRight);
$this->configureYAxis($ret->yAxis(), $height);
return $ret;
}
function configureYAxis(&$a, $height) {
$a->setAutoScale(0, 0.05, 0);
if ($height < 100) {
$a->setTickDensity(15);
}
$a->setMargin($this->m_yAxisMargin);
$a->setLabelStyle($this->m_yAxisFont, $this->m_yAxisFontSize, $this->m_yAxisFontColor, 0);
$a->setTickLength(-4, -2);
}
#/ <summary>
#/ Add a generic line indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="data">The data series of the indicator line.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <param name="name">The name of the indicator.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addLineIndicator($height, $data, $color, $name) {
$c = $this->addIndicator($height);
$this->addLineIndicator2($c, $data, $color, $name);
return $c;
}
#/ <summary>
#/ Add a line to an existing indicator chart.
#/ </summary>
#/ <param name="c">The indicator chart to add the line to.</param>
#/ <param name="data">The data series of the indicator line.</param>
#/ <param name="color">The color of the indicator line.</param>
#/ <param name="name">The name of the indicator.</param>
#/ <returns>The LineLayer object representing the line created.</returns>
function addLineIndicator2(&$c, $data, $color, $name) {
return $c->addLineLayer($data, $color, $this->formatIndicatorLabel($name, $data));
}
#/ <summary>
#/ Add a generic bar indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="data">The data series of the indicator bars.</param>
#/ <param name="color">The color of the indicator bars.</param>
#/ <param name="name">The name of the indicator.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addBarIndicator($height, $data, $color, $name) {
$c = $this->addIndicator($height);
$this->addBarIndicator2($c, $data, $color, $name);
return $c;
}
#/ <summary>
#/ Add a bar layer to an existing indicator chart.
#/ </summary>
#/ <param name="c">The indicator chart to add the bar layer to.</param>
#/ <param name="data">The data series of the indicator bars.</param>
#/ <param name="color">The color of the indicator bars.</param>
#/ <param name="name">The name of the indicator.</param>
#/ <returns>The BarLayer object representing the bar layer created.</returns>
function addBarIndicator2(&$c, $data, $color, $name) {
$layer = $c->addBarLayer($data, $color, $this->formatIndicatorLabel($name, $data));
$layer->setBorderColor(Transparent);
return $layer;
}
#/ <summary>
#/ Add an upper/lower threshold range to an existing indicator chart.
#/ </summary>
#/ <param name="c">The indicator chart to add the threshold range to.</param>
#/ <param name="layer">The line layer that the threshold range applies to.</param>
#/ <param name="topRange">The upper threshold.</param>
#/ <param name="topColor">The color to fill the region of the line that is above the
#/ upper threshold.</param>
#/ <param name="bottomRange">The lower threshold.</param>
#/ <param name="bottomColor">The color to fill the region of the line that is below
#/ the lower threshold.</param>
function addThreshold(&$c, &$layer, $topRange, $topColor, $bottomRange, $bottomColor) {
$topMark = $c->yAxis->addMark($topRange, $topColor, $this->formatValue($topRange,
$this->m_generalFormat));
$bottomMark = $c->yAxis->addMark($bottomRange, $bottomColor, $this->formatValue(
$bottomRange, $this->m_generalFormat));
$c->addInterLineLayer($layer->getLine(), $topMark->getLine(), $topColor, Transparent);
$c->addInterLineLayer($layer->getLine(), $bottomMark->getLine(), Transparent, $bottomColor);
}
function formatIndicatorLabel($name, $data) {
$i = $this->lastIndex($data);
if ($name == null) {
return $name;
}
if (($name == "") || ($i < 0)) {
return $name;
}
$ret = sprintf("%s: %s", $name, $this->formatValue($data[$i], $this->m_generalFormat));
return $ret;
}
#/ <summary>
#/ Add an Accumulation/Distribution 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 addAccDist($height, $color) {
#Close Location Value = ((C - L) - (H - C)) / (H - L)
#Accumulation Distribution Line = Accumulation of CLV * volume
$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();
return $this->addLineIndicator($height, $tmpArrayMath1->result(), $color,
"Accumulation/Distribution");
}
function computeAroonUp($period) {
$aroonUp = array_pad(array(), count($this->m_highData), 0);
for($i = 0; $i < count($this->m_highData); ++$i) {
$highValue = $this->m_highData[$i];
if ($highValue == NoValue) {
$aroonUp[$i] = NoValue;
} else {
$currentIndex = $i;
$highCount = $period;
$count = $period;
while (($count > 0) && ($currentIndex >= $count)) {
$currentIndex = $currentIndex - 1;
$currentValue = $this->m_highData[$currentIndex];
if ($currentValue != NoValue) {
$count = $count - 1;
if ($currentValue > $highValue) {
$highValue = $currentValue;
$highCount = $count;
}
}
}
if ($count > 0) {
$aroonUp[$i] = NoValue;
} else {
$aroonUp[$i] = $highCount * 100.0 / $period;
}
}
}
return $aroonUp;
}
function computeAroonDn($period) {
$aroonDn = array_pad(array(), count($this->m_lowData), 0);
for($i = 0; $i < count($this->m_lowData); ++$i) {
$lowValue = $this->m_lowData[$i];
if ($lowValue == NoValue) {
$aroonDn[$i] = NoValue;
} else {
$currentIndex = $i;
$lowCount = $period;
$count = $period;
while (($count > 0) && ($currentIndex >= $count)) {
$currentIndex = $currentIndex - 1;
$currentValue = $this->m_lowData[$currentIndex];
if ($currentValue != NoValue) {
$count = $count - 1;
if ($currentValue < $lowValue) {
$lowValue = $currentValue;
$lowCount = $count;
}
}
}
if ($count > 0) {
$aroonDn[$i] = NoValue;
} else {
$aroonDn[$i] = $lowCount * 100.0 / $period;
}
}
}
return $aroonDn;
}
#/ <summary>
#/ Add an Aroon Up/Down indicators chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
#/ <param name="period">The period to compute the indicators.</param>
#/ <param name="upColor">The color of the Aroon Up indicator line.</param>
#/ <param name="downColor">The color of the Aroon Down indicator line.</param>
#/ <returns>The XYChart object representing the chart created.</returns>
function addAroon($height, $period, $upColor, $downColor) {
$c = $this->addIndicator($height);
$this->addLineIndicator2($c, $this->computeAroonUp($period), $upColor, "Aroon Up");
$this->addLineIndicator2($c, $this->computeAroonDn($period), $downColor, "Aroon Down");
$c->yAxis->setLinearScale(0, 100);
return $c;
}
#/ <summary>
#/ Add an Aroon Oscillator indicator chart.
#/ </summary>
#/ <param name="height">The height of the indicator chart in pixels.</param>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -