应要求,将源码附上 -e?n4YO*\
//+------------------------------------------------------------------+ TKbfZw
//| 自动止损、止盈、盈利后移动止损、分批出场.mq4 | {5HQ=&
//| Copyright ?2009, 龙德而隐者 | :cIPX%S
//| | bD3 dT>(+
//+------------------------------------------------------------------+ (Rp5g}b
#property copyright "Copyright 2009 by 龙德而隐者" (&V)D?/hS
#property link "http://www.metaquotes.net/" C
OL"/3r
extern string 自动止损参数="默认打开"; JlawkA
extern bool AutoStoploss=True; #,FXc~ V
extern double stoploss= 22; "(~fl<;
extern string 自动止盈参数="默认打开"; !Htl e %
extern bool AutoTakeProfit=True; {K|ds($ 5
extern double takeprofit=30; %kH,Rl\g
extern string 盈利后移动止损="默认打开"; Xi+l 1xe
extern bool AutoTrailingStop=true; "]=XB0)
extern double TrailingStop = 15; _g D9oK
extern string 分次离场参数="按比例分步撤退"; naeppBo
extern bool Gradually = False; OMab!
extern int GraduallyNum = 3; hu}uc&N)iE
double OriginalLot; s%m?Yh3
//+------------------------------------------------------------------+ /nt%VLms%
//| expert start function| -
s{&_]A~
//+------------------------------------------------------------------+ mVK^gJ3
int start() =^zOM6E1ZF
{ Q%V530
P;
for(int cnt=0;cnt
%Rm`YH?
{ cz$*6P<9J
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) PBwKR D[I
{ Ik=bgEF
_sCzee&uQ
if(OrderSymbol()==Symbol()) 8Urj;KkD
{ UGA``;f
double stp=OrderStopLoss(); r+h$]OJ
double tpt=OrderTakeProfit(); ^VjF W
double OpenPrice = OrderOpenPrice(); -{$L`{|G
Qf}}/k|)k
if (OriginalLot == 0) QY1|:(
{ 14h0$7
OriginalLot=OrderLots(); [-3x *?Ju
} K5\;'.9M
%9T|"\
|6Qn/N$+f
if(OrderType()==OP_BUY) 0JV|wd8j
{ dpB\=
CraduallyBuy (); 0M;aTM
if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0) MtBoX*"
OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,Ask+Point*takeprofit,0,Green); SfGl*2
else QlH,-]N$L
{ kD_616
if (AutoStoploss && stp==0) n4DKLAl
{ CdTE~O<)
OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,OrderTakeProfit(),0,Green); ECLQqjB
} kZ<"hsh,Y'
fwz-)?
if (AutoTakeProfit && tpt==0) :Wd@Qy?;
{ xcE<|0N
:
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+Point*takeprofit,0,Green); d\j[O9W>
} uu;1B.[b
]seOc],4
T6I$7F
if (AutoTrailingStop && ((Bid - OpenPrice) > Point*TrailingStop)) ja+PVf
{ +$
0wBU
if((Bid-stp)>TrailingStop*Point ) ,^uQw/
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); b+e9Pi*\
} c^x5 E`{
} =.ReM_.
} V&Q_iE
/xw}]Fa5
if(OrderType()==OP_SELL) k8E{pc6;
{ %ZM"c
CraduallySell (); ,U?^u%
if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0) NY"+Qw@$
OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,Bid-Point*takeprofit,0,Green); XNQPyZ2@|b
else yyM`J7]J
{ tX~*.W:
if (AutoStoploss && stp==0) vE&K!k`
{ @wcrtf~{)&
OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,OrderTakeProfit(),0,Green); _f"KB=A_x
} 1'f&
if (AutoTakeProfit && tpt==0) r7-H`%.
{ jx14/E+^
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-Point*takeprofit,0,Green); m2[]`Ir^@
} =HjC.h
*yYeqm
if(AutoTrailingStop && ((OpenPrice-Ask) > Point*TrailingStop )) !GnwE
{ ~ DP5Qi
if((stp-Ask)>TrailingStop*Point) OmlM9cXm^4
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Green); QL:Qzr[
} %xA-j]%?ep
} {01^xn.
} /0b7"Kr
baGV]=j
} lib}dk
} pnUL+UYeM
else 2M)E1q|a
{ <?%49
OriginalLot=0; 6=96 ^o*
} =3PZGdWD
!QCErE;r
} ` 5n^DP*X
} 1Se2@WR'
#mD_<@@
Wu/:ES)C
S5r.so
kx;7/fH
ru|*xNXKgC
void CraduallyBuy () OTNI@jQ)
{ `aA)n;{/2u
double OpenPrice = OrderOpenPrice(); ?Ss~!38
double lot=OrderLots(); q
s:TR
xrI9t?QaCb
for (int yi=1;yi<=GraduallyNum;yi++) @LSX@V
{ |:,`dQfw
if (NormalizeDouble((Bid - OpenPrice)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0)) w c\`2(
{ K /%5\h
rq1zvuUx
if (lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2)) 8k+k\V{
{ lkC| g%f
OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Bid,3,CLR_NONE); DghqSL^s
} ` k(Q:
3+q-yP#X
} ;jO+<~YP!
} \Co
Z+
} [Z&<# -
E*kZGHA
@;KvUR/+FE
52^,qP'6
void CraduallySell () Vup|*d2r0E
{ =
C/F26=|
double OpenPrice = OrderOpenPrice(); _1WA:7$C
double lot=OrderLots(); (]10Z8"fJ
0%,?z`UY
for (int yi=1;yi<=GraduallyNum;yi++) QIJ/'72
{ #
@7I
if (NormalizeDouble((OpenPrice - Ask)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0)) H\a\xCP3
{ "|R75m,Id
!DHfw-1K
if (lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2)) +rhBC
V
{ r`RLDN!`
OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Ask,3,CLR_NONE); 0O-"tP8o
} $Zkk14
w@n}DCFt
} zJ:%iL@
} Tks"GlE*D
Q}a(vlZ
}