I am struggling to convert the ADX indicator code (by Metaquotes) to work with array data instead of MT4 data centre.
I did successfully converted the feed source so it works OK for drawing buffers (for visual indicator purposes),
but when I try to use the buffer arrays just to pull data from (without drawing vectors), I get no values.
I really can't figure out, why the calculation of adx values are accessable only when i draw the visual vectors.
It must be something I don't realy aware of how MQL works!!!
Maybe any of you can help me out with this issue?
I attach original ADX code + my revision intend to work independntly, no drawing, only supply values through arrays.
Will Appreciate any Help.
REVISED CODE:: INTEND TO SUPPLY ADX VALUES FROM ARRAYS:
I did successfully converted the feed source so it works OK for drawing buffers (for visual indicator purposes),
but when I try to use the buffer arrays just to pull data from (without drawing vectors), I get no values.
I really can't figure out, why the calculation of adx values are accessable only when i draw the visual vectors.
It must be something I don't realy aware of how MQL works!!!
Maybe any of you can help me out with this issue?
I attach original ADX code + my revision intend to work independntly, no drawing, only supply values through arrays.
Will Appreciate any Help.
REVISED CODE:: INTEND TO SUPPLY ADX VALUES FROM ARRAYS:
PHP Code
//+------------------------------------------------------------------+
//| ADX.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- input parameters
extern int ADXPeriod=14;
//---- buffers
double a_ADX[];
double PlusDi[];
double MinusDi[];
double PlusSdi[];
double MinusSdi[];
double TempBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Average Directional Movement Index |
//+------------------------------------------------------------------+
int start()
{
double pdm,mdm,tr;
double price_high,price_low;
int starti,i,counted_bars=IndicatorCounted();
double tempRates[][6];
ArrayCopyRates(tempRates,"EURUSD",60);
Comment(ArraySize(tempRates)+" first bar="+tempRates[ArraySize(tempRates)/6-1][3]);
//----
i=ArraySize(tempRates)/6-1-2;
PlusSdi[i+1]=0;
MinusSdi[i+1]=0;
if(counted_bars>=i) i=ArraySize(tempRates)/6-1-counted_bars-1;
starti=i;
//----
while(i>=0)
{
price_low=tempRates[i][2];
price_high=tempRates[i][3];
//----
pdm=price_high-tempRates[i+1][3];
mdm=tempRates[i+1][2]-price_low;
if(pdm<0) pdm=0; // +DM
if(mdm<0) mdm=0; // -DM
if(pdm==mdm) { pdm=0; mdm=0; }
else if(pdm<mdm) pdm=0;
else if(mdm<pdm) mdm=0;
//---- ????????? ???????? ????????
double num1=MathAbs(price_high-price_low);
double num2=MathAbs(price_high-tempRates[i+1][4]);
double num3=MathAbs(price_low-tempRates[i+1][4]);
tr=MathMax(num1,num2);
tr=MathMax(tr,num3);
//---- counting plus/minus direction
if(tr==0) { PlusSdi[i]=0; MinusSdi[i]=0; }
else { PlusSdi[i]=100.0*pdm/tr; MinusSdi[i]=100.0*mdm/tr; }
//----
i--;
}
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
int limit=ArraySize(tempRates)/6-1-counted_bars;
//---- apply EMA to +DI
for(i=0; i<=limit; i++)
PlusDi[i]=iMAOnArray(PlusSdi,ArraySize(tempRates)/6-1,ADXPeriod,0,MODE_EMA,i);
//---- apply EMA to -DI
for(i=0; i<=limit; i++)
MinusDi[i]=iMAOnArray(MinusSdi,ArraySize(tempRates)/6-1,ADXPeriod,0,MODE_EMA,i);
//---- Directional Movement (DX)
i=ArraySize(tempRates)/6-1-2;
TempBuf[i+1]=0;
i=starti;
while(i>=0)
{
double div=MathAbs(PlusDi[i]+MinusDi[i]);
if(div==0.00) TempBuf[i]=0;
else TempBuf[i]=100*(MathAbs(PlusDi[i]-MinusDi[i])/div);
i--;
}
//---- ADX is exponential moving average on DX
for(i=0; i<limit; i++)
{
a_ADX[i]=iMAOnArray(TempBuf,ArraySize(tempRates)/6-1,ADXPeriod,0,MODE_EMA,i);
}
// ******* HELP:: WHY I DONT GET VALUES FOR a_ADX array or any other? *****************
// ******* Why if i would draw buffer line as indicator, it would supply values? ******
Comment("ADX Mian="+a_ADX[0]);
return(0);
}
Attached File(s)
ADX.mq4
4 KB
|
289 downloads