//+--------------------------------------------------------------------------------------+ //| Fourier_Extrapolator_of_Price.mq5 | //| Copyright 2010, gpwr | //+--------------------------------------------------------------------------------------+ #property copyright "gpwr" #property version "1.00" #property description "Extrapolation of open prices by trigonometric (multitone) model" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 //--- future model outputs #property indicator_label1 "Modeled future" #property indicator_type1 DRAW_LINE #property indicator_color1 Red #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- past model outputs #property indicator_label2 "Modeled past" #property indicator_type2 DRAW_LINE #property indicator_color2 Blue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- global constants #define pi 3.141592653589793238462643383279502884197169399375105820974944592 //--- indicator inputs input int Npast =300; // Past bars, to which trigonometric series is fitted input int Nfut =50; // Predicted future bars input int Nharm =20; // Narmonics in model input double FreqTOL =0.00001; // Tolerance of frequency calculations //--- global variables int N; //--- indicator buffers double ym[],xm[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- initialize global variables N=MathMax(Npast,Nfut+1); //--- indicator buffers mapping ArraySetAsSeries(xm,true); ArraySetAsSeries(ym,true); SetIndexBuffer(0,ym,INDICATOR_DATA); SetIndexBuffer(1,xm,INDICATOR_DATA); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); IndicatorSetString(INDICATOR_SHORTNAME,"Fourier("+string(Npast)+")"); PlotIndexSetInteger(0,PLOT_SHIFT,Nfut); } //+------------------------------------------------------------------+ //| 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) { alpha=beta; z[1]=x[1]-xm[1]+alpha*z[0]; double num=z[0]*z[1]; double den=z[0]*z[0]; for(int i=2;i