采用EasyLanguage脚本语言编写:
input: InitialBalance(100000),loss(2),win(4);
variables: N(0),
StopLoss(0),
DV(0),
AccountBalance(0),system(0),
DollarRisk(0),AvgEtyPrice(0),
LTT(0),
Tracker(0),
LastTrade(-1),myprofit(0),
HBP(0),
LBP(0),
Ndays(20);
vars:EtyPrice_L10(0),EtyPrice_L11(0),EtyPrice_L12(0),EtyPrice_L13(0),
EtyPrice_S10(0),EtyPrice_S11(0),EtyPrice_S12(0),EtyPrice_S13(0),
EtyPrice_L20(0),EtyPrice_L21(0),EtyPrice_L22(0),EtyPrice_L23(0),
EtyPrice_S20(0),EtyPrice_S21(0),EtyPrice_S22(0),EtyPrice_S23(0);
/// Turtle 20-Day Breakout //////////////////////////////////////
if marketposition = 0 then
begin
N = AvgTrueRange( 20 );
DV = N * 100;//*BigPointValue;
AccountBalance = InitialBalance + netprofit;
DollarRisk = AccountBalance * 0.01;
LTT = IntPortion( DollarRisk / DV );
StopLoss = 2 * DV * LTT;
HBP = 0;
LBP = 0;
if LastTrade = -1 then
begin
buy( "b-20-1" ) LTT shares next bar highest( h, 20 ) or higher;
EtyPrice_L10 = highest( h, 20 );
buy( "b-20-2" ) LTT shares next bar highest( h, 20 ) + ( 0.5 * N ) or higher;
EtyPrice_L11 = highest( h, 20 ) + ( 0.5 * N );
buy( "b-20-3" ) LTT shares next bar highest( h, 20 ) + ( 1.0 * N ) or higher;
EtyPrice_L12 = highest(h,20) + (1.0*N);
buy( "b-20-4" ) LTT shares next bar highest( h, 20 ) + ( 1.5 * N ) or higher;
EtyPrice_L13 = highest( h, 20 ) + ( 1.5 * N );
sellshort( "s-20-1" ) LTT shares next bar lowest( l, 20 ) or lower;
EtyPrice_S10 = lowest( l, 20 );
sellshort( "s-20-2" ) LTT shares next bar lowest( l, 20 ) - ( 0.5 * N ) or lower;
EtyPrice_S11= lowest( l, 20 ) - ( 0.5 * N );
sellshort( "s-20-3" ) LTT shares next bar lowest( l, 20 ) - ( 1.0 * N ) or lower;
EtyPrice_S12 = lowest( l, 20 ) - ( 1.0 * N );
sellshort( "s-20-4" ) LTT shares next bar lowest( l, 20 ) - ( 1.5 * N ) or lower;
EtyPrice_S13 = lowest( l, 20 ) - ( 1.5 * N );
system = 1;
end;
if LastTrade = 1 then
begin
buy("b-55-1") LTT shares next bar highest(h,55) or higher;
EtyPrice_L20= highest(h,55);
buy("b-55-2") LTT shares next bar highest(h,55) + (0.5*N) or higher;
EtyPrice_L21= highest(h,55)+ (0.5*N);
buy("b-55-3") LTT shares next bar highest(h,55) + (1.0*N) or higher;
EtyPrice_L22= highest(h,55)+ (1.0*N);
buy("b-55-4") LTT shares next bar highest(h,55) + (1.5*N) or higher;
EtyPrice_L23= highest(h,55)+ (1.5*N);
sellshort("s-55-1") LTT shares next bar lowest(l,55) or lower;
EtyPrice_S20= lowest(l,55);
sellshort("s-55-2") LTT shares next bar lowest(l,55) - (0.5*N) or lower;
EtyPrice_S21= lowest(l,55)- (0.5*N) ;
sellshort("s-55-3") LTT shares next bar lowest(l,55) - (1.0*N) or lower;
EtyPrice_S22= lowest(l,55)- (1.0*N) ;
sellshort("s-55-4") LTT shares next bar lowest(l,55) - (1.5*N) or lower;
EtyPrice_S23= lowest(l,55)- (1.5*N) ;
system=2;
end;
end;
if HBP = 0 and LBP = 0 and h > highest( h,19 )[ 1 ] then
begin
Tracker = 1;
HBP = h;
LBP = 0;
end;
if HBP = 0 and LBP = 0 and l < lowest( l,19 )[ 1 ] then
begin
Tracker = -1;
LBP = l ;
HBP = 0;
end;
if Tracker = 1 then
begin
if l < HBP - ( loss * N ) then LastTrade = -1;
if h > HBP + ( win * N ) then LastTrade = 1;
end;
if Tracker = -1 then
begin
if h > LBP + ( loss * N ) then LastTrade = -1;
if l < LBP - ( win * N ) then LastTrade = 1;
end;
////jia cang system 1
if LastTrade = -1 and marketposition = 1 then
begin
if currentshares = LTT then
begin
buy( "b-20-2." ) LTT shares next bar EtyPrice_L11 or higher;
buy( "b-20-3." ) LTT shares next bar EtyPrice_L12 or higher;
buy( "b-20-4." ) LTT shares next bar EtyPrice_L13 or higher;
end;
if currentshares = 2 * LTT then
begin
buy( "b-20-3.." ) LTT shares next bar EtyPrice_L12 or higher;
buy( "b-20-4.." ) LTT shares next bar EtyPrice_L13 or higher;
end;
if currentshares = 3 * LTT then
buy( "b-20-4..." ) LTT shares next bar EtyPrice_L13 or higher;
end;
if LastTrade = -1 and marketposition = -1 then
begin
if currentshares = LTT then
begin
sellshort( "s-20-2." ) LTT shares next bar EtyPrice_S11 stop;
sellshort( "s-20-3." ) LTT shares next bar EtyPrice_S12 stop;
sellshort( "s-20-4." ) LTT shares next bar EtyPrice_S13 stop;
end;
if currentshares = 2 * LTT then
begin
sellshort( "s-20-3.." ) LTT shares next bar EtyPrice_S12 stop;
sellshort( "s-20-4.." ) LTT shares next bar EtyPrice_S13 stop;
end;
if currentshares = 3 * LTT then
sellshort( "s-20-4..." ) LTT shares next bar EtyPrice_S13 stop;
end;
////jia cang system 2
if LastTrade = 1 and marketposition = 1 then begin
if currentshares=LTT then
begin
buy( "b-55-2." ) LTT shares next bar EtyPrice_L21 stop;
buy( "b-55-3." ) LTT shares next bar EtyPrice_L22 stop;
buy( "b-55-4." ) LTT shares next bar EtyPrice_L23 stop;
end;
if currentshares = 2 * LTT then
begin
buy( "b-55-3.." ) LTT shares next bar EtyPrice_L22 stop;
buy( "b-55-4.." ) LTT shares next bar EtyPrice_L23 stop;
end;
if currentshares = 3 * LTT then
buy( "b-55-4..." ) LTT shares next bar EtyPrice_L23 stop;
end;
if LastTrade = 1 and marketposition = -1 then begin
if currentshares = LTT then begin
sellshort( "s-55-2." ) LTT shares next bar EtyPrice_S21 stop;
sellshort( "s-55-3." ) LTT shares next bar EtyPrice_S22 stop;
sellshort( "s-55-4." ) LTT shares next bar EtyPrice_S23 stop;
end;
if currentshares = 2 * LTT then begin
sellshort( "s-55-3.." ) LTT shares next bar EtyPrice_S22 stop;
sellshort( "s-55-4.." ) LTT shares next bar EtyPrice_S23 stop;
end;
if currentshares = 3 * LTT then
sellshort( "s-55-4..." ) LTT shares next bar EtyPrice_S23 stop;
end;
// STOPS
if currentshares = LTT then StopLoss = 2.0 * DV * LTT ;
if currentshares = ( 2 * LTT ) then StopLoss = 3.5 * DV * LTT ;
if currentshares = ( 3 * LTT ) then StopLoss = 4.5 * DV * LTT ;
if currentshares = ( 4 * LTT ) then StopLoss = 5.0 * DV * LTT ;
setstoploss ( stoploss );
//out system
if system = 1 then
begin
if marketposition = 1 then sell( "20_L-exit" ) next bar Lowest( l, 10 ) stop;
if marketposition = -1 then buytocover( "20_S-exit" ) next bar Highest( h, 10 ) stop;
end;
if system = 2 then
begin
if marketposition = 1 then sell( "55_L-exit" ) next bar Lowest( l, 20 ) stop;
if marketposition = -1 then buytocover( "55_S-exit" ) next bar Highest( h, 20 ) stop;
end;
print("date = ", date, " time = ", time);
print("maxconsecwinners = ", maxconsecwinners, " maxconseclosers = ", maxconseclosers, " maxiddrawdown = ", maxiddrawdown);
print("");