【外汇EA】(自动交易系统)EA是什么?及他的工作原理
小明学外汇EA入门 2019-09-08 13:45:35 交流微信号:FX263cn 外汇EA 自动交易系统
{
Print("TakeProfit less than 10");
return (0); // check TakeProfit
}
//----
SEma = iMA(NULL, 0, ShortEma, 0, MODE_EMA, PRICE_CLOSE, 0);
LEma = iMA(NULL, 0, LongEma, 0, MODE_EMA, PRICE_CLOSE, 0);
//----
static int isCrossed = 0;
isCrossed = Crossed(LEma, SEma);
//----
total = OrdersTotal();
if (total < 1)
{
if (isCrossed == 1) // 满足空仓条件,开空仓
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + StopLoss * Point,
Bid - TakeProfit * Point, "EMA_CROSS", 12345, 0, Green);
if (ticket > 0)
{
if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("SELL order opened : ", OrderOpenPrice());
} else
Print("Error opening SELL order : ", GetLastError());
return (0);
}
if (isCrossed == 2) // 满足多仓条件,开多仓
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - StopLoss * Point,
Ask + TakeProfit * Point, "EMA_CROSS", 12345, 0, Red);
if (ticket > 0)
{
if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("BUY order opened : ", OrderOpenPrice());
} else
Print("Error opening BUY order : ", GetLastError());
return (0);
}
return (0);
}
//---- 订单修改,实现动态止盈止损跟踪
for (cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if (OrderType() == OP_SELL) // long position is opened
{
// check for trailing stop
if (TrailingStop > 0)
{
if (Bid - OrderOpenPrice() > Point * TrailingStop)
{
if (OrderStopLoss() < Bid - Point * TrailingStop)
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid - Point * TrailingStop,
OrderTakeProfit(), 0, Green);
return (0);
}
}
}
} else // go to short position
{
// check for trailing stop
if (TrailingStop > 0)
{
if ((OrderOpenPrice() - Ask) > (Point * TrailingStop))
{
if ((OrderStopLoss() > (Ask + Point * TrailingStop)))
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + Point * TrailingStop,
OrderTakeProfit(), 0, Red);
return (0);
}
}
}
}
}
}
//----
return (0);
}
//+------------------------------------------------------------------+
// 移动平均线多空条件判断,
int Crossed(double line1, double line2)
{
static int last_direction = 0;
static int current_direction = 0;
//Don't work in the first load, wait for the first cross!
static bool first_time = true;
if (first_time == true)
{
first_time = false;
return (0);
}
//----
if (line1 > line2)
current_direction = 2; //up 多头市场 上穿做多
if (line1 < line2)
current_direction = 1; //down 空头市场 下穿做空
//----
if (current_direction != last_direction) //changed 多空改变 {
last_direction = current_direction;
return (last_direction);
else return (0); //not changed
}
五、本文结论
从以上的分析,可以知道,所谓EA,就是由电脑模拟交易员的下单操作进行机器交易的过程, 具体步骤如下:
【版权声明】
本文仅代表作者观点,不代表本站立场。Fx263.com对文中陈述、观点判断保持中立,不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证,且不构成任何投资建议,请读者仅作参考,并自行承担全部风险与责任。Fx263.com作为信息内容发布平台,页面展示内容的目的在于传播更多信息,不代表Fx263.com立场;本站会员及自媒体人所发的稿件所载明的信息与本网无关,如文章涉及版权,请联系本站处理。
【风险提示】
请通过正规渠道参与外汇保证金交易。目前通过网络平台提供、参与外汇保证金交易均属非法。请提高意识,谨防损失!外汇、贵金属和差价合约(OTC场外交易)是杠杆产品,存在较高的风险,可能会导致亏损您的投资本金,请理性投资。