//+------------------------------------------------------------------+
//| Test_IndicatorRelease.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//--- input parameters
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;
//--- vamos a almacenar el manejador del indicador
int MA_handle;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- creamos el manejador del indicador
MA_handle=iMA(Symbol(),0,MA_Period,MA_shift,MA_smooth,price);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- si el valor de la variable global todavía no está indicado
if(GlobalVariableCheck("MA_value")==0)
{
//--- array dinámico para los valores del indicador
double v[];
//--- obtenemos el valor del indicador en dos últimas barras
if(CopyBuffer(MA_handle,0,0,2,v)==2 && v[1]!=EMPTY_VALUE)
{
//--- recordamos en la variable global valor en la penúltima barra
if(GlobalVariableSet("MA_value",v[1]))
{
//--- liberamos el manejador del indicador
if(!IndicatorRelease(MA_handle))
Print("IndicatorRelease() failed. Error ",GetLastError());
}
}
}
//---
}
|