//+--------------------------------------------------------------------------------+
//| 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"
//--- parametri di input
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;
//--- salverà l'handle indicatore
int MA_handle=INVALID_HANDLE;
//+--------------------------------------------------------------------------------+
//| Funzione di inizializzazione dell' Expert |
//+--------------------------------------------------------------------------------+
int OnInit()
{
//--- crea l'handle indicatore
MA_handle=iMA(Symbol(),0,MA_Period,MA_shift,MA_smooth,PRICE_CLOSE);
//--- elimina la variabile globale
if(GlobalVariableCheck("MA_value"))
GlobalVariableDel("MA_value");
//---
return(INIT_SUCCEEDED);
}
//+--------------------------------------------------------------------------------+
//| Funzione tick dell'Expert |
//+--------------------------------------------------------------------------------+
void OnTick()
{
//--- se il valore della variabile globale non esiste
if(!GlobalVariableCheck("MA_value"))
{
//--- ottiene il valore dell'indicatore nelle ultime due barre
if(MA_handle!=INVALID_HANDLE)
{
//--- array dinamico per i valori degli indicatori
double values[];
if(CopyBuffer(MA_handle,0,0,2,values)==2 && values[0]!=EMPTY_VALUE)
{
//--- ricorda il valore della variabile globale sulla penultima barra
if(GlobalVariableSet("MA_value",values[0]))
{
//--- libera l'handle dell'indicatore
if(!IndicatorRelease(MA_handle))
Print("IndicatorRelease() fallito. Error ",GetLastError());
else MA_handle=INVALID_HANDLE;
}
else
Print("GlobalVariableSet fallito. Error ",GetLastError());
}
}
}
//---
}
|