//+------------------------------------------------------------------+ //| iBBands_HTF.mq5 | //| Copyright © 2012, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2012, Nikolay Kositsin" #property link "farria@mail.redcom.ru" //--- indicator version number #property version "1.00" //--- drawing the indicator in the main window #property indicator_chart_window //--- number of indicator buffers 3 #property indicator_buffers 3 //--- only three plots are used #property indicator_plots 3 //+----------------------------------------------+ //| Declaration of constants | //+----------------------------------------------+ #define RESET 0 // The constant for getting the command for the indicator recalculation back to the terminal #define INDICATOR_NAME "iBBands" // The constant for the indicator name //+----------------------------------------------+ //| Indicator drawing parameters | //+----------------------------------------------+ //--- drawing the indicator 1 as a zigzag #property indicator_type1 DRAW_SECTION //--- the following colors are used for the indicator #property indicator_color1 clrLightSeaGreen //--- indicator 1 line width is equal to 2 #property indicator_width1 2 //--- drawing the indicator 2 as a zigzag #property indicator_type2 DRAW_SECTION //--- the following colors are used for the indicator #property indicator_color2 clrBlue //--- indicator 2 line width is equal to 2 #property indicator_width2 2 //--- drawing the indicator 3 as a zigzag #property indicator_type3 DRAW_SECTION //--- the following colors are used for the indicator #property indicator_color3 clrMagenta //--- indicator 3 line width is equal to 2 #property indicator_width3 2 //+-------------------------------------+ //| Indicator input parameters | //+-------------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4; // Chart period input uint MA_Period=15; // Period of averaging input ENUM_APPLIED_PRICE Applied_price=PRICE_CLOSE; // Price constant input double Deviation=2.0; // Deviation 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 further will be used as indicator buffers double MdIndBuffer[],UpIndBuffer[],DnIndBuffer[]; //--- declaration of a variable for storing the indicator initialization result bool Init; double dPriceShift; //--- declaration of strings string Symbol_,Word; //--- declaration of integer variables for the indicators handles int Ind_Handle; //--- declaration of the integer variables for the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Init=true; //--- checking correctness of the chart periods if(TimeFramerates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator { limit=rates_total-min_rates_total-2; // starting index for calculation of all bars LastCountBar=limit; } else limit=int(LastCountBar)+rates_total-prev_calculated; // starting index for calculation of new bars //--- indexing elements in arrays as timeseries ArraySetAsSeries(time,true); //--- main cycle of calculation of the indicator for(bar=limit; bar>=0 && !IsStopped(); bar--) { //--- zero out the contents of the indicator buffers for calculation UpIndBuffer[bar+1]=0.0; MdIndBuffer[bar+1]=0.0; DnIndBuffer[bar+1]=0.0; //--- copy newly appeared data in the iTime array if(CopyTime(Symbol_,TimeFrame,time[bar],1,iTime)<=0) return(RESET); if(time[bar]>=iTime[0] && time[bar+1]