MC海龟交易法则源码[MC公式]
(2012-11-26 09:11:15)
标签:
mc公式multicharts策略模型程序化交易mc海龟财经 |
分类: MultiCharts(MC)交易策略 |
程序化交易的诞生是以海龟交易法则的出现为里程碑的,
海龟交易法则的诞生是在二十四年前,来处于查德·丹尼斯与威廉·埃克哈特的一个赌博——“伟大的期货交易者究竟是天生的,还是可以后天培养的?”,这个赌博,最终成就了一个传奇性的实验。
丹尼斯将他的交易理念和思想用两周时间传授给他招募来的23个普通人,并像新加坡人养海龟一样训练他们,给他训练的这些交易者取了个名字叫做海龟,他们所使用的交易方法叫做海龟法则。在随后的四年中,海龟们取得了年均复利80%的收益。
下面是海龟交易法则的源代码
源码:
vars: N(0),StopLoss(1),DV(0),BB(0),AccountBalance(0),DollarRisk(0),LTT(0),
Tracker(0),LastTrade(0),HBP(0),LBP(0);
{/// Turtle 20-Day Breakout Replica //////////////////////////////////////}
if marketposition = 0 then begin
BB = 0;
N = AvgTrueRange(20);
AccountBalance = 1000000;
DV = N * BigPointValue;
{AccountBalance = InitialBalance + netprofit;}
DollarRisk = AccountBalance * 0.01;
LTT = IntPortion(DollarRisk/DV);
StopLoss = 2 * DV * LTT;
if LastTrade = -1 then begin
buy LTT shares next bar highest(h,20) or higher;
buy LTT shares next bar highest(h,20) + (0.5*N) or higher;
buy LTT shares next bar highest(h,20) + (1.0*N) or higher;
buy LTT shares next bar highest(h,20) + (1.5*N) or higher;
sellshort LTT shares next bar lowest(l,20) or lower;
sellshort LTT shares next bar lowest(l,20) - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,20) - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,20) - (1.5*N) or lower;
end;
if LastTrade = 1 then begin
buy LTT shares next bar highest(h,50) or higher;
buy LTT shares next bar highest(h,50) + (0.5*N) or higher;
buy LTT shares next bar highest(h,50) + (1.0*N) or higher;
buy LTT shares next bar highest(h,50) + (1.5*N) or higher;
sellshort LTT shares next bar lowest(l,50) or lower;
sellshort LTT shares next bar lowest(l,50) - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,50) - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,50) - (1.5*N) or lower;
end;
end;
{// PREVIOUS TRADE TRACKER}
if HBP = 0 and h > highest(h,19)[1] then begin
Tracker = 1; HBP = h; LBP = 0;
end;
if 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 - (2*N) then LastTrade = -1;
if h > HBP + (4*N) then LastTrade = 1;
end;
if Tracker = -1 then begin
if h > LBP + (2*N) then LastTrade = -1;
if l < LBP - (4*N) then LastTrade = 1;
end;
{// LONG 20 }
if LastTrade = -1 and marketposition = 1 then begin
BB = BB + 1;
if currentcontracts = LTT then begin
buy LTT shares next bar highest(h,20)[BB] + (0.5*N) or higher;
buy LTT shares next bar highest(h,20)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,20)[BB]+ (1.5*N) or higher;
end;
if currentcontracts = LTT * 2 then begin
buy LTT shares next bar highest(h,20)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,20)[BB] + (1.5*N) or higher;
end;
if currentcontracts = LTT * 3 then
buy LTT shares next bar highest(h,20)[BB] + (1.5*N) or higher;
end;
{// LONG 50}
if LastTrade = 1 and marketposition = 1 then begin
BB = BB + 1;
if currentcontracts = LTT then begin
buy LTT shares next bar highest(h,50)[BB] + (0.5*N) or higher;
buy LTT shares next bar highest(h,50)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,50)[BB]+ (1.5*N) or higher;
end;
if currentcontracts = LTT * 2 then begin
buy LTT shares next bar highest(h,50)[BB] + (1.0*N) or higher;
buy LTT shares next bar highest(h,50)[BB] + (1.5*N) or higher;
end;
if currentcontracts = LTT * 3 then
buy LTT shares next bar highest(h,50)[BB] + (1.5*N) or higher;
end;
sell("out-S") next bar lowest(l,10) or lower;
{// SHORT 20 }
if LastTrade = -1 and marketposition = -1 then begin
BB = BB + 1;
if currentcontracts = LTT then begin
sellshort LTT shares next bar lowest(l,20)[BB] - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,20)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,20)[BB] - (1.5*N) or lower;
end;
if currentcontracts = LTT * 2 then begin
sellshort LTT shares next bar lowest(l,20)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,20)[BB] - (1.5*N) or lower;
end;
if currentcontracts = LTT * 3 then
sellshort LTT shares next bar lowest(l,20)[BB] - (1.5*N) or lower;
end;
{// SHORT 55 }
if LastTrade = 1 and marketposition = -1 then begin
BB = BB + 1;
if currentcontracts = LTT then begin
sellshort LTT shares next bar lowest(l,50)[BB] - (0.5*N) or lower;
sellshort LTT shares next bar lowest(l,50)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,50)[BB] - (1.5*N) or lower;
end;
if currentcontracts = LTT * 2 then begin
sellshort LTT shares next bar lowest(l,50)[BB] - (1.0*N) or lower;
sellshort LTT shares next bar lowest(l,50)[BB] - (1.5*N) or lower;
end;
if currentcontracts = LTT * 3 then
sellshort LTT shares next bar lowest(l,50)[BB] - (1.5*N) or lower;
end;
buytocover ("out-B") next bar highest(h,10) or higher;
{// STOPS}
if currentcontracts = (2 * LTT) then StopLoss = DV * 3.5 * LTT;
if currentcontracts = (3 * LTT) then StopLoss = DV * 4.5 * LTT;
if currentcontracts = (4 * LTT) then StopLoss = DV * 5.0 * LTT;
setstoploss (StopLoss);
{// COMMENTARY}
commentary ("LTT: ",LTT,Newline);
commentary ("currentcontracts: ",currentcontracts,Newline);
commentary ("StopLoss: ",StopLoss,Newline);
commentary ("AccountBalance:",AccountBalance,NewLine);
commentary ("LastTrade: ",LastTrade,NewLine);