//--- parametri d'ingresso input int InpPeriod = 10; // Periodo di calcolo media mobile input ENUM_MA_METHOD InpMethod = MODE_SMA; // Metodo di calcolo media mobile input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // Prezzo per il calcolo della media mobile //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- se il periodo della media mobile è impostato su un valore inferiore a 1, viene utilizzato il valore predefinito (10) int period=(InpPeriod<1 ? 10 : InpPeriod); //--- creare il gestore dell'indicatore Media Mobile int handle=iMA(Symbol(),Period(),period,0,InpMethod,InpPrice); if(handle==INVALID_HANDLE) { Print("Failed to create the Moving Average indicator handle. Error ",GetLastError()); return; } //--- ottenere il prezzo Bid attuale double bid=0; ResetLastError(); if(!SymbolInfoDouble(Symbol(),SYMBOL_BID,bid)) { Print("Failed to get Bid price. Error ",GetLastError()); return; } //--- ottenere il valore media mobile sulla barra corrente double array[1]; int copied=CopyBuffer(handle,0,0,1,array); if(copied!=1) { Print("Failed to get Moving Average data. Error ",GetLastError()); return; } //-- ottenere il prezzo più alto dei due (prezzo Bid e valore Media Mobile) e visualizzare i dati risultanti nel journal double max_price=MathMax(bid,array[0]); PrintFormat("Bid: %.*f, Moving Average: %.*f, highest price of the two: %.*f",_Digits,bid,_Digits,array[0],_Digits,max_price); PrintFormat("Bid price %s moving average",(bid>array[0] ? "higher" : bid<array[0] ? "lower" : "equal to")); } |