MT4自动交易系统实例三
锁仓顺势加码EA源码
#property copyright ""
#property link ""
#include <stdlib.mqh>
extern bool USE_ATR=true;
extern int PercentATR=40; //40% ATR
extern double HedgingLevel=30;
杞人忧天原文译文extern bool AutoTakeProfit=fal;
int start()
{野猫
画盘简笔画Hedge_Assistante();
return(0);
}
//+------------------------------------------------------------------+
void Hedge_Assistante()
{
int i,Tic,Ticket,Hedge,Type;
double TP;
string msg="\n"+"ATR(14)="+iATR(Symbol(),PERIOD_D1,14,0)+"\n"+"dHigh:"+iHigh(Symbol(),PERIOD_D1,0)+" dLow:"+
iLow(Symbol(),PERIOD_D1,0)+"\n"+"AtrHi:"+(iLow(Symbol(),PERIOD_D1,0)+iATR(Symbol(),PERIOD_D1,14,0))+
" AtrLo:"+(iHigh(Symbol(),PERIOD_D1,0)-iATR(Symbol(),PERIOD_D1,14,0));
Comment( msg,Red,10);
//1)仅对于BUY/SELL 手动订单进行止盈, BUY/SELL STOP 和BUY/SELL LIMIT 的手动订单不会进行止盈
//2)GBP/USD 止盈 17点, 其他货币对止盈 10点
if(AutoTakeProfit)
{ for(i=0;i<OrdersTotal();i++)
riad {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==fal) continue;
if(Symbol()==OrderSymbol() && OrderMagicNumber()==0 && OrderProfit()!=0) //找到手动订单张国荣歌曲
{
if(Symbol()=="GBPUSD") TP=17; el TP=10; // GBPUSD takeprofit is 17, other pairs takeprofit is 10
if(OrderType()==OP_BUY )
{
if (Bid-OrderOpenPrice()>=TP*Point)
{
if(OrderClo(OrderTicket(),OrderLots(),Bid,2,0)==true)
包公的故事
屁股长痣 {Alert("Good Job! 自动止盈@",Bid," ",OrderTicket()," ",OrderTakeProfit()," - ",OrderOpenPrice(),
" = ",OrderTakeProfit()-OrderOpenPrice()," X ",OrderLots()," = ",OrderProfit());
return(0);
}
el Alert(OrderTicket()," Clo Order err---->",ErrorDescription(GetLastError()));
}
if (OrderTakeProfit()-OrderOpenPrice()<(TP-1)*Point || OrderTakeProfit()-OrderOpenPrice()>(TP+1)*Point)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+TP*Point,0,0)==true)
{Alert(OrderTicket()," ",Symbol()," Buy=",OrderOpenPrice()," 设置止盈@",OrderOpenPrice()+TP*Point);
Sleep(10000);
}
el Alert(OrderTicket()," ",Symbol()," Modify TakeProfit error---->",ErrorDescription(GetLastError()));
}
}
if(OrderType()==OP_SELL)
{
if (OrderOpenPrice()-Ask>=TP*Point)
{
if(OrderClo(OrderTicket(),OrderLots(),Ask,2,0)==true)
{Alert("Good Job! 自动止盈@",Ask," ",OrderTicket()," ",OrderOpenPrice()," - ",OrderTakeProfit(),
" = ",OrderOpenPrice()-OrderTakeProfit()," X ",OrderLots()," = ",OrderProfit());
return(0);
}
el Alert(OrderTicket()," ",Symbol()," Modify TakeProfit error---->",ErrorDescription(GetLastError()));
}
if (OrderOpenPrice()-OrderTakeProfit()>(TP+1)*Point ||OrderOpenPrice()-OrderTakeProfit()<(TP-1)*Point)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-TP*Point,0,0)==true)
{Alert(OrderTicket()," ",Symbol()," Sell=",OrderOpenPrice()," 设置止盈@",OrderOpenPrice()-TP*Point);
Sleep(10000);
}
el Alert(OrderTicket()," ",Symbol()," Modify TakeProfit error----> ",ErrorDe
scription(GetLastError()));
}
}
}
}
}
//-------------------------------------------------------------------------
if (USE_ATR) HedgingLevel=iATR(NULL,PERIOD_D1,14,0)*PercentATR/100;
el HedgingLevel=HedgingLevel*Point;
//Check all manual order, if no it's countpart hedging order, then creat one
for (i=0;i<OrdersTotal();i++)
灿烂无比{if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==fal) break;
if(Symbol()==OrderSymbol() && OrderMagicNumber()==0 && OrderProfit()!=0/*Actived!*/ ) //it's a manual Order
{
Hedge=0;
Ticket=OrderTicket();
Type=OrderType();
double Lots=OrderLots(),OpenPrice=OrderOpenPrice();
for (int j=i;j<OrdersTotal();j++)