1 Star 0 Fork 0

潘波波/expert_trend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MyExpert.mqh 10.78 KB
一键复制 编辑 原始数据 按行查看 历史
潘波波 提交于 2024-06-06 19:22 . init project
//+------------------------------------------------------------------+
//| MyExpert.mq |
//| Copyright 2020-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
#include "Indicators.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CMyExpert : public CExpert
{
private:
public:
CMyExpert(void);
virtual ~CMyExpert(void);
virtual bool Processing(void) override;
virtual bool CheckCloseLong() override;
virtual bool CheckCloseShort() override;
virtual bool OpenLong(double price,double sl,double tp) override;
virtual bool OpenShort(double price,double sl,double tp) override;
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CMyExpert::CMyExpert(void)
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CMyExpert::~CMyExpert(void)
{
}
//+------------------------------------------------------------------+
//| Custom processing method |
//+------------------------------------------------------------------+
bool CMyExpert::Processing(void)
{
ExtractCurrentIndicators();
//--- calculate signal direction once
m_signal.SetDirection();
//--- check if open positions
if(SelectPosition())
{
//--- open position is available
//--- check the possibility of reverse the position
if(CheckReverse())
return(true);
//--- check the possibility of closing the position/delete pending orders
if(!CheckClose())
{
//--- check the possibility of modifying the position
if(CheckTrailingStop())
return(true);
//--- return without operations
return(false);
}
}
//--- check if plased pending orders
int total=OrdersTotal();
if(total!=0)
{
for(int i=total-1; i>=0; i--)
{
m_order.SelectByIndex(i);
if(m_order.Symbol()!=m_symbol.Name())
continue;
if(m_order.OrderType()==ORDER_TYPE_BUY_LIMIT || m_order.OrderType()==ORDER_TYPE_BUY_STOP)
{
//--- check the ability to delete a pending order to buy
if(CheckDeleteOrderLong())
return(true);
//--- check the possibility of modifying a pending order to buy
if(CheckTrailingOrderLong())
return(true);
}
else
{
//--- check the ability to delete a pending order to sell
if(CheckDeleteOrderShort())
return(true);
//--- check the possibility of modifying a pending order to sell
if(CheckTrailingOrderShort())
return(true);
}
//--- return without operations
return(false);
}
}
//--- check the possibility of opening a position/setting pending order
if(CheckOpen())
return(true);
//--- return without operations
return(false);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| 平多单 |
//+------------------------------------------------------------------+
bool CMyExpert::CheckCloseLong(void)
{
return false;
}
//+------------------------------------------------------------------+
//| 平空单 |
//+------------------------------------------------------------------+
bool CMyExpert::CheckCloseShort(void)
{
return false;
}
//+------------------------------------------------------------------+
//| Long position open or limit/stop order set |
//+------------------------------------------------------------------+
bool CMyExpert::OpenLong(double price,double sl,double tp)
{
if(price==EMPTY_VALUE)
return(false);
//--- get lot for open
double lot=LotOpenLong(price,sl);
//--- check lot for open
lot=LotCheck(lot,price,ORDER_TYPE_BUY);
if(lot==0.0)
return(false);
//--- 在这里循环
m_trade.Buy(lot,price,sl,tp);
return(true);
}
//+------------------------------------------------------------------+
//| Short position open or limit/stop order set |
//+------------------------------------------------------------------+
bool CMyExpert::OpenShort(double price,double sl,double tp)
{
if(price==EMPTY_VALUE)
return(false);
//--- get lot for open
double lot=LotOpenShort(price,sl);
//--- check lot for open
lot=LotCheck(lot,price,ORDER_TYPE_SELL);
if(lot==0.0)
return(false);
//---
m_trade.Sell(lot,price,sl,tp);
return(true);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sparrowbo/expert_trend.git
git@gitee.com:sparrowbo/expert_trend.git
sparrowbo
expert_trend
expert_trend
master

搜索帮助