Waddah Attar Win - MetaTrader 5EA
- 发布者:
- Vladimir Karputov
- 显示:
- 1239
- 等级:
- 已发布:
- 2017.03.23 07:54
- 需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务
思路提供者 — Ahmad Waddah Attar, MQL5 代码作者 — barabashkakvn。
采用限价买入 (BuyLimit) 和限价卖出 (SellLimit) 订单的智能交易系统。一旦价格移动到十分接近挂单:
if((m_symbol.Ask()-LastBuyLimitPrice)<=5*m_symbol.Point()) // FirstLot 非常接近
m_trade.BuyLimit(LastBuyLimitLot+IncLot,m_symbol.NormalizePrice(LastBuyLimitPrice-ExtStep));
if((LastSellLimitPrice-m_symbol.Bid())<=5*m_symbol.Point()) // FirstLot 非常接近
m_trade.SellLimit(LastBuyLimitLot+IncLot,m_symbol.NormalizePrice(LastSellLimitPrice+ExtStep));
m_trade.BuyLimit(LastBuyLimitLot+IncLot,m_symbol.NormalizePrice(LastBuyLimitPrice-ExtStep));
if((LastSellLimitPrice-m_symbol.Bid())<=5*m_symbol.Point()) // FirstLot 非常接近
m_trade.SellLimit(LastBuyLimitLot+IncLot,m_symbol.NormalizePrice(LastSellLimitPrice+ExtStep));
放置一笔或多笔挂单。
若要获取所放置的最后一笔订单的价格, 我们使用 OnTradeTransaction():
//+------------------------------------------------------------------+
//| TradeTransaction 函数 |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
const MqlTradeRequest &request,
const MqlTradeResult &result)
{
//--- 获取交易类型作为枚举的值
ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
Print(EnumToString(type));
//--- 如果是一笔成交 — 成交结果添加到历史
if(type==TRADE_TRANSACTION_ORDER_ADD)
{
long order_type =0;
double order_price =0.0;
double order_volume =0.0;
string order_symbol ="";
long order_magic =0;
if(OrderSelect(trans.order)) // 选择挂单
{
order_type=OrderGetInteger(ORDER_TYPE);
order_price=OrderGetDouble(ORDER_PRICE_OPEN);
order_volume=OrderGetDouble(ORDER_VOLUME_INITIAL);
order_symbol=OrderGetString(ORDER_SYMBOL);
order_magic=OrderGetInteger(ORDER_MAGIC);
}
else
return;
if(order_symbol==m_symbol.Name() && order_magic==m_magic)
{
if(order_type==ORDER_TYPE_BUY_LIMIT)
{
LastBuyLimitPrice=order_price;
LastBuyLimitLot=order_volume;
}
if(order_type==ORDER_TYPE_SELL_LIMIT)
{
LastSellLimitPrice=order_price;
LastSellLimitlLot=order_volume;
}
}
}
}
//| TradeTransaction 函数 |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
const MqlTradeRequest &request,
const MqlTradeResult &result)
{
//--- 获取交易类型作为枚举的值
ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
Print(EnumToString(type));
//--- 如果是一笔成交 — 成交结果添加到历史
if(type==TRADE_TRANSACTION_ORDER_ADD)
{
long order_type =0;
double order_price =0.0;
double order_volume =0.0;
string order_symbol ="";
long order_magic =0;
if(OrderSelect(trans.order)) // 选择挂单
{
order_type=OrderGetInteger(ORDER_TYPE);
order_price=OrderGetDouble(ORDER_PRICE_OPEN);
order_volume=OrderGetDouble(ORDER_VOLUME_INITIAL);
order_symbol=OrderGetString(ORDER_SYMBOL);
order_magic=OrderGetInteger(ORDER_MAGIC);
}
else
return;
if(order_symbol==m_symbol.Name() && order_magic==m_magic)
{
if(order_type==ORDER_TYPE_BUY_LIMIT)
{
LastBuyLimitPrice=order_price;
LastBuyLimitLot=order_volume;
}
if(order_type==ORDER_TYPE_SELL_LIMIT)
{
LastSellLimitPrice=order_price;
LastSellLimitlLot=order_volume;
}
}
}
}
测试品种 EURUSD, M15 自 2015.06.07 至 2016.12.31 — "每笔即时报价" 模式, 初始本金 10000:
由MetaQuotes Ltd译自俄语
原代码: https://www.mql5.com/ru/code/17339