Les erreurs indiquent que les tableaux open, high, low, et close doivent être passés par référence dans les fonctions de MQL5. En MQL5, les tableaux sont passés par référence par défaut sans spécification explicite &, mais il est parfois nécessaire de s'assurer que vos appels de fonctions et déclarations respectent cette contrainte.
Pour résoudre ce problème, assurez-vous que vos fonctions acceptent et transmettent correctement les tableaux par référence. Voici la façon correcte de gérer cela avec les tableaux :
//+------------------------------------------------------------------+
//| Ichimoku.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2010, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Ichimoku Kinko Hyo"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_plots 6
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_FILLING
#property indicator_type4 DRAW_LINE
#property indicator_type5 DRAW_ARROW
#property indicator_type6 DRAW_ARROW
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 SandyBrown,Thistle
#property indicator_color4 Lime
#property indicator_color5 Green
#property indicator_color6 Red
#property indicator_label1 "Tenkan-sen"
#property indicator_label2 "Kijun-sen"
#property indicator_label3 "Senkou Span A;Senkou Span B"
#property indicator_label4 "Chikou Span"
#property indicator_label5 "Buy Signal"
#property indicator_label6 "Sell Signal"
//--- input parameters
input int InpTenkan = 9; // Tenkan-sen
input int InpKijun = 26; // Kijun-sen
input int InpSenkou = 52; // Senkou Span B
//--- indicator buffers
double ExtTenkanBuffer[];
double ExtKijunBuffer[];
double ExtSpanABuffer[];
double ExtSpanBBuffer[];
double ExtChikouBuffer[];
double BuySignalBuffer[];
double SellSignalBuffer[];
//--- Heikin Ashi buffers
double haOpen[];
double haHigh[];
double haLow[];
double haClose[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0, ExtTenkanBuffer);
SetIndexBuffer(1, ExtKijunBuffer);
SetIndexBuffer(2, ExtSpanABuffer);
SetIndexBuffer(3, ExtSpanBBuffer);
SetIndexBuffer(4, ExtChikouBuffer);
SetIndexBuffer(5, BuySignalBuffer);
SetIndexBuffer(6, SellSignalBuffer);
//--- indicator arrow settings
PlotIndexSetInteger(5, PLOT_ARROW, 233); // Use Wingdings arrow up
PlotIndexSetInteger(6, PLOT_ARROW, 234); // Use Wingdings arrow down
//--- Initialisation des lignes de l'indicateur Ichimoku
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpKijun);
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, InpKijun);
PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, InpSenkou - 1);
PlotIndexSetInteger(2, PLOT_SHIFT, InpKijun);
PlotIndexSetInteger(3, PLOT_SHIFT, InpKijun);
PlotIndexSetInteger(4, PLOT_SHIFT, -InpKijun);
//--- Initialisation des buffers Heikin Ashi
ArraySetAsSeries(haOpen, true);
ArraySetAsSeries(haHigh, true);
ArraySetAsSeries(haLow, true);
ArraySetAsSeries(haClose, true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Méthode pour calculer la plus haute valeur sur une période |
//+------------------------------------------------------------------+
double Highest(const double &array[], int range, int index)
{
double high = array[index];
for (int i = index; i > index - range && i >= 0; i--) {
if (array[i] > high) {
high = array[i];
}
}
return(high);
}
//+------------------------------------------------------------------+
//| Méthode pour calculer la plus basse valeur sur une période |
//+------------------------------------------------------------------+
double Lowest(const double &array[], int range, int index)
{
double low = array[index];
for (int i = index; i > index - range && i >= 0; i--) {
if (array[i] < low) {
low = array[i];
}
}
return(low);
}
//+------------------------------------------------------------------+
//| Calcul des bougies Heikin Ashi |
//+------------------------------------------------------------------+
void CalculateHeikinAshi(const int rates_total, const double &open[], const double &high[], const double &low[], const double &close[])
{
if (rates_total < 2) return;
haClose[0] = (open[0] + high[0] + low[0] + close[0]) / 4.0;
haOpen[0] = (open[1] + close[1]) / 2.0;
haHigh[0] = MathMax(high[0], MathMax(haOpen[0], haClose[0]));
haLow[0] = MathMin(low[0], MathMin(haOpen[0], haClose[0]));
for (int i = 1; i < rates_total; i++) {
haClose[i] = (open[i] + high[i] + low[i] + close[i]) / 4.0;
haOpen[i] = (haOpen[i-1] + haClose[i-1]) / 2.0;
haHigh[i] = MathMax(high[i], MathMax(haOpen[i], haClose[i]));
haLow[i] = MathMin(low[i], MathMin(haOpen[i], haClose[i]));
}
}
//+------------------------------------------------------------------+
//| Méthode principale pour calculer l'indicateur Ichimoku |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
CalculateHeikinAshi(rates_total, open, high, low, close);
int limit = MathMax(InpKijun, MathMax(InpTenkan, InpSenkou));
for (int i = prev_calculated; i < rates_total; i++) {
ExtChikouBuffer[i] = close[i];
if (i >= InpTenkan) {
double high_tenkan = Highest(high, InpTenkan, i);
double low_tenkan = Lowest(low, InpTenkan, i);
ExtTenkanBuffer[i] = (high_tenkan + low_tenkan) / 2.0;
}
if (i >= InpKijun) {
double high_kijun = Highest(high, InpKijun, i);
double low_kijun = Lowest(low, InpKijun, i);
ExtKijunBuffer[i] = (high_kijun + low_kijun) / 2.0;
}
if (i >= InpSenkou) {
ExtSpanABuffer[i] = (ExtTenkanBuffer[i] + ExtKijunBuffer[i]) / 2.0;
double high_spb = Highest(high, InpSenkou, i);
double low_spb = Lowest(low, InpSenkou, i);
ExtSpanBBuffer[i] = (high_spb + low_spb) / 2.0;
}
if (i > 1) {
bool longCondition = haHigh[i] > MathMax(haHigh[i-1], haHigh[i-2]) &&
close[i] > ExtChikouBuffer[i] &&
close[i] > MathMax(ExtSpanABuffer[i], ExtSpanBBuffer[i]) &&
(ExtTenkanBuffer[i] >= ExtKijunBuffer[i] || close[i] > ExtKijunBuffer[i]);
bool shortCondition = haLow[i] < MathMin(haLow[i-1], haLow[i-2]) &&
close[i] < ExtChikouBuffer[i] &&
(ExtTenkanBuffer[i] < ExtKijunBuffer[i] ||
close[i] < ExtSpanABuffer[i] ||
close[i] < MathMin(ExtSpanABuffer[i], ExtSpanBBuffer[i]) ||
close[i] < ExtKijunBuffer[i]);
if (longCondition) {
BuySignalBuffer[i] = low[i] - 10 * _Point;
} else {
BuySignalBuffer[i] = EMPTY_VALUE;
}
if (shortCondition) {
SellSignalBuffer[i] = high[i] + 10 * _Point;
} else {
SellSignalBuffer[i] = EMPTY_VALUE;
}
}
}
return rates_total;
}
Explications :
- J'ai ajouté
& au type de tableau pour open, high, low, et close dans la signature de la fonction CalculateHeikinAshi pour indiquer explicitement qu'ils sont passés par référence.
- Les erreurs devraient être corrigées avec ces changements. Assurez-vous que toutes les références aux tableaux de prix utilisent les paramètres passés dans
OnCalculate.
Ce correctif devrait résoudre les erreurs que vous avez rencontrées en lien avec le passage incorrect des tableaux en MQL5. N'hésitez pas à tester et ajuster en fonction de vos besoins spécifiques et de votre environnement de codage.