© 本贴为 My05613828 首发,严禁抄袭!
- //+------------------------------------------------------------------+
- //| M4EA 订单属性封装.mq4 |
- //| Copyright 2024, MetaQuotes Ltd. |
- //| https://www.mql5.com |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2024, MetaQuotes Ltd."
- #property link "https://www.mql5.com"
- #property version "1.00"
- #property strict
- //+------------------------------------------------------------------+
- //| Expert initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //--- create timer
- EventSetTimer(60);
-
- //---
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Expert deinitialization function |
- //+------------------------------------------------------------------+
- void OnDeinit(const int reason)
- {
- //--- destroy timer
- EventKillTimer();
-
- }
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- //---
- long open_time = 获取订单的integer属性值(Symbol(),0,orderopentime);
- double lots = 获取订单的double属性值(Symbol(),0,orderlots);
- string comment = 获取订单的string属性值(Symbol(),0,ordercomment);
-
- string time = TimeToString((datetime)open_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
-
-
-
- long history_open_time = 获取历史订单的integer属性值(Symbol(),0,orderopentime);
- long history_close_time = 获取历史订单的integer属性值(Symbol(),0,orderclosetime);
-
- string histoyr_open_times = TimeToString((datetime)history_open_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
- string histoyr_close_times = TimeToString((datetime)history_close_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
-
- Alert("开盘时间 ",histoyr_open_times," 关闭时间",histoyr_close_times);
- //Alert(time," &&手数",lots,"&&注释",comment);
- }
- //+------------------------------------------------------------------+
- //| Timer function |
- //+------------------------------------------------------------------+
- void OnTimer()
- {
- //---
-
- }
- //+------------------------------------------------------------------+
-
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
-
-
-
-
-
- //+------------------------------------------------------------------+
- enum ENUM_PROPERTY_INTEGER
- {
- orderopentime=0,
- orderticket=1,
- ordermagicnumber=2,
- ordertype=3,
- timecurrent_orderopentime=4,
- orderclosetime=5
- };
- enum ENUM_PROPERTY_DOUBLE
- {
- orderopenprice=0,
- orderlots=1,
- orderstoploss=2,
- ordertakeprofit=3,
- ordercloseprice=4,
- orderprofit=5,
- orderswap=6,
- ordercommission=7
- };
-
- enum ENUM_PROPERTY_STRING
- {
- ordersymbol=0,
- ordercomment=1
- };
-
- //+------------------------------------------------------------------+
- long GetInteger(ENUM_PROPERTY_INTEGER property)
- {
- if(property==orderopentime)
- return OrderOpenTime();
- if(property==orderticket)
- return OrderTicket();
- if(property==ordermagicnumber)
- return OrderMagicNumber();
- if(property==ordertype)
- return OrderType();
- if(property==timecurrent_orderopentime)
- return TimeCurrent()-OrderOpenTime();
- if(property==orderclosetime)
- return OrderCloseTime();
- return -1;
- }
- //+------------------------------------------------------------------+
- double GetDouble(ENUM_PROPERTY_DOUBLE property)
- {
- if(property==orderopenprice)
- return OrderOpenPrice();
- if(property==orderlots)
- return OrderLots();
- if(property==orderstoploss)
- return OrderStopLoss();
- if(property==ordertakeprofit)
- return OrderTakeProfit();
- if(property==ordercloseprice)
- return OrderClosePrice();
- if(property==orderprofit)
- return OrderProfit();
- if(property==orderswap)
- return OrderSwap();
- if(property==ordercommission)
- return OrderCommission();
- return 0.0;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string GetString(ENUM_PROPERTY_STRING property)
- {
- if(property==ordersymbol)
- return OrderSymbol();
- if(property==ordercomment)
- return OrderComment();
- return "";
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
-
- //+------------------------------------------------------------------+
-
- //+------------------------------------------------------------------+
- long 获取订单的integer属性值(string symbol,int magic,ENUM_PROPERTY_INTEGER property)
- {
- for(int i= OrdersTotal()-1; i>=0; i--)
- {
- if(OrderSelect(i,SELECT_BY_POS)&&order_type_choose(1))
- {
- if(OrderTicket()>0)
- return GetInteger(property);
- }
- }
- return -1;
- }
-
- //+------------------------------------------------------------------+
- double 获取订单的double属性值(string symbol,int magic,ENUM_PROPERTY_DOUBLE property)
- {
- for(int i= OrdersTotal()-1; i>=0; i--)
- {
- if(OrderSelect(i,SELECT_BY_POS)&&order_type_choose(1))
- {
- if(OrderTicket()>0)
- return GetDouble(property);
- }
- }
- return 0.0;
- }
-
- //+------------------------------------------------------------------+
- string 获取订单的string属性值(string symbol,int magic,ENUM_PROPERTY_STRING property)
- {
- for(int i= OrdersTotal()-1; i>=0; i--)
- {
- if(OrderSelect(i,SELECT_BY_POS)&&order_type_choose(1))
- {
- if(OrderTicket()>0)
- return GetString(property);
- }
- }
- return "";
- }
- //+------------------------------------------------------------------+
-
-
-
-
- //+------------------------------------------------------------------+
- //+------------------------------------------------------------------+
- long 获取历史订单的integer属性值(string symbol,int magic,ENUM_PROPERTY_INTEGER property)
- {
- for(int i= OrdersHistoryTotal()-1; i>=0; i--)
- {
- if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&order_type_choose(2))
- {
- if(OrderTicket()>0)
- return GetInteger(property);
- }
- }
- return -1;
- }
-
- //+------------------------------------------------------------------+
- double 获取历史订单的double属性值(string symbol,int magic,ENUM_PROPERTY_DOUBLE property)
- {
- for(int i= OrdersHistoryTotal()-1; i>=0; i--)
- {
- if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&order_type_choose(2))
- {
- if(OrderTicket()>0)
- return GetDouble(property);
- }
- }
- return 0.0;
- }
-
- //+------------------------------------------------------------------+
- string 获取历史订单的string属性值(string symbol,int magic,ENUM_PROPERTY_STRING property)
- {
- for(int i= OrdersHistoryTotal()-1; i>=0; i--)
- {
- if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&order_type_choose(2))
- {
- if(OrderTicket()>0)
- return GetString(property);
- }
- }
- return "";
- }
- //+------------------------------------------------------------------+
- bool order_type_choose(int choose)
- {
- if(choose ==1)
- return OrderType()==OP_BUY||OrderType()==OP_SELL;
- if(choose ==2)
- return OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT||OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP;
- return false;
- }
- //+------------------------------------------------------------------+
复制代码
//+------------------------------------------------------------------+
//| M4EA 订单属性封装.mq4 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(60);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
long open_time = 获取订单的integer属性值(Symbol(),0,orderopentime);
double lots = 获取订单的double属性值(Symbol(),0,orderlots);
string comment = 获取订单的string属性值(Symbol(),0,ordercomment);
string time = TimeToString((datetime)open_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
long history_open_time = 获取历史订单的integer属性值(Symbol(),0,orderopentime);
long history_close_time = 获取历史订单的integer属性值(Symbol(),0,orderclosetime);
string histoyr_open_times = TimeToString((datetime)history_open_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
string histoyr_close_times = TimeToString((datetime)history_close_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
Alert("开盘时间 ",histoyr_open_times," 关闭时间",histoyr_close_times);
//Alert(time," &&手数",lots,"&&注释",comment);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
enum ENUM_PROPERTY_INTEGER
{
orderopentime=0,
orderticket=1,
ordermagicnumber=2,
ordertype=3,
timecurrent_orderopentime=4,
orderclosetime=5
};
enum ENUM_PROPERTY_DOUBLE
{
orderopenprice=0,
orderlots=1,
orderstoploss=2,
ordertakeprofit=3,
ordercloseprice=4,
orderprofit=5,
orderswap=6,
ordercommission=7
};
enum ENUM_PROPERTY_STRING
{
ordersymbol=0,
ordercomment=1
};
//+------------------------------------------------------------------+
long GetInteger(ENUM_PROPERTY_INTEGER property)
{
if(property==orderopentime)
return OrderOpenTime();
if(property==orderticket)
return OrderTicket();
if(property==ordermagicnumber)
return OrderMagicNumber();
if(property==ordertype)
return OrderType();
if(property==timecurrent_orderopentime)
return TimeCurrent()-OrderOpenTime();
if(property==orderclosetime)
return OrderCloseTime();
return -1;
}
//+------------------------------------------------------------------+
double GetDouble(ENUM_PROPERTY_DOUBLE property)
{
if(property==orderopenprice)
return OrderOpenPrice();
if(property==orderlots)
return OrderLots();
if(property==orderstoploss)
return OrderStopLoss();
if(property==ordertakeprofit)
return OrderTakeProfit();
if(property==ordercloseprice)
return OrderClosePrice();
if(property==orderprofit)
return OrderProfit();
if(property==orderswap)
return OrderSwap();
if(property==ordercommission)
return OrderCommission();
return 0.0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetString(ENUM_PROPERTY_STRING property)
{
if(property==ordersymbol)
return OrderSymbol();
if(property==ordercomment)
return OrderComment();
return "";
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
long 获取订单的integer属性值(string symbol,int magic,ENUM_PROPERTY_INTEGER property)
{
for(int i= OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)&&order_type_choose(1))
{
if(OrderTicket()>0)
return GetInteger(property);
}
}
return -1;
}
//+------------------------------------------------------------------+
double 获取订单的double属性值(string symbol,int magic,ENUM_PROPERTY_DOUBLE property)
{
for(int i= OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)&&order_type_choose(1))
{
if(OrderTicket()>0)
return GetDouble(property);
}
}
return 0.0;
}
//+------------------------------------------------------------------+
string 获取订单的string属性值(string symbol,int magic,ENUM_PROPERTY_STRING property)
{
for(int i= OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)&&order_type_choose(1))
{
if(OrderTicket()>0)
return GetString(property);
}
}
return "";
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
long 获取历史订单的integer属性值(string symbol,int magic,ENUM_PROPERTY_INTEGER property)
{
for(int i= OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&order_type_choose(2))
{
if(OrderTicket()>0)
return GetInteger(property);
}
}
return -1;
}
//+------------------------------------------------------------------+
double 获取历史订单的double属性值(string symbol,int magic,ENUM_PROPERTY_DOUBLE property)
{
for(int i= OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&order_type_choose(2))
{
if(OrderTicket()>0)
return GetDouble(property);
}
}
return 0.0;
}
//+------------------------------------------------------------------+
string 获取历史订单的string属性值(string symbol,int magic,ENUM_PROPERTY_STRING property)
{
for(int i= OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)&&order_type_choose(2))
{
if(OrderTicket()>0)
return GetString(property);
}
}
return "";
}
//+------------------------------------------------------------------+
bool order_type_choose(int choose)
{
if(choose ==1)
return OrderType()==OP_BUY||OrderType()==OP_SELL;
if(choose ==2)
return OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT||OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP;
return false;
}
//+------------------------------------------------------------------+ |