Thanh An Nguyen / Profil
- Bilgiler
yok
deneyim
|
0
ürünler
|
0
demo sürümleri
|
0
işler
|
1
sinyaller
|
0
aboneler
|
Thanh An Nguyen
Help me!
I want to code a hybrid indicator for an mt4 application. I will use the Accumulation/Distribution indicator as the main indicator, then I will add the Moving Average indicator to the Accumulation/Distribution indicator, the data of the Moving Average indicator will take the data of the indicator accumulate/distribute as input
Code:
"#property indicator_chart_window
// Input parameters
extern int period = 14; // Period for the Moving Average
// Global variables
double ad_values[]; // Array to store Accumulation/Distribution values
// Custom Indicator Initialization function
int init()
{
IndicatorBuffers(2); // Set the number of buffers required
// Set buffer 0 as the A/D values buffer
SetIndexBuffer(0, ad_values, INDICATOR_DATA);
// Set buffer 1 as the MA values buffer
SetIndexBuffer(1, NULL, INDICATOR_CALCULATIONS);
// Set the indicator labels
IndicatorDigits(Digits);
SetIndexLabel(0, "AD");
SetIndexLabel(1, "MA");
return 0;
}
// Custom Indicator Calculation function
int start()
{
int limit = MathMax(Bars - period, 0);
// Calculate Accumulation/Distribution values
for (int i = 0; i < limit; i++)
{
double high_prev = High[i + 1];
double low_prev = Low[i + 1];
double close_prev = Close[i + 1];
double volume_current = Volume[i];
double ad_value = ((Close[i] - low_prev) - (high_prev - Close[i])) /
(high_prev - low_prev) * volume_current;
ad_values[i] = ad_value;
}
// Calculate Moving Average on Accumulation/Distribution values
int ma_calculated = iMAOnArray(ad_values, 0, period, 0, MODE_SMA, 0);
return 0;
}
"
I want to code a hybrid indicator for an mt4 application. I will use the Accumulation/Distribution indicator as the main indicator, then I will add the Moving Average indicator to the Accumulation/Distribution indicator, the data of the Moving Average indicator will take the data of the indicator accumulate/distribute as input
Code:
"#property indicator_chart_window
// Input parameters
extern int period = 14; // Period for the Moving Average
// Global variables
double ad_values[]; // Array to store Accumulation/Distribution values
// Custom Indicator Initialization function
int init()
{
IndicatorBuffers(2); // Set the number of buffers required
// Set buffer 0 as the A/D values buffer
SetIndexBuffer(0, ad_values, INDICATOR_DATA);
// Set buffer 1 as the MA values buffer
SetIndexBuffer(1, NULL, INDICATOR_CALCULATIONS);
// Set the indicator labels
IndicatorDigits(Digits);
SetIndexLabel(0, "AD");
SetIndexLabel(1, "MA");
return 0;
}
// Custom Indicator Calculation function
int start()
{
int limit = MathMax(Bars - period, 0);
// Calculate Accumulation/Distribution values
for (int i = 0; i < limit; i++)
{
double high_prev = High[i + 1];
double low_prev = Low[i + 1];
double close_prev = Close[i + 1];
double volume_current = Volume[i];
double ad_value = ((Close[i] - low_prev) - (high_prev - Close[i])) /
(high_prev - low_prev) * volume_current;
ad_values[i] = ad_value;
}
// Calculate Moving Average on Accumulation/Distribution values
int ma_calculated = iMAOnArray(ad_values, 0, period, 0, MODE_SMA, 0);
return 0;
}
"
: