//+------------------------------------------------------------------+ //| MultiCharts.mq5 | //| Copyright 2012, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" //--- include the ChartObjectSubChart library #include //--- size of OBJ_Chart #define chart_width 318 #define chart_height 288 //--- start point for charts table drawing #define start_x 0 #define start_y 0 #property script_show_inputs //--- input parameters input datetime start=D'2012.11.26 00:00:00'; input datetime stop=D'2012.12.01 00:00:00'; //+------------------------------------------------------------------+ //| Class for short and long lines levels | //+------------------------------------------------------------------+ class CLines { public: string m_name; // name of currency pair double m_short; // level value for the "short" line double m_long; // level value for the "long" line //--- constructor, destructor CLines(void) { }; ~CLines(void) { }; }; //+------------------------------------------------------------------+ //| Class for draw a chart with rectangul area | //| and short & long lines | //+------------------------------------------------------------------+ class CSubChartExtended: public CChartObjectSubChart { private: long m_subchartID; // subchart ID static bool m_lines_loaded; // flag of lines loading static CLines m_linesData[]; // array for the lines public: CSubChartExtended(void); ~CSubChartExtended(void); //--- subchart create bool CreateSubChart(const long chart_id,const string name,const int window, const int X,const int Y,const int sizeX,const int sizeY); //--- changing of display settings void ChangeSettings(void); void SubChartNavigate(void); //--- drawing of graphical objects void DrawRectangle(void); void DrawLines(void); //--- redraw void ReDraw(void); //--- loading lines data bool LoadLines(const string path); virtual bool Load(const int file_handle); //--- calculate the location of the point relative to the interval void SetChartMaxMin(const double short_value,const double long_value); int InRange(const double top,const double bottom,const double pos,const double indent); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CSubChartExtended::CSubChartExtended(void) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CSubChartExtended::~CSubChartExtended(void) { } //+------------------------------------------------------------------+ //| Subchart create | //+------------------------------------------------------------------+ bool CSubChartExtended::CreateSubChart(const long chart_id,const string name, const int window,const int X,const int Y, const int sizeX,const int sizeY) { //--- creating of chart object if(!Create(0,name,0,X,Y,sizeX,sizeY)) return(false); //--- get subchart ID m_subchartID=ObjectGetInteger(0,name,OBJPROP_CHART_ID); //--- successful creating return(true); } //+------------------------------------------------------------------+ //| Changing of display settings | //+------------------------------------------------------------------+ void CSubChartExtended::ChangeSettings(void) { //--- disable chart autoscroll ChartSetInteger(m_subchartID,CHART_AUTOSCROLL,false); //--- set the background color if(!ChartSetInteger(m_subchartID,CHART_COLOR_BACKGROUND,C'245,255,250')) Print("Failed to set the background color for the chart. Code ",GetLastError()); ResetLastError(); //--- color of axes, scale and OHLC line ChartSetInteger(m_subchartID,CHART_COLOR_FOREGROUND,clrBlack); //--- disable Ask, Bid and Last lines ChartSetInteger(m_subchartID,CHART_SHOW_BID_LINE,false); ChartSetInteger(m_subchartID,CHART_SHOW_BID_LINE,false); ChartSetInteger(m_subchartID,CHART_SHOW_BID_LINE,false); //--- disable OHLC ChartSetInteger(m_subchartID,CHART_SHOW_OHLC,false); //--- use candles ChartSetInteger(m_subchartID,CHART_MODE,CHART_CANDLES); //--- bullish candle color ChartSetInteger(m_subchartID,CHART_COLOR_CANDLE_BULL,clrWhite); //--- bullish bur color ChartSetInteger(m_subchartID,CHART_COLOR_CHART_UP,clrBlack); //--- bearish candle color ChartSetInteger(m_subchartID,CHART_COLOR_CANDLE_BEAR,clrBlack); //--- bearish bar color ChartSetInteger(m_subchartID,CHART_COLOR_CHART_DOWN,clrBlack); //--- line color ChartSetInteger(m_subchartID,CHART_COLOR_CHART_LINE,clrBlack); //--- disable the grid if(!ChartSetInteger(m_subchartID,CHART_SHOW_GRID,0)) Print("Failed to set property \"Grid \"\ for the chart. Code ",GetLastError()); ResetLastError(); //--- disable the shift of the right edge of the chart ChartSetInteger(m_subchartID,CHART_SHIFT,0); //--- set the shift equal to 30% of the chart width ChartSetDouble(m_subchartID,CHART_SHIFT_SIZE,10); //--- disable the trade levels display if(!ChartSetInteger(m_subchartID,CHART_SHOW_TRADE_LEVELS,0)) Print("Failed to set property \"Grid \"\ for the chart. Code ",GetLastError()); ResetLastError(); } //+------------------------------------------------------------------+ //| Chart shift to the left to the desired dates | //+------------------------------------------------------------------+ void CSubChartExtended::SubChartNavigate(void) { //--- chart shift ChartNavigate(m_subchartID,CHART_END,GetShift(Name(),PERIOD_H4,m_subchartID)); } //+------------------------------------------------------------------+ //| Draw a rectangle on the subchart | //+------------------------------------------------------------------+ void CSubChartExtended::DrawRectangle(void) { //--- create rectangle by start-stop dates if(ObjectCreate(m_subchartID,"rect",OBJ_RECTANGLE,0,start,200,stop,0.01)) { //--- fill rectangle ObjectSetInteger(m_subchartID,"rect",OBJPROP_FILL,true); //--- rectangle color ObjectSetInteger(m_subchartID,"rect",OBJPROP_COLOR,White); } else { //--- error PrintFormat("Failed to create a rectangle, error code %d",GetLastError()); ResetLastError(); } } //+------------------------------------------------------------------+ //| Draw short and long lines on the subchart | //+------------------------------------------------------------------+ void CSubChartExtended::DrawLines(void) { //--- check the flag of data loading if(m_lines_loaded) { //--- create variables double short_value=0; double long_value=0; int size=ArraySize(m_linesData); //--- find lines data by name of currency pair for(int j=0;j=top-indent) return(1); //--- if below, return -1 if(pos<=bottom+indent) return(-1); //--- inside return(0); } //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- number of currency pairs int symbols; //--- name of currency pairs string name; //--- variables of row and column numbers for the chart drawing int col; int row; //--- get the number of currency pairs symbols=SymbolsTotal(true); //--- subchart object CSubChartExtended SubChart[]; ArrayResize(SubChart,symbols); //--- loading lines data if(SubChart[0].LoadLines("linesdata.txt")) Print("Data successfully loaded"); else Print("Failed to load data: ",GetLastError()); //--- loop over all pairs for(int i=0;i=0;j--) if(DATA_TIME[j]==start) index=j; //--- get the shift, 2 - indent for the rectangle shift=-count+index+visible_bars-2; } //--- return shift return(shift); } //+------------------------------------------------------------------+