WLD的Turtle_original_V3.1版要比较复杂些。它使用了两套系统,如果上次交易是亏损的话,那么使用20突破,否则用55突破。可能更符合海龟系统一的原意。而Turtle_original_V2则像是和系统二一样。这是个人理解吧。
Turtle Original V3.1: http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/editsystem?id=35356 Turtle_original_V2: http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/editsystem?id=18357
粘过来供分析用 var ChannelUp, ChannelDn, LongExit, ShrtExit, FailsafeUp, FailsafeDn : integer; var N, L1, S1, L2, S2, L3, S3, L4, S4, SE, LE, LS, SS, FU, FD, Account, Tick: float; var BrktProf : float; var Bar, p, LeadBars, ATRParam, LstPsExBar : integer; var cond20 : boolean; *以上是变量申明,名字说明了一些变量的用途,后缀说明了变量的类型* { Parameters input } ChannelUp := 20 ; ChannelDn := 20 ; LongExit := 10 ; ShrtExit := 10 ; FailsafeUp := 55 ; FailsafeDn := 55 ; ATRParam := 20 ; Account := 1000000 ; //This is the notional account *为变量赋了初值,特别留意其三个通道的意义* { Cosmetics and general info } HideVolume ; PlotStops; EnableNotes(false); tick := GetTick ; *关于GETTICK说明 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=299 * 关于PLOTSTOPS http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=283 * HideVolume Renders the Volume Pane invisible, providing more room to the Prices Pane in the chart. * *WLD的专用函数,可参见其在线帮助 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getpage?page=Help.htm * { Indicators plotting } PlotSeries( HighestSeries( #High, ChannelUp ), 0, #blue, #Thin ); PlotSeries( LowestSeries( #Low, ChannelDn ), 0, #fuchsia, #Thin ); PlotSeries( HighestSeries( #High, FailsafeUp ), 0, #green, #Dotted ); PlotSeries( LowestSeries( #Low, FailsafeDn ), 0, #green, #Dotted ); *相当于多彩K线,细情参见 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getpage?page=TheChart.htm http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=104 * { MAIN CYCLE } *关于此段的功能参见 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getpage?page=SystemsCoding.htm * LeadBars := Trunc(max(FailsafeUp, FailsafeDn)); // Failsafe > Channel and Failsafe > Exit *Trunc的功能是小数转整数 Trunc Trunc( Value: float ): integer; Truncates the decimal portion of the specified floating point and returns an integer. * for Bar := LeadBars to BarCount - 1 do begin SE := Highest( Bar, #High, ShrtExit) + tick ; LE := Lowest( Bar, #Low, LongExit) - tick ; N := ATR( Bar, ATRParam ); // N calculation {关于HIGHEST,ATR http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=133 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=116 } { Entering the first position } if PositionCount = 0 then begin SetShareSize(Int( (Account * 0.01) / (N * GetPointValue))); // Unit L1 := Highest( Bar, #High, ChannelUp); S1 := Lowest( Bar, #Low, ChannelDn); L2 := L1 + 0.5 * N ; S2 := S1 - 0.5 * N ; L3 := L1 + 1.0 * N ; S3 := S1 - 1.0 * N ; L4 := L1 + 1.5 * N ; S4 := S1 - 1.5 * N ; BuyAtStop( Bar + 1, L1, 'L1 ' + FormatFloat( '#0.00', L1)); LS := L1 - 2 * N ; ShortAtStop (Bar + 1, S1, 'S1 ' + FormatFloat( '#0.00', S1)); SS := S1 + 2 * N ; end // of 'if PositionCount = 0 then' {关于SETSHARESIZE, BuyAtStop,ShortAtStop http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=300 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=36 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=55 } { Entering positions next to the first one } else begin if ActivePositionCount=3 then begin BuyAtStop( Bar + 1, L4, 'L4 '+ FormatFloat( '#0.00', L4)); ShortAtStop (Bar + 1, S4, 'S4 '+ FormatFloat( '#0.00', S4)); end; if ActivePositionCount=2 then begin BuyAtStop( Bar + 1, L3, 'L3 '+ FormatFloat( '#0.00', L3)); ShortAtStop (Bar + 1, S3, 'S3 '+ FormatFloat( '#0.00', S3)); end; if ActivePositionCount=1 then begin BuyAtStop( Bar + 1, L2, 'L2 '+ FormatFloat( '#0.00', L2)); ShortAtStop (Bar + 1, S2, 'S2 '+ FormatFloat( '#0.00', S2)); end; if ActivePositionCount = 0 then begin { if cond20 is true, System 1 rules are triggered, otherwise System 2 rules apply. Ref. Faith page 19 cond20 turns true if last traded breakout was unprofitable. Faith rules state that also not traded breakouts should be considered for the purpose of this rule, but this Script is currently limited to those actually traded. } cond20 := false ; BrktProf := 0 ; LstPsExBar := PositionExitBar( LastPosition ); for p := 0 to PositionCount -1 do begin if PositionExitBar( p ) = LstPsExBar then BrktProf := BrktProf + PositionProfit( p ); end ; // Of checking all positions to see if they belong to the last breakout {关于PositionExitBar,LastPosition, PositionCount ,PositionProfit,ActivePositionCount http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=191 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=57 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=62 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=64 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=308 } if BrktProf < 0 then cond20 := true ; {以下是两个系统,系统1和系统2的切换} if cond20 = true then begin SetShareSize(Int( (Account * 0.01) / (N * GetPointValue))); // Unit L1 := Highest( Bar, #High, ChannelUp); S1 := Lowest( Bar, #Low, ChannelDn); L2 := L1 + 0.5 * N ; S2 := S1 - 0.5 * N ; L3 := L1 + 1.0 * N ; S3 := S1 - 1.0 * N ; L4 := L1 + 1.5 * N ; S4 := S1 - 1.5 * N ; BuyAtStop( Bar + 1, L1, 'L1 '+ FormatFloat( '#0.00', L1)); LS := L1 - 2 * N ; ShortAtStop (Bar + 1, S1, 'S1 '+ FormatFloat( '#0.00', S1)); SS := S1 + 2 * N ; end // of cases where cond20 = true else begin SetShareSize(Int( (Account * 0.01) / (N * GetPointValue))); // Unit FU := Highest( Bar, #High, FailsafeUp); FD := Lowest( Bar, #Low, FailsafeDn); L2 := FU + 0.5 * N ; S2 := FD - 0.5 * N ; L3 := FU + 1.0 * N ; S3 := FD - 1.0 * N ; L4 := FU + 1.5 * N ; S4 := FD - 1.5 * N ; BuyAtStop( Bar + 1, FU, 'FU'); LS := FU - 2 * N ; ShortAtStop (Bar + 1, FD, 'FD'); SS := FD + 2 * N ; end; // of cases where cond20 = false end; // of entering positions ActivePositionCount = 0 end; // of buying rules when PositionCount > 0 and ActivePositions = 0 {关于ActivePositionCount http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=308 } { Check for position exit conditions } for p := 0 to PositionCount -1 do begin if PositionActive(p) then if Positionlong(p) then SellAtStop( Bar + 1, LS, p, 'LongStop') else CoverAtStop( Bar + 1, SS, p, 'ShortStop'); if PositionActive(p) then if Positionlong(p) then SellAtStop( Bar + 1, LE, p, 'LongExit') else CoverAtStop( Bar + 1, SE, p, 'ShortExit'); end; // of position exits end; // OF THE MAIN CYCLE {关于CoverAtStop,Positionlong(p),PositionActive(p) http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=40 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=63 http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=59 }
主循环的主体结构 for Bar := LeadBars to BarCount - 1 do begin { Entering the first position } if PositionCount = 0 then begin 。。。。。 end // of 'if PositionCount = 0 then' *未有头寸时的处理方法* { Entering positions next to the first one } else begin //buying rules when PositionCount > 0 if ActivePositionCount=3 then begin 。。。。。。 end; *持有三个头寸时的处理方法* if ActivePositionCount=2 then begin 。。。。。 end; if ActivePositionCount=1 then begin 。。。。。 end; if ActivePositionCount = 0 then begin { if cond20 is true, System 1 rules are triggered, otherwise System 2 rules apply. Ref. Faith page 19 cond20 turns true if last traded breakout was unprofitable. Faith rules state that also not traded breakouts should be considered for the purpose of this rule, but this Script is currently limited to those actually traded. } 。。。。。。 end ; // Of checking all positions to see if they belong to the last breakout if BrktProf < 0 then 。。。; if cond20 = true then begin 。。。。 end // of cases where cond20 = true else begin 。。。。 end; // of cases where cond20 = false end; // of entering positions ActivePositionCount = 0 end; // of buying rules when PositionCount > 0 and ActivePositions = 0 *表示曾经有过头寸,但现在又出完了,因而结束了买入的动作*
主体结构分析 for Bar := LeadBars to BarCount - 1 do begin { Entering the first position } if PositionCount = 0 then begin 。。。。。 end // of 'if PositionCount = 0 then' { Entering positions next to the first one } else begin 。。。。。 end; // of buying rules when PositionCount > 0 and ActivePositions = 0 { Check for position exit conditions } for p := 0 to PositionCount -1 do begin 。。。。。。 end; // of position exits end; // OF THE MAIN CYCLE
Re: 主体结构分析 LeadBars := Trunc(max(FailsafeUp, FailsafeDn)); // Failsafe > Channel and Failsafe > Exit 这是类似空头排列的假设吗? BarCount - 1: In order to work with Price Series properly, you first need to know how many bars of data you have available. Use the native BarCount function to return this information. BarCount: integer; Returns the total number of bars available in the current chart. Remarks The first bar of any chart is Bar Number 0, and the last bar can be found by the expression BarCount - 1. PositionCount:Returns the total number of trading system Positions, both open and closed. http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=62 ActivePositions:Returns the number of active Positions currently being held by the trading system. http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/getdoc?id=308