//------------------------------------------------------------------------ // 简称: AlligatorTBQ // 名称: 鳄鱼线突破(GitHub开源策略转换版) // 类别: 公式应用 // 类型: 用户应用 // 输出: Void //------------------------------------------------------------------------ // // 来源: https://github.com/ipqhjjybj/future_data_analyse/blob/master/easy_鳄鱼线.tb // 原版语法: 老版 TradeBlazer(Begin/End、NumericSeries) // 转换说明: // 1) Begin/End -> Events/OnInit/OnBar,NumericSeries -> Series; // 2) XAverage 与三条线统一在 If 外计算,避免 2002 警告; // 3) 原版只有开仓、没有任何平仓条件。转换版新增可关闭的离场模块: // enableExit = True 时按“嘴闭合/反向排列”离场;设 False 即完全复现原版只开不平; // 4) 新增可选百分比止损止盈(默认 0 = 关闭),属于转换补充,不是原版逻辑; // 5) PlotNumeric 第 3 个参数按新版语法改为 0(位置占位); // 6) 未在本机 TBQuant 实测编译,EntryPrice() 等函数请编译后核对。 // //------------------------------------------------------------------------ Params Bool isRollover(False); //是否后复权 Bool isRolloverRealPrice(False); //是否映射真实价格 Bool isAutoSwapPosition(False); //是否自动换仓 Bool ignoreSwapSiganlCalc(False); //是否忽略换仓信号计算 Numeric cf(5); //唇线周期 Numeric cm(8); //齿线周期 Numeric cs(13); //鄂线周期 Numeric dCf(3); //唇线平移 Numeric dCm(5); //齿线平移 Numeric dCs(8); //鄂线平移 Numeric lots(1); //每次下单手数 Bool enableExit(True); //新增:嘴闭合/反向排列时离场,False 则完全复现原版 Numeric stopLossPct(0); //新增:百分比止损,0 表示关闭 Numeric takeProfitPct(0); //新增:百分比止盈,0 表示关闭 Vars Natural CodeProperty codePro; Series lipsN(0,2); Series teethN(0,2); Series crocoN(0,2); Series lips(0,2); Series teeth(0,2); Series croco(0,2); Series zui(0,2); Numeric dPrice(0); Numeric dVolume(0); Numeric dStopPrice(0); Defs Numeric Cond_Open(Integer barback = 0) { If(Frequency == "tick") { Return Close[barback]; } Return Open[barback]; } Integer Cond_round_volume(Numeric volume, Numeric price = 0) { Return IntPart(Round(volume / BaseShares(), 0))*BaseShares(); } Events OnReady() { Range[0:DataSourceSize()-1] { GetProperty(codePro); SetBackBarMaxCount(5000); } } OnInit() { Range[0:DataCount()-1] { If(isRollover) { AddDataFlag(Enum_Data_RolloverBackWard()); } If(isRolloverRealPrice) { AddDataFlag(Enum_Data_RolloverRealPrice()); } If(isAutoSwapPosition) { AddDataFlag(Enum_Data_AutoSwapPosition()); } If(ignoreSwapSiganlCalc) { AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); } } } OnBar(ArrayRef indexs) { Range[0:DataSourceSize()-1] { //三条平滑线统一计算,平移用序列回溯实现 lipsN = XAverage(Close, cf); teethN = XAverage(Close, cm); crocoN = XAverage(Close, cs); lips = lipsN[IntPart(dCf)]; teeth = teethN[IntPart(dCm)]; croco = crocoN[IntPart(dCs)]; PlotNumeric("lips", lips, 0, Green); PlotNumeric("teeth", teeth, 0, Red); PlotNumeric("croco", croco, 0, Blue); //嘴的张开方向:1 向上,-1 向下,0 闭合 If(lips > teeth And teeth > croco) { zui = 1; } Else If(lips < teeth And teeth < croco) { zui = 0 - 1; } Else { zui = 0; } dPrice = Cond_Open(); dVolume = Cond_round_volume(lots, dPrice); //原版开仓条件,完全按上一根 Bar 的信号判断 If(zui[1] == 1 And Close[1] > Open[1] And Low[1] > lips[1] And Open() > lips) { Buy(dVolume, dPrice); } If(zui[1] == 0 - 1 And Close[1] < Open[1] And High[1] < lips[1] And Open() < lips) { SellShort(dVolume, dPrice); } //以下为转换补充的离场与止损止盈,原版没有 If(enableExit) { If(MarketPosition > 0 And (zui[1] == 0 - 1 Or lips < teeth)) { Sell(dVolume, dPrice); } If(MarketPosition < 0 And (zui[1] == 1 Or lips > teeth)) { BuyToCover(dVolume, dPrice); } } If(MarketPosition > 0 And stopLossPct > 0) { dStopPrice = EntryPrice() * (100 - stopLossPct) / 100; If(dPrice <= dStopPrice) { Sell(dVolume, dPrice); } } If(MarketPosition < 0 And stopLossPct > 0) { dStopPrice = EntryPrice() * (100 + stopLossPct) / 100; If(dPrice >= dStopPrice) { BuyToCover(dVolume, dPrice); } } If(MarketPosition > 0 And takeProfitPct > 0) { dStopPrice = EntryPrice() * (100 + takeProfitPct) / 100; If(dPrice >= dStopPrice) { Sell(dVolume, dPrice); } } If(MarketPosition < 0 And takeProfitPct > 0) { dStopPrice = EntryPrice() * (100 - takeProfitPct) / 100; If(dPrice <= dStopPrice) { BuyToCover(dVolume, dPrice); } } } } //------------------------------------------------------------------------ // 编译版本 GS2010.12.08 // 版权所有 TradeBlazer Software 2003-2045 // 更改声明 TradeBlazer Software保留对TradeBlazer平台每一版本的TradeBlazer公式修改和重写的权利 //------------------------------------------------------------------------