//+------------------------------------------------------------------+ //| ID Lite Info MA.mq4 | //| 2015, Dina Paches | //| https://login.mql5.com/ru/users/dipach | //+------------------------------------------------------------------+ #property copyright "2015, Dina Paches" #property link "https://login.mql5.com/ru/users/dipach" #property version "1.93" #property strict #property indicator_chart_window #property indicator_buffers 2 //--- plot Label1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrCornflowerBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Label2 #property indicator_type2 DRAW_LINE #property indicator_color2 clrCornflowerBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- #define CHART_ID (0) #define COLUMNS (9) //количество ячеек таблицы по оси Х (>=2 and <=~30) #define ROWS (5) //количество строк в таблице по оси Y (без заголовка) #define MIN_COLUMNS (2) #define MAX_COLUMNS (30) #define NUMBER_ROWS_FOR_ONE_MA (2) #define SMALL_ROW(hw) ((hw/3)*2) #define HEIGHT_LONG_BUTTON(h) ((h/3)-1) #define DISTANCE_XY (1) #define BUFF_0 (0) #define BUFF_1 (1) #define NUMBER_BUFFERS (2) //number Moving Averages #define MA_PERIOD_MAX (3000) //ограничение периода усреднения МА (произвольное число) #define MA_SHIFT (0) #define BAR_ADD (1) #define MIN_BARS (5) #define PREFIX_COLUMNS ("_edit_") #define PREFIX_BUTTONS ("_butt") #define PREFIX_TITLE ("_title_") #define CODE_BUTTON (229) #define LINE_NUMBER "Line: ",__LINE__,", " //--- enum enum_Digits { auto=-1,//current chart dig0=0,//0 dig1=1,//1 dig2=2,//2 dig3=3,//3 dig4=4,//4 dig5=5,//5 dig6=6,//6 dig7=7,//7 dig8=8,//8 }; //--- input bool i_show_lines=false; // Show lines MA input int i_ma_0_indent=0; // Shift in points from MA1 (-/+ Down or Up) input int i_ma_1_indent=0; // Shift in points from MA2 (-/+ Down or Up) input enum_Digits i_digits=auto; // Decimal digits input uint i_shift=1; // Shift (bar for first value): sinput string i_stripe_0="+++++++++++++++++++++";//+++++++++++++++++++++ input uint i_ma_0_period=1; // Period Moving Averages (1)>= 1 or <= 3000: input ENUM_MA_METHOD i_ma_0_method=MODE_SMA; // MA method (1): input ENUM_APPLIED_PRICE i_ma_0_applied_price=PRICE_HIGH; // Apply to (1): sinput string i_stripe_1="+++++++++++++++++++++";//+++++++++++++++++++++ input uint i_ma_1_period=1; // Period Moving Averages (2)>= 1 or <= 3000: input ENUM_MA_METHOD i_ma_1_method=MODE_SMA; // MA method (2): input ENUM_APPLIED_PRICE i_ma_1_applied_price=PRICE_LOW; // Apply to (2): sinput string i_stripe_2="+++++++++++++++++++++";//+++++++++++++++++++++ input uint i_distance_x=3; // X coordinate input uint i_distance_y=3; // Y coordinate input color i_clr_back_main=C'224,224,224'; // Background color (table and Equal) input color i_clr_back_up=clrCornflowerBlue; // Background color (Up) input color i_clr_back_down=C'255,85,85'; // Background color (Down) input color i_clr_text_ma=C'48,48,48'; // Text color for MA input color i_clr_text_delta=clrDimGray; // Color text for delta input uint i_obj_width=60; // Width input uint i_obj_height=18; // Height input uint i_font_size=9; // Font size input bool i_behind=true; // Table of the indicator behind bars //--- double ma_0_buff[], ma_1_buff[]; string gp_symbol, gp_ind_shortname, gp_name_butt, ga_name[ROWS][COLUMNS], ga_text_odd_row[NUMBER_BUFFERS+1][COLUMNS], ga_text_even_row[NUMBER_BUFFERS][COLUMNS]; color ga_clr_back_odd_row[NUMBER_BUFFERS+1][COLUMNS], ga_clr_text_even_row[NUMBER_BUFFERS][COLUMNS]; int gp_first_bar, gp_min_rates_total, ga_ma_handle[NUMBER_BUFFERS], ga_ma_period[NUMBER_BUFFERS]; bool gp_first; //+------------------------------------------------------------------+ enum enum_DisplayTable{NO_,IS_,MINIMIZED,}; enum enum_UsePrice{IMA,HIGH,LOW,OPEN,CLOSE,}; //+------------------------------------------------------------------+ ENUM_TIMEFRAMES gp_tf; enum_DisplayTable gp_display_table=NO_; enum_UsePrice ga_use_price[NUMBER_BUFFERS]={IMA,IMA}; //+------------------------------------------------------------------+ int OnInit() { if(!InitAny())return(REASON_INITFAILED); //--- BuffersInit(); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void OnDeinit(const int reason) { if(reason!=REASON_CHARTCHANGE){ObjectsDeleteAll(CHART_ID,gp_ind_shortname,0,EMPTY);} //--- if(reason==REASON_INITFAILED){ChIndicatorDelete(gp_ind_shortname);} //--- ChartRedraw(); } //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, 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[]) { if(gp_first){if(rates_total-1=0;i--) {SetIndexEmptyValue(i,0.0);}} //--- limit=COLUMNS+gp_first_bar+BAR_ADD; } else{limit=rates_total-prev_calculated+BAR_ADD;} //--- if(time_new_bar!=time[0]) { time_new_bar=time[0]; //--- if(ga_use_price[BUFF_0]!=IMA) {if(!CopyPrice(gp_symbol,gp_tf,gp_first_bar,limit,ma_0_buff,ma_0_indent,digits,ga_use_price[BUFF_0])){return(0);}} else {IMAGet(gp_symbol,gp_tf,ga_ma_period[BUFF_0],MA_SHIFT,i_ma_0_method,i_ma_0_applied_price,gp_first_bar,limit,ma_0_indent,digits,ma_0_buff);} //--- if(ga_use_price[BUFF_1]!=IMA) {if(!CopyPrice(gp_symbol,gp_tf,gp_first_bar,limit,ma_1_buff,ma_1_indent,digits,ga_use_price[BUFF_1])){return(0);}} else {IMAGet(gp_symbol,gp_tf,ga_ma_period[BUFF_1],MA_SHIFT,i_ma_1_method,i_ma_1_applied_price,gp_first_bar,limit,ma_1_indent,digits,ma_1_buff);} //--- int count=MathMin(limit,COLUMNS); //--- if(count>0) { TableValuesSet(0,ma_0_buff,point_pow,BUFF_0,count,digits,ma_0_change_clr_arr,gp_first); TableValuesSet(NUMBER_ROWS_FOR_ONE_MA,ma_1_buff,point_pow,BUFF_1,count,digits,ma_1_change_clr_arr,gp_first); TableDeltaBetweenBuffers(NUMBER_ROWS_FOR_ONE_MA*NUMBER_BUFFERS,ma_0_buff,ma_1_buff,point_pow,NUMBER_BUFFERS,count,gp_first); //--- if(gp_first) { gp_first=false; gp_display_table=IS_; TableCreate(); } //--- if(i_show_lines){BuffersLineClrChange();} BufferBegin(rates_total-(COLUMNS+gp_first_bar+BAR_ADD)); } }//if(time_new_bar!=time[0]) //--- return(rates_total); } //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_OBJECT_CLICK) { if(StringFind(sparam,gp_ind_shortname)==0) { string clickedChartObject=sparam; //--- if(gp_display_table==IS_) { if(StringCompare(clickedChartObject,gp_name_butt,true)==0) { gp_display_table=MINIMIZED; //--- ObjectsDeleteAll(CHART_ID,gp_ind_shortname); //--- TableButtonsSet(gp_display_table,gp_name_butt,i_distance_x+i_obj_height, i_distance_y,i_obj_height); //--- ChartRedraw(); return; } } else if(gp_display_table==MINIMIZED) { gp_display_table=IS_; //--- TableCreate(); //--- ChartRedraw(); return; } return; } return; } return; } //+------------------------------------------------------------------+ bool InitAny() { gp_display_table =NO_; gp_first =true; gp_symbol =Symbol(); gp_tf =PERIOD_CURRENT; gp_first_bar =(i_shiftMAX_COLUMNS) {Print(LINE_NUMBER,"Error code: COLUMNS.");return(false);} //--- if(!MADataInit(ga_ma_period)){return(false);} //--- gp_min_rates_total=MinRatesTotalNumberSet(ga_ma_period); //--- for(int row=0;rowMA_PERIOD_MAX) { Alert("Indicator removed. Period Moving Averages (",IntegerToString(index),": < 1 or > ",MA_PERIOD_MAX,")"); return(false); } result=ma_period; //--- return(true); } //+------------------------------------------------------------------+ void PriseUse(int ma_period,ENUM_MA_METHOD method,ENUM_APPLIED_PRICE applied_price,enum_UsePrice &use_price) { if(ma_period==1 && method==MODE_SMA) { if(applied_price==PRICE_HIGH){use_price=HIGH;return;} else if(applied_price==PRICE_LOW){use_price=LOW;return;} else if(applied_price==PRICE_OPEN){use_price=OPEN;return;} else if(applied_price==PRICE_CLOSE){use_price=CLOSE;return;} } return; } //+------------------------------------------------------------------+ int MinRatesTotalNumberSet(int &period_arr[]) { //---две строки ниже применимы только для значений МА с текущего таймфрейма и символа: int min[NUMBER_BUFFERS]={1,1}; //--- for(int i=NUMBER_BUFFERS-1;i>=0;i--){min[i]=period_arr[i]+COLUMNS+gp_first_bar+MIN_BARS;} //---минимальное количество баров на графике, при котором индикатор будет работать: return(min[ArrayMaximum(min)]); } //+------------------------------------------------------------------+ void ObjNameTwoDArray(int rows, //сколько строк по оси Y string &array[][COLUMNS], //массив для имен объектов string pr="_") { for(int row=0;row=0;i--) {SetIndexLabel(i,name_buff_arr[i]);} BufferBegin(COLUMNS+gp_first_bar+BAR_ADD); //--- if(i_show_lines){for(int i=NUMBER_BUFFERS-1;i>=0;i--){SetIndexStyle(i,DRAW_LINE,EMPTY,EMPTY,i_clr_back_main);}} else {for(int i=NUMBER_BUFFERS-1;i>=0;i--){SetIndexStyle(i,DRAW_NONE);}} //--- for(int i=NUMBER_BUFFERS-1;i>=0;i--) {SetIndexEmptyValue(i,0.0);} //--- return; } //+------------------------------------------------------------------+ int DigitsSet(const enum_Digits variant) {return((i_digits==auto) ? Digits() : i_digits);} //+------------------------------------------------------------------+ string BufferMaNameSet(int index,int ma_period) {return(StringConcatenate(index," MA(",IntegerToString(ma_period),"):"));} //+------------------------------------------------------------------+ void BufferBegin(const int count) { for(int i=NUMBER_BUFFERS-1;i>=0;i--) {SetIndexDrawBegin(i,count);} return; } //+------------------------------------------------------------------+ template //+------------------------------------------------------------------+ bool ArrayResizeAndSetAsSeries(TB &array[], const int new_size, const int reserve_size=0, const bool flag=true) { ArrayResize(array,new_size,reserve_size); int array_size=ArraySize(array); //--- if(array_size>1){ArraySetAsSeries(array,flag);} else if(array_size<0){return(false);} return(true); } //+------------------------------------------------------------------+ double IndentDoubleSet(const int indent, const int point_pow, int digits) { int max_value=(int)(100*point_pow);//произвольное число: 100 умноженное на 10 в степени digits int int_value=(int)MathAbs(indent); //--- return((int_value==0 || int_value>=max_value) ? 0.0 : indent*Point()); } //+------------------------------------------------------------------+ bool CopyPrice(string symbol, ENUM_TIMEFRAMES tf, int start_pos, int count, double &buffer[], double indent, int digits, enum_UsePrice use) { double dt[]; if(!ArrayResizeAndSetAsSeries(dt,count+start_pos,count+start_pos)) {Print(LINE_NUMBER,"Error code = ",GetLastError());return(false);} //--- int copied=-1; //--- if(use==HIGH){copied=CopyHigh(symbol,tf,start_pos-BAR_ADD,count,dt);} else if(use==LOW){copied=CopyLow(symbol,tf,start_pos-BAR_ADD,count,dt);} else if(use==OPEN){copied=CopyOpen(symbol,tf,start_pos-BAR_ADD,count,dt);} else if(use==CLOSE){copied=CopyClose(symbol,tf,start_pos-BAR_ADD,count,dt);} //--- if(copied=NUMBER_ROWS_FOR_ONE_MA)? ma_1_tooltip: ma_0_tooltip; //--- y_dis_ch=y_dis+((height+heigh_small)*(row-step))+((DISTANCE_XY*NUMBER_BUFFERS)*(row-step)); for(int i=0;i=0;i--){name_arr[i]=StringConcatenate(gp_ind_shortname,PREFIX_TITLE,i);} } //--- for(int i=0;i