您需要 登录 才可以下载或查看,没有帐号?注册
//+------------------------------------------------------------------+
//| EMA保本追踪止损程序.mq4 |
//| Copyright 2015, metaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright Copyright 2015, metaQuotes Software Corp.
#property link https://www.mql5.com
#property version 1.00
#property strict
//---- input parameters
extern double 平衡止损增加点数=10;
extern double 追踪止损=1;
extern double Magic=0;
extern string 参数说明= ZHUCHAOJIAN
extern double MAPeriod=20; //指数均线周期
extern double CloseSpred = 200; //盈亏平衡后止损离均线的点数
int start()
{
//----
//追踪止损
_MoveStop(Magic, 追踪止损);
//设置止损
_StopLoss(Magic,平衡止损增加点数);
//----
return(0);
}
//+------------------------------------------------------------------+
//| _MoveStop 移动止损函数 function |
//+------------------------------------------------------------------+
int _MoveStop(int MAGIC, int MOVE)//_MoveStop(MAGIC, MOVE);
{
//----
if (MOVE =0) return(0);
double MoveStopPrice;
int Ma=iMA(NULL,5,MAPeriod,0,MODE_EMA,PRICE_CLOSE,1);
for ( int z = OrdersTotal() - 1; z z -- )
{
if ( !OrderSelect( z, SELECT_BY_POS ) )
{
Print( OrderSelect( , z, ,SELECT_BY_POS) - Error # ,GetLastError() );
continue;
}
if (OrderSymbol()!=Symbol())continue;
if (OrderMagicNumber() != MAGIC )continue;
switch (OrderType())
{
case OP_BUY :
{
MoveStopPrice=NormalizeDouble(Ma-CloseSpred*Point,Digits);
if (MoveStopPrice OrderStopLoss() OrderOpenPrice() =OrderStopLoss())
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),MoveStopPrice,OrderTakeProfit(),OrderExpiration()))
{
alert( MoveStop_OrderModify Error # ,GetLastError());
return(-1);
}
}
continue;
}
case OP_SELL:
{
MoveStopPrice=NormalizeDouble(Ma+CloseSpred*Point,Digits);
if (MoveStopPrice OrderStopLoss() OrderOpenPrice() =OrderStopLoss())
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),MoveStopPrice,OrderTakeProfit(),OrderExpiration()))
{
alert( MoveStop_OrderModify Error # ,GetLastError());
return(-1);
}
}
continue;
}
default: continue;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| _MoveStop 移动止损函数 function |
//+------------------------------------------------------------------+
int _StopLoss(int MAGIC, int SL)//_MoveStop(MAGIC, MOVE);
{
//----
if (SL =0) return(0);
double StopLoss;
for ( int z = OrdersTotal() - 1; z z -- )
{
if ( !OrderSelect( z, SELECT_BY_POS ) )
{
Print( OrderSelect( , z, ,SELECT_BY_POS) - Error # ,GetLastError());
continue;
}
if (OrderSymbol()!=Symbol())continue;
if (OrderMagicNumber() != MAGIC )continue;
switch (OrderType())
{
case OP_BUY :
{
StopLoss=NormalizeDouble(OrderOpenPrice()+SL*Point,Digits);
if (Ask-OrderOpenPrice() OrderOpenPrice()-OrderStopLoss() OrderOpenPrice() OrderStopLoss())
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,OrderTakeProfit(),OrderExpiration()))
{
alert( StopLoss_OrderModify Error # ,GetLastError());
}
}
continue;
}
case OP_SELL:
{
StopLoss=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits);
if (OrderOpenPrice()-Bid OrderStopLoss()-OrderOpenPrice() OrderOpenPrice() OrderStopLoss())
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,OrderTakeProfit(),OrderExpiration()))
{
alert( StopLoss_OrderModify Error # ,GetLastError());
}
}
continue;
}
default: continue;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
外汇交易有很大的风险性,本站所有资源均来自网络,请选择使用,如若出现亏损,本站不承担任何责任!