代码拉取完成,页面将自动刷新
//+------------------------------------------------------------------+
//| 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);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。