//+------------------------------------------------------------------+
//| Test_IndicatorRelease.mq5 |
//| Copyright 2010, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2010, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//--- paramètres d'entrée
input int MA_Period=15;
input int MA_shift=0;
input ENUM_MA_METHOD MA_smooth=MODE_SMA;
input ENUM_APPLIED_PRICE price=PRICE_CLOSE;
//--- reçevra le handle de l'indicateur
int MA_handle=INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Fonction d'initialisation de l'expert |
//+------------------------------------------------------------------+
int OnInit()
{
//--- crée le handle de l'indicateur
MA_handle=iMA(Symbol(),0,MA_Period,MA_shift,MA_smooth,PRICE_CLOSE);
//--- supprime la variable globale
if(GlobalVariableCheck("MA_value"))
GlobalVariableDel("MA_value");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Fonction de tick de l'Expert |
//+------------------------------------------------------------------+
void OnTick()
{
//--- si la variable globale n'existe pas
if(!GlobalVariableCheck("MA_value"))
{
//--- obtient la valeur de l'indicateur sur les deux dernières barres
if(MA_handle!=INVALID_HANDLE)
{
//--- tableau dynamique pour les valeurs de l'indicateur
double values[];
if(CopyBuffer(MA_handle,0,0,2,values)==2 && values[0]!=EMPTY_VALUE)
{
//--- stocke dans la variable globale la valeur de la dernière barre
if(GlobalVariableSet("MA_value",values[0]))
{
//--- libère le handle de l'indicateur
if(!IndicatorRelease(MA_handle))
Print("Echec de IndicatorRelease(). Erreur ",GetLastError());
else MA_handle=INVALID_HANDLE;
}
else
Print("Echec de GlobalVariableSet. Erreur ",GetLastError());
}
}
}
//---
}
|