//+------------------------------------------------------------------+ //| kiosotto_lines_ma.mq4 | //| Copyright 2016, Kilian19@FF, remix by Scriptong | //| http://advancetools.net | //+------------------------------------------------------------------+ #property copyright "Kilian19@FF, remix by Scriptong" #property link "http://advancetools.net" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 clrRed #property indicator_color2 clrGreen #property indicator_color3 clrDodgerBlue #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 2 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_YESNO { NO, // No / Нет YES // Yes / Да }; // Input parameters of indicator input int i_dev_period = 5; // RSI period / Период RSI input int i_maPeriod = 13; // MA period / Период МА input ENUM_MA_METHOD i_maMethod = MODE_EMA; // MA calculation method / Метод расчета МА input double i_maRatio = 1.0; // MA ratio / Коэффициент умножения МА input ENUM_YESNO i_useAlert = YES; // Use alert? / Использовать оповещения? input int i_indBarsCount = 10000; // The number of bars to display / Количество баров отображения // The indicator's buffers double g_sellBuffer[]; double g_buyBuffer[]; double g_maBuffer[]; // Other global variables of indicator bool g_activate; // Sign of successful initialization of indicator double g_maSourceValues[]; //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Custom indicator initialization function | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ int OnInit() { g_activate=false; if(!IsTuningParametersCorrect()) return INIT_FAILED; iTime(NULL,PERIOD_D1,0); if(!BuffersBind()) return (INIT_FAILED); g_activate=true; return INIT_SUCCEEDED; } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Checking the correctness of input parameters | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ bool IsTuningParametersCorrect() { string name=WindowExpertName(); bool isRussianLang=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian"); if(i_dev_period<1) { Alert(name,(isRussianLang)? ": период RSI должен быть 1 и более. Индикатор отключен." : ": the RSI period must be 1 or more. The indicator is turned off."); return false; } if(i_maPeriod<1) { Alert(name,(isRussianLang)? ": период MA должен быть 1 и более. Индикатор отключен." : ": the MA period must be 1 or more. The indicator is turned off."); return false; } if(i_maRatio<=0.0) { Alert(name,(isRussianLang)? ": коэффициент умножения MA должен быть положительным. Индикатор отключен." : ": the MA ratio must have a positive value. The indicator is turned off."); return false; } if(ArrayResize(g_maSourceValues,i_maPeriod)<0) { Alert(name,(isRussianLang)? ": не удалось распределить память для массива исходных значений MA. Индикатор отключен." : ": unable to allocate the memory for array of source MA values. The indicator is turned off."); return false; } return true; } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Determination of bar index which needed to recalculate | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ int GetRecalcIndex(int &total,const int ratesTotal,const int prevCalculated) { total=ratesTotal-1; if(i_indBarsCount>0 && i_indBarsCountcurHigh) { curHigh=high; bullPower+=power; } if(low0; i--) { CalculateBuyAndSellBuffers(i,total); CalculateMA(i,total); } DoAlert(); } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Custom indicator iteration function | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 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[]) { if(!g_activate) return prev_calculated; int total; int limit=GetRecalcIndex(total,rates_total,prev_calculated); ShowIndicatorData(limit,total); return rates_total; } //+------------------------------------------------------------------+