77 lines
4.7 KiB
MQL5
77 lines
4.7 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ProjectName |
|
|
//| Copyright 2020, CompanyName |
|
|
//| http://www.companyname.net |
|
|
//+------------------------------------------------------------------+
|
|
#ifndef GLOBAL_VAR_MQH
|
|
#define GLOBAL_VAR_MQH
|
|
|
|
#define GLOBAL_VAR_PREFIX "STK"
|
|
|
|
/*
|
|
Наименование глобальных переменных:
|
|
[Префикс]_[Пара]_[Мэджик]_[Направление=S\B]_[Наименование переменной]
|
|
*/
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
class tool_global_var
|
|
{
|
|
public:
|
|
static string _prefix_global;
|
|
public:
|
|
void init();
|
|
void deinit();
|
|
|
|
static string global_prefix()
|
|
{
|
|
str_builder b;
|
|
b.append(GLOBAL_VAR_PREFIX);
|
|
b.append("_");
|
|
b.append(Symbol());
|
|
b.append(itos(MagicNumber));
|
|
return b.to_str();
|
|
}
|
|
|
|
static void delete_all(const uchar postfix=0)
|
|
{
|
|
GlobalVariablesDeleteAll(prepare_var_name("",postfix),layer::time_local());
|
|
}
|
|
|
|
static bool set(const string name, double value,uchar postfix=0)
|
|
{
|
|
return (GlobalVariableSet(prepare_var_name(name,postfix), value)!=0);
|
|
}
|
|
|
|
static bool get(const string name, double& value, uchar postfix=0)
|
|
{
|
|
if(!GlobalVariableCheck(prepare_var_name(name,postfix)))
|
|
return false;
|
|
|
|
value=GlobalVariableGet(prepare_var_name(name,postfix));
|
|
return true;
|
|
}
|
|
|
|
static bool del(const string name,uchar postfix=0)
|
|
{
|
|
return GlobalVariableDel(prepare_var_name(name,postfix));
|
|
}
|
|
|
|
|
|
static string prepare_var_name(const string name,const uchar postfix)
|
|
{
|
|
return _prefix_global+((postfix!=0)?CharToString(postfix):"")+"_"+name;
|
|
}
|
|
|
|
static string generate_hash_var_name(const string name)
|
|
{
|
|
return ext_string::get_hash(name,CRYPT_HASH_MD5);
|
|
}
|
|
|
|
};
|
|
|
|
string tool_global_var::_prefix_global=tool_global_var::global_prefix();
|
|
|
|
#endif
|
|
//+------------------------------------------------------------------+
|