给大家分享turtle和turtle soup tradestation代码(soup未测试过) *************************************************** /// Turtle 20-Day Breakout Replica ////////////////////////////////////// vars: N(0),StopLoss(1),DV(0),BB(0),AccountBalance(0),DollarRisk (0),LTT(0), Tracker(0),LastTrade(0),HBP(0),LBP(0); input: InitialBalance (100000),Length(20); if marketposition = 0 then begin BB = 0; N = xAverage( TrueRange, Length ); DV = N * BigPointValue; AccountBalance = InitialBalance; DollarRisk = AccountBalance * .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,55) or higher; buy LTT shares next bar highest(h,55) + (0.5*N) or higher; buy LTT shares next bar highest(h,55) + (1.0*N) or higher; buy LTT shares next bar highest(h,55) + (1.5*N) or higher; sellshort LTT shares next bar lowest(l,55) or lower; sellshort LTT shares next bar lowest(l,55) - (0.5*N) or lower; sellshort LTT shares next bar lowest(l,55) - (1.0*N) or lower; sellshort LTT shares next bar lowest(l,55) - (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 currentshares = 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 currentshares = 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 currentshares = LTT * 3 then buy LTT shares next bar highest(h,20)[BB] + (1.5*N) or higher; end; // LONG 55 if LastTrade = 1 and marketposition = 1 then begin BB = BB + 1; if currentshares = LTT then begin buy LTT shares next bar highest(h,55)[BB] + (0.5*N) or higher; buy LTT shares next bar highest(h,55)[BB] + (1.0*N) or higher; buy LTT shares next bar highest(h,55)[BB]+ (1.5*N) or higher; end; if currentshares = LTT * 2 then begin buy LTT shares next bar highest(h,55)[BB] + (1.0*N) or higher; buy LTT shares next bar highest(h,55)[BB] + (1.5*N) or higher; end; if currentshares = LTT * 3 then buy LTT shares next bar highest(h,55)[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 currentshares = 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 currentshares = 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 currentshares = 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 currentshares = LTT then begin sellshort LTT shares next bar lowest(l,55)[BB] - (0.5*N) or lower; sellshort LTT shares next bar lowest(l,55)[BB] - (1.0*N) or lower; sellshort LTT shares next bar lowest(l,55)[BB] - (1.5*N) or lower; end; if currentshares = LTT * 2 then begin sellshort LTT shares next bar lowest(l,55)[BB] - (1.0*N) or lower; sellshort LTT shares next bar lowest(l,55)[BB] - (1.5*N) or lower; end; if currentshares = LTT * 3 then sellshort LTT shares next bar lowest(l,55)[BB] - (1.5*N) or lower; end; buytocover ("out-B") next bar highest(h,10) or higher; // STOPS if currentshares = (2 * LTT) then StopLoss = DV * 3.5 * LTT; if currentshares = (3 * LTT) then StopLoss = DV * 4.5 * LTT; if currentshares = (4 * LTT) then StopLoss = DV * 5.0 * LTT; setstoploss (StopLoss); // COMMENTARY commentary ("LTT: ",LTT,Newline); commentary ("CurrentShares: ",CurrentShares,Newline); commentary ("StopLoss: ",StopLoss,Newline); commentary ("AccountBalance:",AccountBalance,NewLine); commentary ("LastTrade: ",LastTrade,NewLine); ******************************************************* ******************soup******************************** INPUT:LENGTH(20),PREV(4),ENTRYADD(10 POINTS); VAR:HH(0),LL(0),NEWH(999),NEWL(999),Z(0),LEN(0),CD AYS(0),MP(0), TSSELL(0),TSBUY(99999),LGO(FALSE),SGO(FALSE), REBUY(99999),REBUYLIFE(0),RESELL(0),RESELLLIFE(0); ARRAY:HI[40](0),LO[40](99999); MP=MARKETPOSITION; IF DATACOMPRESSION=1 THEN BEGIN IF CURRENTBAR=1 THEN BEGIN LEN=MINLIST(LENGTH,39); IF LEN<1 THEN LEN=1; END; if D>D[1] then begin for value1=LEN downto 1 begin HI[value1]=HI[value1-1]; LO[value1]=LO[value1-1]; end; end; HI[0]=idhigh; LO[0]=idlow; IF D>D[1] THEN BEGIN CDAYS=CDAYS+1; NEWH=NEWH+1; NEWL=NEWL+1; LGO=TRUE; SGO=TRUE; REBUYLIFE=REBUYLIFE-1; RESELLLIFE=RESELLLIFE-1; HH=HI[LEN];LL=LO[LEN]; FOR Z=1 TO LEN-1 BEGIN IF HI[Z]>HH THEN HH=HI[Z]; IF LO[Z]<LL THEN LL=LO[Z]; END; IF HI[1]=HH THEN NEWH=1; IF LO[1]=LL THEN NEWL=1; END; IF H>=TSBUY[1] THEN BEGIN TSBUY=99999; REBUY=TSBUY[1]; REBUYLIFE=2; END; IF (H>=REBUY[1] AND MP[1]=0) OR REBUYLIFE<=0 THEN BEGIN REBUY=99999; REBUYLIFE=0; END; IF REBUYLIFE>0 AND MP=0 AND MP[1]=0 THEN Buy("TS-ReBuy") Next Bar REBUY STOP; IF L<=TSSELL[1] THEN BEGIN TSSELL=0; RESELL=TSSELL[1]; RESELLLIFE=2; END; IF (L<=RESELL[1] AND MP[1]=0) OR RESELLLIFE<=0 THEN BEGIN RESELL=0; RESELLLIFE=0; END; IF RESELLLIFE>0 AND MP=0 AND MP[1]=0 THEN Sell Short("TS-ReSell") Next Bar RESELL STOP; IF CDAYS>LEN THEN BEGIN IF HH>0 AND NEWH>=PREV AND IDHIGH>HH AND SGO THEN BEGIN TSSELL=HH-ENTRYADD; Sell Short("TS-Sell") Next Bar TSSELL STOP; SGO=FALSE; END; IF LL>0 AND NEWL>=PREV AND IDLOW<LL AND LGO THEN BEGIN TSBUY=LL+ENTRYADD; Buy("TS-Buy") Next Bar TSBUY STOP; LGO=FALSE; END; END; END; Sell("Initial LX") Next Bar IDLOW STOP; Buy to Cover("Initial SX") Next Bar IDHIGH STOP;