//+--------------------------------------------------------------------------------------+ //| Fourier_Extrapolator_of_Price_orig.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 //===================================== INPUTS =========================================== input int Npast =300; // # of past bars, to which trigonometric series is fitted input int Nfut =50; // # of predicted future bars input int Nharm =20; // # of harmonics in model input double FreqTOL =0.00001; // Tolerance of frequency calculations input int schift =50; // Global variables int N; // Indicator buffers double ym[],xm[]; // Custom indicator initialization function ---------------------------------------------+ void OnInit() { // Initialize global variables N=MathMax(Npast,Nfut+1); // Map indicator buffers 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-schift); PlotIndexSetInteger(1,PLOT_SHIFT,-schift); } //====================================== MAIN ============================================ 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