//+------------------------------------------------------------------+ //| ColorDM_361.mq5 | //| Copyright 2002, Finware.ru Ltd. | //| http://www.finware.ru/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2002, Finware.ru Ltd." #property link "http://www.finware.ru/" //---- Indicator version #property version "1.00" //--- drawing the indicator in a separate window #property indicator_separate_window //---- number of indicator buffers #property indicator_buffers 2 //---- only one plot is used #property indicator_plots 1 //+-----------------------------------+ //| Parameters of indicator drawing | //+-----------------------------------+ //---- drawing the indicator as multi-colored symbols #property indicator_type1 DRAW_COLOR_ARROW //---- the following colors are used in a three-color line #property indicator_color1 clrMagenta,clrGray,clrTeal //--- indicator line width is 2 #property indicator_width1 2 //--- displaying the indicator label #property indicator_label1 "ColorDM_361" //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ enum Applied_price_ // type of constant { PRICE_CLOSE_ = 1, // Close PRICE_OPEN_, // Open PRICE_HIGH_, // High PRICE_LOW_, // Low PRICE_MEDIAN_, // Median Price (HL/2) PRICE_TYPICAL_, // Typical Price (HLC/3) PRICE_WEIGHTED_, // Weighted Close (HLCC/4) PRICE_SIMPL_, // Simple Price (OC/2) PRICE_QUARTER_, // Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, // TrendFollow_1 Price PRICE_TRENDFOLLOW1_, // TrendFollow_2 Price PRICE_DEMARK_ // Demark Price }; //+-----------------------------------+ //| Indicator input parameters | //+-----------------------------------+ input Applied_price_ IPC=PRICE_CLOSE; // Applied price input int Shift=0; // Horizontal shift of the indicator in bars input int PriceShift=0; // Vertical shift of the indicator in points //+-----------------------------------+ //--- declaration of dynamic arrays that //--- will be used as indicator buffers double InBuffer[]; double ColorInBuffer[]; //--- declaration of the integer variables for the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- initialization of variables of the start of data calculation min_rates_total=65; //--- Set dynamic array as an indicator buffer SetIndexBuffer(0,InBuffer,INDICATOR_DATA); //--- shifting the indicator 1 horizontally PlotIndexSetInteger(0,PLOT_SHIFT,Shift); //--- shifting the start of drawing of the indicator 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,0.0); //--- set dynamic array as a color index buffer SetIndexBuffer(1,ColorInBuffer,INDICATOR_COLOR_INDEX); //--- Creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,"ColorDM_361"); //--- Determining the accuracy of displaying the indicator values IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //--- initialization end } //+------------------------------------------------------------------+ //| 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[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- checking if the number of bars is 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 //--- main indicator calculation loop for(bar=first; barrates_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 //--- main loop of the signal line coloring for(bar=first; barInBuffer[bar]) clr=0; ColorInBuffer[bar]=clr; } //--- return(rates_total); } //+------------------------------------------------------------------+ //| Getting values of a price time series | //+------------------------------------------------------------------+ double PriceSeries(uint applied_price, // Price constant uint bar, // Index of shift relative to the current bar for a specified number of periods back or forward). const double &Open[], const double &Low[], const double &High[], const double &Close[]) { //--- switch(applied_price) { //--- price constants from the ENUM_APPLIED_PRICE enumeration case PRICE_CLOSE: return(Close[bar]); case PRICE_OPEN: return(Open [bar]); case PRICE_HIGH: return(High [bar]); case PRICE_LOW: return(Low[bar]); case PRICE_MEDIAN: return((High[bar]+Low[bar])/2.0); case PRICE_TYPICAL: return((Close[bar]+High[bar]+Low[bar])/3.0); case PRICE_WEIGHTED: return((2*Close[bar]+High[bar]+Low[bar])/4.0); //--- case 8: return((Open[bar] + Close[bar])/2.0); case 9: return((Open[bar] + Close[bar] + High[bar] + Low[bar])/4.0); //--- case 10: { if(Close[bar]>Open[bar])return(High[bar]); else { if(Close[bar]Open[bar])return((High[bar]+Close[bar])/2.0); else { if(Close[bar]Open[bar]) res=(res+High[bar])/2; if(Close[bar]==Open[bar]) res=(res+Close[bar])/2; return(((res-Low[bar])+(res-High[bar]))/2); } //--- default: return(Close[bar]); } //--- } //+------------------------------------------------------------------+