mq5 EA模板及双均线交叉策略EAdemo

//+------------------------------------------------------------------+
//|                                                  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()); 
         //--- 当前挂单数量 
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值