//+------------------------------------------------------------------+ //| WidnersOscilator.mq5 | //| Copyright © 2004, http://www.expert-mt4.nm.ru | //| http://www.expert-mt4.nm.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, http://www.expert-mt4.nm.ru" #property link "http://www.expert-mt4.nm.ru" //---- Indicator version number #property version "1.00" //---- drawing indicator in a separate window #property indicator_separate_window //----two buffers are used for calculating and drawing the indicator #property indicator_buffers 2 //---- two plots are used #property indicator_plots 2 //+----------------------------------------------+ //| WSO drawing parameters | //+----------------------------------------------+ //---- drawing indicator 1 as a line #property indicator_type1 DRAW_LINE //---- red color is used as the color of the bearish indicator line #property indicator_color1 clrRed //---- the line of the indicator 1 is a continuous curve #property indicator_style1 STYLE_SOLID //---- indicator 1 line width is equal to 1 #property indicator_width1 1 //---- display of the bearish label of the indicator line #property indicator_label1 "WSO" //+----------------------------------------------+ //| WRO drawing parameters | //+----------------------------------------------+ //---- dawing the indicator 2 as a line #property indicator_type2 DRAW_LINE //---- blue color is used for the indicator bullish line #property indicator_color2 clrBlue //---- the indicator 2 line is a continuous curve #property indicator_style2 STYLE_SOLID //---- indicator 2 line width is equal to 1 #property indicator_width2 1 //---- display of the bullish label of the indicator line #property indicator_label2 "WRO" //+----------------------------------------------+ //| Parameters of displaying horizontal levels | //+----------------------------------------------+ #property indicator_level1 50.0 #property indicator_levelcolor clrGray #property indicator_levelstyle STYLE_DASHDOTDOT //+-----------------------------------+ //| Declaration of constants | //+-----------------------------------+ #define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input uint nPeriod=9; input int Shift=0; // horizontal shift of the indicator in bars //+----------------------------------------------+ //---- declaration of dynamic arrays that //---- will be used as indicator buffers double WSOBuffer[]; double WROBuffer[]; //---- declaration of the integer variables for the start of data calculation int min_rates_total,per; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=int(nPeriod); per=int((nPeriod-1)/2); //---- Set dynamic array as an indicator buffer SetIndexBuffer(0,WSOBuffer,INDICATOR_DATA); //---- shifting the indicator 1 horizontally by Shift PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //---- shifting the starting point of the indicator 1 drawing by min_rates_total PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //---- Setting the indicator values that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- Set dynamic array as an indicator buffer SetIndexBuffer(1,WROBuffer,INDICATOR_DATA); //---- shifting the indicator 2 horizontally by Shift PlotIndexSetInteger(1,PLOT_SHIFT,Shift); //---- shifting the starting point of the indicator 2 drawing by min_rates_total PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); //---- Setting the indicator values that won't be visible on a chart PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); //---- Initializations of variable for indicator short name string shortname; StringConcatenate(shortname,"WidnersOscilator(",nPeriod,", ",Shift,")"); //--- Creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- Determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,0); //---- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated,// amount of history in bars at the previous tick const datetime &time[], const double &open[], const double& high[], // price array of price maximums for the indicator calculation const double& low[], // price array of minimums of price for the indicator calculation const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---- checking the number of bars to be enough for the calculation if(rates_totalrates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator first=min_rates_total; // starting index for calculation of all bars else first=prev_calculated-1; // starting number for calculation of new bars s6=S6; s5=S5; s4=S4; s3=S3; s2=S2; s1=S1; r6=R6; r5=R5; r4=R4; r3=R3; r2=R2; r1=R1; //---- The main loop of the indicator calculation for(bar=first; bar