//+------------------------------------------------------------------+
//| mt5_ea_demo.mq5 |
//| Copyright 吕海洋 QQ交流群:157528427|
//| https://www.mql5.com/zh/signals/789037|
//+------------------------------------------------------------------+
#property copyright "Copyright 吕海洋 QQ交流群:157528427"
#property link "https://www.mql5.com/zh/signals/789037"
#property version "1.00"
#include <Trade\trade.mqh>
#include <Trade\PositionInfo.mqh>
//EA模板,封装了常用的订单操作,新建的类继承这个模板可以直接调用方法
class TradeSystem
{
public:
CTrade trade;
//获取最后一笔历史订单获利
//magic_number: 幻数(用来标记是EA建仓的单子)
//symbol:货币名称
//cmt: 订单注释信息
//order_type: 订单类型 "BUY","SELL"
double GetLastProfit(ulong magic_number, string symbol, string cmt, string order_type)
{
ENUM_DEAL_TYPE deal_type;
if(order_type == "BUY")
{
deal_type = DEAL_TYPE_SELL;
}
else if(order_type == "SELL")
{
deal_type = DEAL_TYPE_BUY;
}
else return 0;
ulong ticket;
double last_profit = 0;
//--- 请求交易历史记录
HistorySelect(0,TimeCurrent());
//--- 当前挂单数量
int total=HistoryDealsTotal();
//--- 循环检测通过订单
for(int i=total -1;i>=0;i--)
{
//--- 通过其列表中的位置返回订单报价
if((ticket=HistoryDealGetTicket(i))>0)
{
if(HistoryDealGetInteger(ticket,DEAL_MAGIC)==magic_number && HistoryDealGetString(ticket,DEAL_SYMBOL)==symbol)
{
if(HistoryDealGetInteger(ticket,DEAL_TYPE)==deal_type && HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT)
{
last_profit = HistoryDealGetDouble(ticket,DEAL_PROFIT);
break;
}
}
}
}
return last_profit;
}
//获取连续亏损次数
//magic_number: 幻数(用来标记是EA建仓的单子)
//symbol:货币名称
//cmt: 订单注释信息
//order_type: 订单类型 "BUY","SELL"
int GetStopLossTimes(ulong magic_number, string symbol, string cmt, string order_type)
{
ENUM_DEAL_TYPE deal_type;
if(order_type == "BUY")
{
deal_type = DEAL_TYPE_SELL;
}
else if(order_type == "SELL")
{
deal_type = DEAL_TYPE_BUY;
}
else return 0;
ulong ticket;
int stop_loss_times = 0;
//--- 请求交易历史记录
HistorySelect(0,TimeCurrent());
//--- 当前挂单数量
mq5 EA模板及双均线交叉策略EAdemo
最新推荐文章于 2024-08-30 15:20:48 发布