是这样调用的: {$I 'Expectancy'} 你的系统代码 ExpectancyScore; 例: {$I 'Expectancy'} var Bar: integer; for Bar := 10 to BarCount - 1 do begin if CrossOver( Bar,#Close, SMASeries( #Close, 20 ) ) then BuyAtclose( Bar, '' ) else if CrossUnder ( Bar,#Close, SMASeries( #Close, 20 ) ) then SellAtClose ( Bar ,LastPosition, '' ); end; ExpectancyScore; 结果可直接再WLD的 commentary window 窗口看到。
代码 var Bar,kSMA,UpBnd,LoBnd,per1:integer; var W:float; {$I 'Expectancy'} W:=1.0; {channel halfwidth,ATR} per1:=40; {period of price and band SMAs} kSMA:=SMASeries(#AverageC,per1); UpBnd:=AddSeries(kSMA,MultiplySeriesValue (ATRSeries(per1),W)); LoBnd:=SubtractSeries(kSMA,MultiplySeriesValue (ATRSeries(per1),W)); for Bar:=per1 to BarCount-1 do begin {Exit trades} if LastPositionActive then begin if PositionLong(LastPosition) then SellAtStop(Bar+1,@kSMA[Bar],LastPosition,''); if PositionShort(LastPosition) then CoverAtStop(Bar+1,@kSMA[Bar],LastPosition,''); end else {Enter trades} begin if @kSMA[Bar]>@kSMA[Bar-1] then {if PriceHigh(Bar)<@UpBnd[Bar] then} BuyAtStop(Bar+1,@UpBnd[Bar],''); if @kSMA[Bar]<@kSMA[Bar-1] then {if PriceLow(Bar)>@LoBnd[Bar] then} ShortAtStop(Bar+1,@LoBnd[Bar],''); end; end; {Plotting} PlotSeries(kSMA,0,#Blue,#Thick); PlotSeries(UpBnd,0,#Blue,#Dotted); PlotSeries(LoBnd,0,#Blue,#Dotted); DrawLabel('Price SMA - solid line',0); Drawlabel('Up/LoBand - dotted line',0); var ex: float; ex := expectancy(); DrawText( 'Expectancy: '+ FloatToStr(ex), 0, 12, 20, #Black, 16 ); 问题出在600022