From 00d4695a44ab8957b5e9d4c193d06e172005f871 Mon Sep 17 00:00:00 2001 From: Gunther Schulz Date: Sat, 4 Jan 2020 09:57:33 +0100 Subject: [PATCH] add Lizar contrib files https://www.litefx.to/metatrader-5/experts/3691-multicurrency-ontick-string-symbol-event-handler-expert-for-metatrader-5.html --- .../Lizar/Experts/OnTick(string symbol).mq5 | 73 ++++++ .../Lizar/Include/OnTick(string symbol).mqh | 214 ++++++++++++++++++ .../Indicators/Spy Control panel MCM.mq5 | 160 +++++++++++++ 3 files changed, 447 insertions(+) create mode 100644 contrib/Lizar/Experts/OnTick(string symbol).mq5 create mode 100644 contrib/Lizar/Include/OnTick(string symbol).mqh create mode 100644 contrib/Lizar/Indicators/Spy Control panel MCM.mq5 diff --git a/contrib/Lizar/Experts/OnTick(string symbol).mq5 b/contrib/Lizar/Experts/OnTick(string symbol).mq5 new file mode 100644 index 0000000..86d0fc0 --- /dev/null +++ b/contrib/Lizar/Experts/OnTick(string symbol).mq5 @@ -0,0 +1,73 @@ +//+------------------------------------------------------------------+ +//| OnTick(string symbol).mq5 | +//| Copyright 2010, Lizar | +//| https://login.mql5.com/ru/users/Lizar | +//+------------------------------------------------------------------+ +#define VERSION "1.00 Build 1 (01 Fab 2011)" + +#property copyright "Copyright 2010, Lizar" +#property link "https://login.mql5.com/ru/users/Lizar" +#property version VERSION +#property description "Template of the Expert Advisor" +#property description "with multicurrency OnTick(string symbol) event handler" + +//+------------------------------------------------------------------+ +//| MULTICURRENCY MODE SETTINGS | +//| of OnTick(string symbol) event handler | +//| | +//| 1.1 List of symbols needed to proceed in the events: | +#define SYMBOLS_TRADING "EURUSD","GBPUSD","USDJPY","USDCHF" +//| 1.2 If you want all symbols from Market Watch, use this: | +//#define SYMBOLS_TRADING "MARKET_WATCH" +//| Note: Select only one way from 1.1 or 1.2. | +//| | +//| 2. Event type for OnTick(string symbol): | +#define CHART_EVENT_SYMBOL CHARTEVENT_TICK +//| Note: the event type must corresponds to the | +//| ENUM_CHART_EVENT_SYMBOL enumeration. | +//| | +//| 3. Include file: | +#include +//+------------------------------------------------------------------+ + +//+------------------------------------------------------------------+ +//| Expert initialization function | +//| This function must be declared, even if it empty. | +//+------------------------------------------------------------------+ +int OnInit() + { + //--- Add your code here... + return(0); + } + +//+------------------------------------------------------------------+ +//| Expert multi tick function | +//| Use this function instead of the standard OnTick() function | +//+------------------------------------------------------------------+ +void OnTick(string symbol) + { + //--- Add your code here... + Print("New event on symbol: ",symbol); + } + +//+------------------------------------------------------------------+ +//| ChartEvent function | +//| This function must be declared, even if it empty. | +//+------------------------------------------------------------------+ +void OnChartEvent(const int id, // event id + const long& lparam, // event param of long type + const double& dparam, // event param of double type + const string& sparam) // event param of string type + { + //--- Add your code here... + } + +//+------------------------------------------------------------------+ +//| Expert deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { + //--- Add your code here... + } + +//+------------------------------ end -------------------------------+ \ No newline at end of file diff --git a/contrib/Lizar/Include/OnTick(string symbol).mqh b/contrib/Lizar/Include/OnTick(string symbol).mqh new file mode 100644 index 0000000..87cfdca --- /dev/null +++ b/contrib/Lizar/Include/OnTick(string symbol).mqh @@ -0,0 +1,214 @@ +//+------------------------------------------------------------------+ +//| OnTick(string symbol).mqh | +//| Copyright 2010, Lizar | +//| https://login.mql5.com/ru/users/Lizar | +//| Revision 2011.01.30 | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2010, Lizar" +#property link "https://login.mql5.com/ru/users/Lizar" + +//+------------------------------------------------------------------+ +//| The events enumeration is implemented as flags | +//| the events can be combined using the OR ("|") logical operation | +//+------------------------------------------------------------------+ + + +enum ENUM_CHART_EVENT_SYMBOL + { + CHARTEVENT_NO =0, // Events disabled + CHARTEVENT_INIT =0, // "Initialization" event + + CHARTEVENT_NEWBAR_M1 =0x00000001, // "New bar" event on M1 chart + CHARTEVENT_NEWBAR_M2 =0x00000002, // "New bar" event on M2 chart + CHARTEVENT_NEWBAR_M3 =0x00000004, // "New bar" event on M3 chart + CHARTEVENT_NEWBAR_M4 =0x00000008, // "New bar" event on M4 chart + + CHARTEVENT_NEWBAR_M5 =0x00000010, // "New bar" event on M5 chart + CHARTEVENT_NEWBAR_M6 =0x00000020, // "New bar" event on M6 chart + CHARTEVENT_NEWBAR_M10=0x00000040, // "New bar" event on M10 chart + CHARTEVENT_NEWBAR_M12=0x00000080, // "New bar" event on M12 chart + + CHARTEVENT_NEWBAR_M15=0x00000100, // "New bar" event on M15 chart + CHARTEVENT_NEWBAR_M20=0x00000200, // "New bar" event on M20 chart + CHARTEVENT_NEWBAR_M30=0x00000400, // "New bar" event on M30 chart + CHARTEVENT_NEWBAR_H1 =0x00000800, // "New bar" event on H1 chart + + CHARTEVENT_NEWBAR_H2 =0x00001000, // "New bar" event on H2 chart + CHARTEVENT_NEWBAR_H3 =0x00002000, // "New bar" event on H3 chart + CHARTEVENT_NEWBAR_H4 =0x00004000, // "New bar" event on H4 chart + CHARTEVENT_NEWBAR_H6 =0x00008000, // "New bar" event on H6 chart + + CHARTEVENT_NEWBAR_H8 =0x00010000, // "New bar" event on H8 chart + CHARTEVENT_NEWBAR_H12=0x00020000, // "New bar" event on H12 chart + CHARTEVENT_NEWBAR_D1 =0x00040000, // "New bar" event on D1 chart + CHARTEVENT_NEWBAR_W1 =0x00080000, // "New bar" event on W1 chart + + CHARTEVENT_NEWBAR_MN1=0x00100000, // "New bar" event on MN1 chart + CHARTEVENT_TICK =0x00200000, // "New tick" event + + CHARTEVENT_ALL =0xFFFFFFFF, // All events enabled + }; + +//--- +string _symbol_[]={SYMBOLS_TRADING}; +int _handle_[]; + +int _symbols_total_ = 0; // total symbols +int _symbols_market_ = 0; // number of symbols in Market Watch +bool _market_watch_ = false; // use symbols from Market Watch +bool _testing_ = false; // In testing mode + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit() + { + //--- check if we work in Strategy Tester: + _testing_=((bool)MQL5InfoInteger(MQL5_TESTING) || + (bool)MQL5InfoInteger(MQL5_OPTIMIZATION) || + (bool)MQL5InfoInteger(MQL5_VISUAL_MODE)); + + //--- Check do we need to use the symbols from Market Watch + if(_symbol_[0]=="MARKET_WATCH") _market_watch_=true; + + //--- check settings + if(_testing_ && _market_watch_) + { + Print("Error: Please specify list of symbols in SYMBOLS_TRADING for use in Strategy Tester "); + return(1); + } + + //--- Initialization of variables and arrays: + _symbols_total_=SymbolsTotal(false); // total symbols + ArrayResize(_handle_,_symbols_total_); // resize array for handles of "spys" + ArrayInitialize(_handle_,INVALID_HANDLE); // initalizae array for handles of "spys" + + //--- Load "spys": + if(_market_watch_) SynchronizationTradingTools(); + else + { + _symbols_total_=ArraySize(_symbol_); + for(int i=0;i<_symbols_total_;i++) + if(!LoadAgent(i, _symbol_[i])) return(1); + } + + //--- Execute OnInit function of Expert Advisor + _OnInit(); + return(0); + } +#define OnInit _OnInit // rendefine of OnInit function + +//+------------------------------------------------------------------+ +//| Expert tick function | +//| Used only in Strategy Tester | +//+------------------------------------------------------------------+ +void OnTick() + { + if(_testing_) + { + for(int i=0;i<_symbols_total_;i++) + { + string __symbol__=_symbol_[i]; + if(MathAbs(GlobalVariableGet(__symbol__+"_flag")-2)<0.1) + { + GlobalVariableSet(__symbol__+"_flag",1); + OnTick(__symbol__); + } + } + } + } + +//+------------------------------------------------------------------+ +//| ChartEvent function | +//+------------------------------------------------------------------+ +void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam) + { + //--- Call of OnTick(string symbol) or OnChartEvent event handler: + if(id==CHARTEVENT_CUSTOM_LAST) + { + OnTick(sparam); + //--- synchronize "agents" with Market Watch if necessary: + if(_market_watch_) SynchronizationTradingTools(); + } + else _OnChartEvent(id,lparam,dparam,sparam); + } +#define OnChartEvent _OnChartEvent // rendefine of OnChartEvent function + +//+------------------------------------------------------------------+ +//| Function for synchronization of "spys" with symbols | +//| from "Market Watch" | +//| INPUT: no. | +//| OUTPUT: no. | +//| REMARK: no. | +//+------------------------------------------------------------------+ +void SynchronizationTradingTools() + { + if(_symbols_market_!=SymbolsTotal(true)) + { + _symbols_market_=0; + + for(int i=0;i<_symbols_total_;i++) + { + long __symbol_select__; + string __symbol__=SymbolName(i,false); + if(!SymbolInfoInteger(__symbol__,SYMBOL_SELECT,__symbol_select__)) return; + + if(_handle_[i]==INVALID_HANDLE && __symbol_select__) + { + if(!LoadAgent(i,__symbol__)) return; + } + else if(_handle_[i]!=INVALID_HANDLE && !__symbol_select__) + { + if(!DeLoadAgent(i,__symbol__)) return; + } + } + _symbols_market_=SymbolsTotal(true); + } + } + +//+------------------------------------------------------------------+ +//| Function for loading of "spys" | +//| INPUT: __id__ - id, corresponds to the symbol index in | +//| the list of symbols | +//| __symbol__ - symbol name | +//| OUTPUT: true - if successful | +//| false - if error | +//| REMARK: no. | +//+------------------------------------------------------------------+ +bool LoadAgent(int __id__, string __symbol__) + { + _handle_[__id__]=iCustom(__symbol__,_Period,"Spy Control panel MCM",ChartID(),65534,CHART_EVENT_SYMBOL); + if(_handle_[__id__]==INVALID_HANDLE) + { + Print("Error in setting of agent for ",__symbol__); + return(false); + } + Print("The agent for ",__symbol__," is set."); + return(true); + } + +//+------------------------------------------------------------------+ +//| Function for release of the "spys" | +//| INPUT: __id__ - id, corresponds to the symbol index in | +//| the list of symbols | +//| __symbol__ - symbol name | +//| OUTPUT: true - if successful | +//| false - if error | +//| REMARK: no. | +//+------------------------------------------------------------------+ +bool DeLoadAgent(int __id__, string __symbol__) + { + if(_handle_[__id__]!=INVALID_HANDLE) + { + if(!IndicatorRelease(_handle_[__id__])) + { + Print("Error deletion of agent for ",__symbol__); + return(false); + } + Print("The agent for ",__symbol__," is deleted."); + _handle_[__id__]=INVALID_HANDLE; + } + return(true); + } + +//+------------------------------ end -------------------------------+ \ No newline at end of file diff --git a/contrib/Lizar/Indicators/Spy Control panel MCM.mq5 b/contrib/Lizar/Indicators/Spy Control panel MCM.mq5 new file mode 100644 index 0000000..dcfce9e --- /dev/null +++ b/contrib/Lizar/Indicators/Spy Control panel MCM.mq5 @@ -0,0 +1,160 @@ +//+------------------------------------------------------------------+ +//| Spy Control panel MCM.mq5 | +//| Copyright 2010, Lizar | +//| https://login.mql5.com/ru/users/Lizar | +//+------------------------------------------------------------------+ +#define VERSION "1.00 Build 4 (30 Jan 2011)" + +#property copyright "Copyright 2010, Lizar" +#property link "https://login.mql5.com/ru/users/Lizar" +#property version VERSION +#property description "MCM Control panel agent." +#property description "It can be attached to the chart (any timeframe) of the symbol needed" +#property description "and generate the NewBar and/or NewTick custom events for the chart" + +#property indicator_chart_window + +//+------------------------------------------------------------------+ +//| The events enumeration is implemented as flags | +//| the events can be combined using the OR ("|") logical operation | +//+------------------------------------------------------------------+ + +enum ENUM_CHART_EVENT_SYMBOL + { + CHARTEVENT_INIT =0, // "Initialization" event + CHARTEVENT_NO =0, // Events disabled + + CHARTEVENT_NEWBAR_M1 =0x00000001, // "New bar" event on 1-m chart + CHARTEVENT_NEWBAR_M2 =0x00000002, // "New bar" event on 2-m chart + CHARTEVENT_NEWBAR_M3 =0x00000004, // "New bar" event on 3-m chart + CHARTEVENT_NEWBAR_M4 =0x00000008, // "New bar" event on 4-m chart + + CHARTEVENT_NEWBAR_M5 =0x00000010, // "New bar" event on 5-m chart + CHARTEVENT_NEWBAR_M6 =0x00000020, // "New bar" event on 6-m chart + CHARTEVENT_NEWBAR_M10=0x00000040, // "New bar" event on 10-m chart + CHARTEVENT_NEWBAR_M12=0x00000080, // "New bar" event on 12-m chart + + CHARTEVENT_NEWBAR_M15=0x00000100, // "New bar" event on 15-m chart + CHARTEVENT_NEWBAR_M20=0x00000200, // "New bar" event on 20-m chart + CHARTEVENT_NEWBAR_M30=0x00000400, // "New bar" event on 30-m chart + CHARTEVENT_NEWBAR_H1 =0x00000800, // "New bar" event on hourly chart + + CHARTEVENT_NEWBAR_H2 =0x00001000, // "New bar" event on H2 chart + CHARTEVENT_NEWBAR_H3 =0x00002000, // "New bar" event on H3 chart + CHARTEVENT_NEWBAR_H4 =0x00004000, // "New bar" event on H4 chart + CHARTEVENT_NEWBAR_H6 =0x00008000, // "New bar" event on H6 chart + + CHARTEVENT_NEWBAR_H8 =0x00010000, // "New bar" event on H8 chart + CHARTEVENT_NEWBAR_H12=0x00020000, // "New bar" event on H12 chart + CHARTEVENT_NEWBAR_D1 =0x00040000, // "New bar" event on D1 chart + CHARTEVENT_NEWBAR_W1 =0x00080000, // "New bar" event on W1 chart + + CHARTEVENT_NEWBAR_MN1=0x00100000, // "New bar" event on MN1 chart + CHARTEVENT_TICK =0x00200000, // "New tick" event + + CHARTEVENT_ALL =0xFFFFFFFF, // All events enabled + }; + +input long chart_id; // chart id +input ushort custom_event_id; // event id +input ENUM_CHART_EVENT_SYMBOL flag_event=CHARTEVENT_NO; // event flag. + +MqlDateTime time, prev_time; + +bool testing=false; + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit() + { + testing=((bool)MQL5InfoInteger(MQL5_TESTING) || + (bool)MQL5InfoInteger(MQL5_OPTIMIZATION) || + (bool) MQL5InfoInteger(MQL5_VISUAL_MODE)); + + if(testing) + { + GlobalVariableTemp(_Symbol+"_flag"); + GlobalVariableTemp(_Symbol+"_custom_id"); + GlobalVariableTemp(_Symbol+"_event"); + GlobalVariableTemp(_Symbol+"_price"); + } + + return(0); + } + +//+------------------------------------------------------------------+ +//| Custom indicator iteration function | +//+------------------------------------------------------------------+ +int OnCalculate (const int rates_total, // size of price[] array + const int prev_calculated, // bars calculated at previous call + const int begin, // begin + const double& price[] // array for calculation + ) + { + double price_current=price[rates_total-1]; + + TimeCurrent(time); + + if(prev_calculated==0) + { + EventCustom(CHARTEVENT_INIT,price_current); + prev_time=time; + return(rates_total); + } + +//--- new tick + if((flag_event & CHARTEVENT_TICK)!=0) EventCustom(CHARTEVENT_TICK,price_current); + +//--- check change time + if(time.min==prev_time.min && + time.hour==prev_time.hour && + time.day==prev_time.day && + time.mon==prev_time.mon) return(rates_total); + +//--- new minute + if((flag_event & CHARTEVENT_NEWBAR_M1)!=0) EventCustom(CHARTEVENT_NEWBAR_M1,price_current); + if(time.min%2 ==0 && (flag_event & CHARTEVENT_NEWBAR_M2)!=0) EventCustom(CHARTEVENT_NEWBAR_M2,price_current); + if(time.min%3 ==0 && (flag_event & CHARTEVENT_NEWBAR_M3)!=0) EventCustom(CHARTEVENT_NEWBAR_M3,price_current); + if(time.min%4 ==0 && (flag_event & CHARTEVENT_NEWBAR_M4)!=0) EventCustom(CHARTEVENT_NEWBAR_M4,price_current); + if(time.min%5 ==0 && (flag_event & CHARTEVENT_NEWBAR_M5)!=0) EventCustom(CHARTEVENT_NEWBAR_M5,price_current); + if(time.min%6 ==0 && (flag_event & CHARTEVENT_NEWBAR_M6)!=0) EventCustom(CHARTEVENT_NEWBAR_M6,price_current); + if(time.min%10==0 && (flag_event & CHARTEVENT_NEWBAR_M10)!=0) EventCustom(CHARTEVENT_NEWBAR_M10,price_current); + if(time.min%12==0 && (flag_event & CHARTEVENT_NEWBAR_M12)!=0) EventCustom(CHARTEVENT_NEWBAR_M12,price_current); + if(time.min%15==0 && (flag_event & CHARTEVENT_NEWBAR_M15)!=0) EventCustom(CHARTEVENT_NEWBAR_M15,price_current); + if(time.min%20==0 && (flag_event & CHARTEVENT_NEWBAR_M20)!=0) EventCustom(CHARTEVENT_NEWBAR_M20,price_current); + if(time.min%30==0 && (flag_event & CHARTEVENT_NEWBAR_M30)!=0) EventCustom(CHARTEVENT_NEWBAR_M30,price_current); + if(time.min!=0) {prev_time=time; return(rates_total);} +//--- new hour + if((flag_event & CHARTEVENT_NEWBAR_H1)!=0) EventCustom(CHARTEVENT_NEWBAR_H1,price_current); + if(time.hour%2 ==0 && (flag_event & CHARTEVENT_NEWBAR_H2)!=0) EventCustom(CHARTEVENT_NEWBAR_H2,price_current); + if(time.hour%3 ==0 && (flag_event & CHARTEVENT_NEWBAR_H3)!=0) EventCustom(CHARTEVENT_NEWBAR_H3,price_current); + if(time.hour%4 ==0 && (flag_event & CHARTEVENT_NEWBAR_H4)!=0) EventCustom(CHARTEVENT_NEWBAR_H4,price_current); + if(time.hour%6 ==0 && (flag_event & CHARTEVENT_NEWBAR_H6)!=0) EventCustom(CHARTEVENT_NEWBAR_H6,price_current); + if(time.hour%8 ==0 && (flag_event & CHARTEVENT_NEWBAR_H8)!=0) EventCustom(CHARTEVENT_NEWBAR_H8,price_current); + if(time.hour%12==0 && (flag_event & CHARTEVENT_NEWBAR_H12)!=0) EventCustom(CHARTEVENT_NEWBAR_H12,price_current); + if(time.hour!=0) {prev_time=time; return(rates_total);} +//--- new day + if((flag_event & CHARTEVENT_NEWBAR_D1)!=0) EventCustom(CHARTEVENT_NEWBAR_D1,price_current); + //--- new week + if(time.day_of_week==1 && (flag_event & CHARTEVENT_NEWBAR_W1)!=0) EventCustom(CHARTEVENT_NEWBAR_W1,price_current); + //--- new month + if(time.day==1 && (flag_event & CHARTEVENT_NEWBAR_MN1)!=0) EventCustom(CHARTEVENT_NEWBAR_MN1,price_current); + prev_time=time; +//--- return value of prev_calculated for next call + return(rates_total); + } +//+------------------------------------------------------------------+ + +void EventCustom(ENUM_CHART_EVENT_SYMBOL event,double price) + { + if(!testing) EventChartCustom(chart_id,custom_event_id,(long)event,price,_Symbol); + else + { + if(GlobalVariableSet(_Symbol+"_custom_id",custom_event_id)==0) return; + if(GlobalVariableSet(_Symbol+"_event",event)==0) return; + if(GlobalVariableSet(_Symbol+"_price",price)==0) return; + GlobalVariableSet(_Symbol+"_flag",2); + } + return; + } \ No newline at end of file