1、Numeric RiskRatio(1); / % Risk Per N ( 0 - 100)Numeric ATRLength(20); / 平均波动周期 ATR LengthNumeric boLength(20); / 短周期 BreakOut LengthNumeric fsLength(55); / 长周期 FailSafe LengthNumeric teLength(10); / 离市周期 Trailing Exit LengthBool LastProfitableTradeFilter(True); / 使用入市过滤条件VarsNumeric N; / N 值Numeric
2、TotalEquity; / 按最新收盘价计算出的总资产Numeric TurtleUnits; / 交易单位NumericSeries DonchianHi; / 唐奇安通道上轨,延后1个BarNumericSeries DonchianLo; / 唐奇安通道下轨,延后1个BarNumericSeries fsDonchianHi; / 唐奇安通道上轨,延后1个Bar,长周期NumericSeries fsDonchianLo; / 唐奇安通道下轨,延后1个Bar,长周期Numeric ExitHighestPrice; / 离市时判断需要的N周期最高价Numeric ExitLowestP
3、rice; / 离市时判断需要的N周期最低价Numeric myEntryPrice; / 开仓价格Numeric myExitPrice; / 平仓价格Bool IsEntryThisBar(False); / 当前Bar开过仓Bool IsAddThisBar(False); / 当前Bar有过增仓Bool LastBreakoutWin(False); / 最后一次突破是否盈利Numeric preEntryPrice; / 前一次开仓的价格,存放到全局变量0号位置Numeric preBreakoutType(0); / 前一次突破的方向,1 - LONG , -1 - SHORT 初
4、始值为0,存放到全局变量1号位置Numeric preBreakOutPrice; / 前一次突破的价格,存放到全局变量2号位置BeginIf(BarStatus = 0) SetGlobalVar(0,InvalidNumeric); SetGlobalVar(1,0); SetGlobalVar(2,InvalidNumeric);Else preBreakoutType = GetGlobalVar(1); preBreakOutPrice = GetGlobalVar(2);N = AverageFC(TrueRange,ATRLength);TotalEquity = Current
5、Capital()+ Abs(CurrentContracts()*Close*ContractUnit()*BigPointValue()*MarginRatio();TurtleUnits = (TotalEquity*RiskRatio/100) /(N * ContractUnit()*BigPointValue();TurtleUnits = IntPart(TurtleUnits); / 对小数取整DonchianHi = HighestFC(Close1,boLength);DonchianLo = LowestFC(Close1,boLength);/ 判断最后一次突破是否盈利
6、If(preBreakoutType = 1) If(Close PreBreakOutPrice) LastBreakoutWin = True; Else If(preBreakoutType = -1) If(Close = 1) / 开仓价格取突破上轨+一个价位和最高价之间的较小值,这样能更接近真实情况,并能尽量保证成交 preBreakoutType = 1; preBreakOutPrice = Donchianhi; SetGlobalVar(1,preBreakoutType); SetGlobalVar(2,preBreakOutPrice); myEntryPrice =
7、min(high,DonchianHi + PriceScale*MinMove); myEntryPrice = IIF(myEntryPrice If(SellShort(TurtleUnits,myEntryPrice)/ 长周期突破开仓 Failsafe Breakout pointIf(MarketPosition = 0) fsDonchianHi = HighestFC(Close1,fsLength); fsDonchianLo = LowestFC(Close1,fsLength); If(CrossOver(High,fsDonchianHi) & myEntryPrice = min(high,fsDonchianHi + PriceScale*MinMove); If(CrossUnder(Low,fsDonchianLo) & myEntryPrice = max(low,fsDonchianLo - PriceScale*MinMove);If(MarketPosition = 1) / 有多仓的情况 / 求出持多仓时离市的条件比较值 ExitLowestPrice = LowestFC(Low1,teLength);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1