//============================================================================================= MQL5 === // LibreFEI v1.005 (MQL5) // Главный модуль обработки событий // Librecoin(c)2014-2017 //============================================================================================= MQL5 === // REVIEWS //------------------------------------------------------------------------------------------------------ // Fourier Extrapolator Adaptive - экстраполятор фурье творческая переработка. //============================================================================================= MQL5 === // IDEAS //------------------------------------------------------------------------------------------------------ // 12.12.2017 Идея: расчетную часть выполнить с использованием OpenCL //============================================================================================= MQL5 === // PROPERTY //------------------------------------------------------------------------------------------------------ #define ver "1.005" #property copyright "Librecoin(c)2014-2017, gpwr(c)2008-2010" #property link "https://www.mql5.com/ru/users/kirillovyv" #property strict #property description "**************************************************" #property description " Indicator LibreFEI v"+ver+" Lite (MQL5)" #property description " Extrapolator by trigonometric (multitone) model" #property description " From Russia with Love! :-)" #property description " https://www.mql5.com/ru/users/kirillovyv" #property description " Based from: gpwr(c)2008-2010, neoclassic(c)2009" #property description "**************************************************" #property version ver const string vers = "LibreFEI v"+ver; //Version //----- indicator property #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 2 //============================================================================================= MQL5 === // INTERFACE //------------------------------------------------------------------------------------------------------ input int Npast = 650; //Past bars, to which trigonometric series is fitted input int Nfut = 20; //Predicted future bars input int Nharm = 9; //Min Narmonics in model input double FreqTOL = 0.0000001; //Tolerance of frequency calculations input int StartBar = 15; //С какого бара начинаем input int MSTimerSet = 500; //Установка таймера xxx миллисекунд input int nTickDelay = 5; //Интервал пропуска тиков для тестирования input ulong IterLimit = 60; //Iteration limit для Freq input bool CommentOn = false; //Вывод комментариев на экран input bool PrintOn = false; //Печать комментариев в журнал //============================================================================================= MQL5 === // Global variable definition //------------------------------------------------------------------------------------------------------ bool TimeInterrupt; int nTickSumm; //----- indicator buffers double pv[]; //0 Отображаемый буфер истории PAST double fv[]; //1 Отображаемый буфер прогноза FUTURE double pc[]; //2 Расчетный буфер истории PAST double fc[]; //3 Расчетныйбуфер прогноза FUTURE //----- Буфер расчетного параметра double xc[]; //Буфер расчетного параметра // //datetime xTime = D'2017.09.13 21:57:59';//Время начала вывода протоколов //datetime xTimeStop = D'2017.09.13 23:55:55';//Время окончания вывода протоколов // //============================================================================================= MQL5 === // OnInit() - Custom indicator initialization function //------------------------------------------------------------------------------------------------------ int OnInit() { //----- initialize global variables TimeInterrupt=true; nTickSumm=0; //----- indicator parametrs IndicatorSetInteger(INDICATOR_DIGITS,_Digits); IndicatorSetString(INDICATOR_SHORTNAME,"LibreFEI"); //----- indicator buffers mapping //Прошлое - буфер отображения PAST ArraySetAsSeries(pv,true); ArrayInitialize(pv,EMPTY_VALUE); SetIndexBuffer(0,pv,INDICATOR_DATA); PlotIndexSetString(0,PLOT_LABEL,"Past"); PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID); PlotIndexSetInteger(0,PLOT_LINE_WIDTH,2); PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrBlue); //Будущее - буфер отображения FUTURE ArraySetAsSeries(fv,true); ArrayInitialize(fv,EMPTY_VALUE); SetIndexBuffer(1,fv,INDICATOR_DATA); PlotIndexSetString(1,PLOT_LABEL,"Future"); PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_SOLID); PlotIndexSetInteger(1,PLOT_LINE_WIDTH,2); PlotIndexSetInteger(1,PLOT_LINE_COLOR,clrRed); PlotIndexSetInteger(1,PLOT_SHIFT,Nfut); //future data vector i=0..Nfut; Nfut corresponds to bar=StartBar //Прошлое - буфер расчета PAST ArraySetAsSeries(pc,true); ArrayInitialize(pc,EMPTY_VALUE); SetIndexBuffer(2,pc,INDICATOR_CALCULATIONS); //Будущее - буфер расчета FUTURE ArraySetAsSeries(fc,true);//false ArrayInitialize(fc,EMPTY_VALUE); SetIndexBuffer(3,fc,INDICATOR_CALCULATIONS); //Буфер расчетного параметра ArrayResize(xc,Npast+1); //----- Настройки таймера и глобальных счетчиков {if(!MQLInfoInteger(MQL_TESTER))//Не тестирование { int err=-1; int count=50; {while((err!=0)&&(count>0)) { ResetLastError(); EventSetMillisecondTimer(MSTimerSet); //Установка таймера XXX миллисекунд err=GetLastError(); {if(err!=0) { Sleep(50); }}//if(err!=0) count--; }}//while((err!=0)&&(count>0)) }}//if(!MQLInfoInteger(MQL_TESTER)) //----- return(INIT_SUCCEEDED); }//OnInit() // //============================================================================================= MQL5 === // OnDeinit() - Custom indicator iteration function | //------------------------------------------------------------------------------------------------------ void OnDeinit(const int reason){ Comment(""); return; }//OnDeinit() // //============================================================================================= MQL5 === // OnTimer() //------------------------------------------------------------------------------------------------------ void OnTimer(){ TimeInterrupt=true; nTickSumm=0; }//OnTimer() // //============================================================================================= MQL5 === // OnCalculate() - 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[]) { //----- Check for insufficient data {if(rates_totalFreqTOL)&&(IterCountFreqTOL) w=MathArccos(beta/2.0); TrigFit(x,ipc,n,w,m,c,s); }//Freq() // //============================================================================================= MQL5 === // TrigFit() - Least-squares fitting of trigonometric series //------------------------------------------------------------------------------------------------------ void TrigFit(double& x[],double& ipc[],int n,double w,double& m,double& c,double& s) { double Sc =0.0; double Ss =0.0; double Scc=0.0; double Sss=0.0; double Scs=0.0; double Sx =0.0; double Sxc=0.0; double Sxs=0.0; {for(int i=0;i