//+------------------------------------------------------------------+ //| Spectrometr_Separate.mq5 | ///| Copyright © 2009, Yuriy Tokman | //| yuriytokman@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Yuriy Tokman" #property link "yuriytokman@gmail.com" //---- indicator version number #property version "1.00" //---- drawing indicator in a separate window #property indicator_separate_window //---- number of indicator buffers #property indicator_buffers 8 //---- only eight graphical plots are used #property indicator_plots 8 //+-----------------------------------+ //| Indicators drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE #property indicator_type4 DRAW_LINE #property indicator_type5 DRAW_LINE #property indicator_type6 DRAW_LINE #property indicator_type7 DRAW_LINE #property indicator_type8 DRAW_LINE //---- the following colors are used for the indicators #property indicator_color1 clrRed #property indicator_color2 clrOrange #property indicator_color3 clrYellow #property indicator_color4 clrLime #property indicator_color5 clrBlue #property indicator_color6 clrDodgerBlue #property indicator_color7 clrDarkViolet #property indicator_color8 clrDimGray //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID #property indicator_style2 STYLE_SOLID #property indicator_style3 STYLE_SOLID #property indicator_style4 STYLE_SOLID #property indicator_style5 STYLE_SOLID #property indicator_style6 STYLE_SOLID #property indicator_style7 STYLE_SOLID #property indicator_style8 STYLE_SOLID //---- displaying the indicator label #property indicator_label1 "Wave 1"; #property indicator_label2 "Wave 2"; #property indicator_label3 "Wave 3"; #property indicator_label4 "Wave 4"; #property indicator_label5 "Wave 5"; #property indicator_label6 "Wave 6"; #property indicator_label7 "Wave 7"; #property indicator_label8 "Wave 8"; //+-----------------------------------+ //| Declaration of constants | //+-----------------------------------+ #define RESET 0 // The constant for returning the indicator recalculation command to the terminal //+-----------------------------------+ //| INDICATOR INPUT PARAMETERS | //+-----------------------------------+ input ENUM_TIMEFRAMES iPeriod=PERIOD_H4; // indicator time frame input int iStartFrom=0; input string AddToObjName="1"; input color HandlerColor=clrGray; input color TextColor=clrBlueViolet; //+-----------------------------------+ //---- Declaration of integer variables of data starting point int min_rates_total; //---- declaration of dynamic arrays that will further be // used as indicator buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; double ExtMapBuffer5[]; double ExtMapBuffer6[]; double ExtMapBuffer7[]; double ExtMapBuffer8[]; //---- int LastLeftBar; int LastRightBar; //---- string ObjNPref; string ShortName; //---- int Wind; int nPeriod; int nStartFrom; double A[],B[],R[],F[]; //+------------------------------------------------------------------+ //| One indicator initialization | //+------------------------------------------------------------------+ void IndicatorInit(int Number,double &IndArray[],int DrawBegin,double EmptyValue,int Shift) { //---- setting dynamic arrays as indicator buffers SetIndexBuffer(Number,IndArray,INDICATOR_DATA); //---- moving the indicator 1 horizontally PlotIndexSetInteger(Number,PLOT_SHIFT,Shift); //---- performing the shift of beginning of indicator drawing PlotIndexSetInteger(Number,PLOT_DRAW_BEGIN,DrawBegin); //---- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(Number,PLOT_EMPTY_VALUE,EmptyValue); //---- indexing buffer elements as time series ArraySetAsSeries(IndArray,true); //---- } //+------------------------------------------------------------------+ //| shifting the starting point of the indicator drawing | //+------------------------------------------------------------------+ void IndicatorsDrawBegin(int DrawBegin) { //---- performing the shift of beginning of indicator drawing PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,DrawBegin); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,DrawBegin); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,DrawBegin); PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,DrawBegin); PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,DrawBegin); PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,DrawBegin); PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,DrawBegin); PlotIndexSetInteger(7,PLOT_DRAW_BEGIN,DrawBegin); //---- } //+------------------------------------------------------------------+ //| Spectrometr_Separate indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- initializations of variable for indicator short name ShortName="Spectrometr"+"_"+AddToObjName; //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,ShortName); //---- Initialization of variables ObjNPref=ShortName+"_"; //---- Initialization of variables of the start of data calculation nStartFrom=iStartFrom; min_rates_total=nStartFrom+nPeriod-1; Wind=ChartWindowFind(0,ShortName); nPeriod=PeriodSeconds(iPeriod)/60; //---- initialize indicator buffers IndicatorInit(0,ExtMapBuffer1,min_rates_total,EMPTY_VALUE,0); IndicatorInit(1,ExtMapBuffer2,min_rates_total,EMPTY_VALUE,0); IndicatorInit(2,ExtMapBuffer3,min_rates_total,EMPTY_VALUE,0); IndicatorInit(3,ExtMapBuffer4,min_rates_total,EMPTY_VALUE,0); IndicatorInit(4,ExtMapBuffer5,min_rates_total,EMPTY_VALUE,0); IndicatorInit(5,ExtMapBuffer6,min_rates_total,EMPTY_VALUE,0); IndicatorInit(6,ExtMapBuffer7,min_rates_total,EMPTY_VALUE,0); IndicatorInit(7,ExtMapBuffer8,min_rates_total,EMPTY_VALUE,0); //--- determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //---- end of initialization } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //---- ObjDeleteByPrefix(ObjNPref); //---- } //+------------------------------------------------------------------+ //| Spectrometr_Separate iteration function | //+------------------------------------------------------------------+ int OnCalculate( const int rates_total, // amount of history in bars at the current tick const int prev_calculated,// amount of history in bars at the previous tick const int begin, // number of beginning of reliable counting of bars const double &price[] // price array for calculation of the indicator ) { //---- checking the number of bars to be enough for calculation if(rates_total=0; i--) if(StringFind(ObjectName(0,i,Wind,-1),aPrefix,0)==0) ObjectDelete(0,ObjectName(0,i,Wind,-1)); //---- } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double fMyArcTan(double aS,double aC) { //---- if(!aS) return(0); if(!aC) { if(aS>0) return(MathArctan(1)*2); else if(aS<0) return(MathArctan(1)*6); } else { if(aS>0) { if(aC>0) return(MathArctan(aS/aC)); else return(MathArctan(aS/aC)+MathArctan(1)*4); } else { if(aC>0) return(MathArctan(aS/aC)+MathArctan(1)*8); else return(MathArctan(aS/aC)+MathArctan(1)*4); } } //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void fFurie(double &aArr[],double &aA[],double &aB[],double &aR[],double &aF[]) { //---- int tN=ArraySize(aArr); int tM=MathMax(tN/2,1); ArrayResize(aA,tM); ArrayResize(aB,tM); ArrayResize(aR,tM); ArrayResize(aF,tM); for(int ti=1;ti