//+------------------------------------------------------------------+ //| CopyTicksVSSymbolInfoTickInd.mq5 | //| Copyright © 2016, Vladimir Karputov | //| http://wmua.ru/slesar/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2015, Vladimir Karputov" #property link "http://wmua.ru/slesar/" #property version "1.44" #property description "Indicator for comparing the three modes of receiving ticks" #property description "Индикатор для сравнения трёх режимов получения тиков" #property indicator_plots 0 #property indicator_chart_window //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_COPY_TICKS { TICKS_INFO=1, // only/только Bid и Ask TICKS_TRADE=2, // only/только Last и Volume TICKS_ALL=-1, // all ticks/все тики }; //--- parameters int ticks=1; // number of requested tics/количество запрашиваемых тиков input ENUM_COPY_TICKS type=TICKS_ALL; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping Print(TICK_FLAG_BID," - tick has changed a Bid price/тик изменил цену бид"); Print(TICK_FLAG_ASK," - a tick has changed an Ask price/тик изменил цену аск"); Print(TICK_FLAG_LAST," - a tick has changed the last deal price/тик изменил цену последней сделки"); Print(TICK_FLAG_VOLUME," - a tick has changed a volume/тик изменил объем"); Print(TICK_FLAG_BUY," - a tick is a result of a buy deal/тик возник в результате сделки на покупку"); Print(TICK_FLAG_SELL," - a tick is a result of a sell deal/тик возник в результате сделки на продажу"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- the array that receives ticks/массив для приема тиков MqlTick tick_array[]; //--- requesting ticks/запросим тики int copied=CopyTicks(_Symbol,tick_array,type,0,ticks); //--- MqlTick last_tick; ResetLastError(); if(!SymbolInfoTick(Symbol(),last_tick)) Print("SymbolInfoTick() failed, error = ",GetLastError()); //--- if ticks are received, show the Bid and Ask values on the chart //--- если тики получены, то выведем на график значения Bid и Ask if(copied>0) { string comment=EnumToString(type)+" ,requested "+IntegerToString(ticks)+ ", copied "+IntegerToString(copied)+"\r\n"; comment+="CopyTicks SymbolInfoTick\r\n"; //--- generate the comment contents /сформируем содержимое комментария string flags=""; MqlTick tick=tick_array[0]; string tick_string=StringFormat("%-4d %-4d",tick.flags,last_tick.flags); comment=comment+tick_string; //--- show a comment on the chart/выводим комментарий на график Comment(comment); //--- if(tick.flags==0 || last_tick.flags==0) Alert("tick.flags="+IntegerToString(tick.flags)+"; last_tick.flags="+IntegerToString(last_tick.flags)); } else // report an error that occurred when receiving ticks/сообщим об ошибке при получении тиков { Comment("Ticks could not be loaded/Не удалось загрузить тики. GetLastError()=",GetLastError()); } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Comment(""); } //+------------------------------------------------------------------+