|
ADX Indicator Values |
Posted by James on Nov-19-2010 13:05 |
|
Hello,
I was working on financial chart and was trying to add ADX indicator. And I noticed that the
values are totally different from StockCharts.com's chart and my manual calculation.
For my manual calculation, I was using ta-lib which I can use for computing many
indicators.
The results are
NWK ADX: 22.9443870713653 +DI: 30.375167969138 -DI: 10.7492857747004
These values are similar to StockCharts.com's chart as you see below (their daily data
source may be little different from mine).
However, the values on FinancialChart are big different.
I was copying and paste from the sample code.
m.addADX(IndicatorHeight, 14, 0x8000, 0x800000, 0x80);
How can I resolve this? I was comparing with many stock values and their ADX values in
FinancialChart are big different from other chart websites like StockCharts or TDAmeritrade.
How can I resolve this? Thanks,
|
Re: ADX Indicator Values |
Posted by Peter Kwan on Nov-19-2010 17:59 |
|
Hi James,
The ADX is one of the several indicator values that have self-inconsistent formulas. The ADX/+DI/-DI computed by different web sites may be somewhat different. Even in the same web site, the ADX/+DI/-DI obtained by using a 30-day chart and half-year chart could be different.
We have noted that the ADX/+DI/-DI computed by ChartDirector can be very different from other web sites. We have already got a new alogrithm which seems to obtain values closer to other web sites.
If you would like to use the code for the new algorithm, please kindly let me know of your programming language.
Hope this can help.
Regards
Peter Kwan |
Re: ADX Indicator Values |
Posted by James on Nov-19-2010 23:15 |
|
Thank you for quick response,
My testing environment is Visual Studio 2010 with C#. How do I evaluate new algorithm?
Thank you always! |
Re: ADX Indicator Values |
Posted by Peter Kwan on Nov-20-2010 03:41 |
|
Hi James,
If you are using the code structure as in the "Interactive Financial Chart" sample code, you may perform the followings:
(A) Include the following code in your existing code
private double[] computeTrueRange()
{
double[] previousClose = new ArrayMath(closeData).shift().result();
double[] ret = new ArrayMath(highData).sub(lowData).result();
double temp = 0;
for(int i = 0; i < highData.Length; ++i) {
if ((ret[i] != Chart.NoValue) && (previousClose[i] != Chart.NoValue)) {
temp = Math.Abs(highData[i] - previousClose[i]);
if (temp > ret[i]) {
ret[i] = temp;
}
temp = Math.Abs(previousClose[i] - lowData[i]);
if (temp > ret[i]) {
ret[i] = temp;
}
}
}
return ret;
}
public XYChart addADX(FinanceChart f, int height, int period, int posColor, int negColor, int color)
{
//pos/neg directional movement
ArrayMath pos = new ArrayMath(highData).delta().selectGTZ();
ArrayMath neg = new ArrayMath(lowData).delta().mul(-1).selectGTZ();
double[] delta = new ArrayMath(pos.result()).sub(neg.result()).result();
pos.selectGTZ(delta);
neg.selectLTZ(delta);
double[] posArray = pos.result();
double[] negArray = neg.result();
posArray[1] = (posArray[1] * 2 + negArray[1]) / 3;
negArray[1] = (negArray[1] + posArray[1]) / 2;
pos = new ArrayMath(posArray);
neg = new ArrayMath(negArray);
//pos/neg directional index
double[] tr = computeTrueRange();
tr = new ArrayMath(tr).expAvg(1.0 / period).result();
pos.expAvg(1.0 / period).financeDiv(tr, 0).mul(100);
neg.expAvg(1.0 / period).financeDiv(tr, 0).mul(100);
//directional movement index ??? what happen if division by zero???
double[] totalDM = new ArrayMath(pos.result()).add(neg.result()).result();
ArrayMath dx = new ArrayMath(pos.result()).sub(neg.result()).abs().financeDiv(totalDM, 0
).mul(100).expAvg(1.0 / period);
XYChart c = f.addIndicator(height);
string label1 = "+DI (" + period + ")";
string label2 = "-DI (" + period + ")";
string label3 = "ADX (" + period + ")";
f.addLineIndicator2(c, pos.result(), posColor, label1);
f.addLineIndicator2(c, neg.result(), negColor, label2);
f.addLineIndicator2(c, dx.result(), color, label3);
return c;
}
(B) Instead of using "m.addADX(height, 14, 0x008000, 0x800000, 0x000080);", please change it to "addADX(m, height, 14, 0x008000, 0x800000, 0x000080);".
Hope this can help.
Regards
Peter Kwan |
Re: ADX Indicator Values |
Posted by James on Nov-20-2010 08:32 |
|
Thank you very much. It worked.
Your support and your product are two thumbs up. Have a great weekend.
James |
Re: ADX Indicator Values |
Posted by Panahi on Nov-28-2014 01:32 |
|
Hi James,
I'm beginner at TA-Lib,I need develop some indicator with TA-Lib i C#, and also create out
put chart through HighStock chart,can you help me where I can start,of course I have
suitable data such as High,Low,Open, and close prices |
Re: ADX Indicator Values |
Posted by Peter Kwan on Nov-28-2014 23:58 |
|
Hi Panahi,
Note that this forum is mainly for support the ChartDirector software.
If you would like to develop some indicators and then plot the chart using ChartDirector,
you may get started by download ChartDirector from our web site. There are a lot of sample
code inside, including some financial charts sample code. The FinanceChart library contains
some APIs to allow for user computed indicators (such as FinanceChart.addLineIndicator,
FinanceChart.addBarIndicator, etc). To actually compute the indicators, there is an
ArrayMath library. As the FinanceChart is open source and the source code is included in
the download, so you can look inside to see how the various standard indicators are
computed using the ArrayMath library, and use it as a reference to develop your own
indicators and include them in the chart.
Hope this can help.
Regards
Peter Kwna |
Re: ADX Indicator Values |
Posted by sandeep on Nov-18-2015 20:21 |
|
hello ,
this seems to be java code, is there any equivalent code for php language
thanks& regards,
sandeep kumar.p |
Re: ADX Indicator Values |
Posted by Peter Kwan on Nov-19-2015 01:23 |
|
Hi sandeep,
The code in this thread is copied from the "FinanceChart.java" included in "ChartDirector for
JSP/Java". There is an equivalent code "FinanceChart.php" in "ChartDirector for PHP" too.
Hope this can help.
Regards
Peter Kwan |
|