//------------------------------------------------------------------------// 简称: fishhook_wyf// 名称: fishhook_wyf// 类别: 公式应用// 类型: 用户应用// 输出: Void//------------------------------------------------------------------------Params //此处添加参数 Numeric period(10); Numeric pcgrationthresold(0.02); Numeric wintick(30); Numeric losstick(30); Numeric drawback(0.01); Vars //此处添加变量 Numeric pcg; Global Numeric currentpcg; Global Numeric postarget; Global Numeric pointindex; Global Numeric pointprice; Global Numeric pointdirection(0); Global Bool pointreverseflag(False); Global Bool pointreadflag(False); Global Bool breakflag(False); Global Numeric pointverseindex(0); Global Numeric pointverseprice(0); Global String pointversedate; Global Numeric direction(0); numeric rightrange ; Global numeric StopLossPrice ; Global numeric StopProfitPrice ; Global numeric StopLossPrice2 ; Global numeric Openprice ; Global numeric myEntryPrice ; numeric highprice ; numeric lowprice ; Series<Numeric> AvgTR; Series<Numeric> volume; Global Array<string> sectionarry; Global Array<string> BlackSection; Global Array<string> ChemSection; Global Array<string> AgriSection; Global Array<string> MentalSection; Global Array<string> OilSection; Global integer fund; Global Map<string,integer> fundmoney; String symbol_target; String exgname; Global String ve;Defs //此处添加公式函数 Numeric calcAvg(Numeric a,Numeric b) { return (a+b)/2; }Events //此处实现事件函数 //初始化事件函数,策略运行期间,首先运行且只有一次,应用在订阅数据等操作 OnInit() { BlackSection = [\"rb\", \"hc\", \"i\", \"j\", \"jm\"]; ChemSection = [\"l\", \"v\", \"pp\", \"pg\", \"eb\", \"eg\", \"ma\", \"ta\", \"pf\", \"fg\", \"sa\", \"ru\", \"ur\", \"bu\",\"sp\",\"nr\"]; MentalSection = [\"cu\",\"al\",\"ni\",\"zn\", \"ag\",\"au\", \"ss\", \"sf\", \"sm\"]; AgriSection = [\"a\", \"b\", \"c\", \"cs\", \"m\", \"p\", \"rm\", \"y\", \"oi\", \"cj\", \"ap\"]; OilSection = [\"sc\", \"lu\", \"fu\"]; } //在所有的数据源准备完成后调用,应用在数据源的设置等操作 OnReady() { } //基础数据更新事件函数 OnDic(StringRef dicName,StringRef dicSymbol,DicDataRef dicValue) { } //在新bar的第一次执行之前调用一次,参数为新bar的图层数组 OnBarOpen(ArrayRef<Integer> indexs) { } //Bar更新事件函数,参数indexs表示变化的数据源图层ID数组 OnBar(ArrayRef<Integer> indexs) { If(BarStatus == 0) { symbol_target = lower(SymbolType()); if (ArrayFind(BlackSection,symbol_target)) {fund = 200000;} if (ArrayFind(ChemSection,symbol_target)) {fund = 150000;} if (ArrayFind(MentalSection,symbol_target)) {fund = 100000;} if (ArrayFind(AgriSection,symbol_target)) {fund = 50000;} if (ArrayFind(OilSection,symbol_target)) {fund = 50000;} //fund = 50000; } fund = 150000; volume = Vol(); pcg = close / close[period] - 1; highprice = Highest(close[1],period); lowprice = Lowest(close[1],period); AvgTR = XAverage(TrueRange,period); numeric TurtleUnits = IntPart( (fund/10) /( AvgTR[1] * ContractUnit() * BigPointValue() )); while(min(fund,Portfolio_CurrentEquity()) < TurtleUnits * close * ContractUnit() * MarginRatio()) { TurtleUnits = TurtleUnits * 0.7; } TurtleUnits = IntPart(TurtleUnits); // 对小数取整 TurtleUnits = MIN(TurtleUnits,50); TurtleUnits = MAX(TurtleUnits,2); Commentary(\"wyf:\" + Text(TurtleUnits * close * ContractUnit() * 0.1)); Commentary(\"close - pointprice\" + Text(close - pointprice)); Commentary(\"pointprice\" + Text(pointprice)); Commentary(\"pcg::::\" + Text(pcg)); Numeric ret1 = IIF(breakflag, 0, -1); Numeric ret2 = IIF(pointreverseflag, 0, -1); Commentary(\"pointreverseflag\" + Text(ret2)); Commentary(\"breakflag\" + Text(ret1)); Commentary(\"postarget\" + Text(postarget)); Commentary(\"TurtleUnits:\" + Text(TurtleUnits)); Commentary(\"AvgTR[1]:\" + Text(AvgTR[1])); Commentary(\"pointdirection:\" + Text(pointdirection)); Commentary(\"direction:\" + Text(direction)); Commentary(\"Time\" + Text(Time())); Commentary(\"date\" + Text(Date())); Numeric ret3 = IIF(pcg > currentpcg, 0, -1); Numeric ret4 = IIF(close >= Highest(close[1],period), 0, -1); Commentary(\"pcg > currentpcg\" + Text(ret3)); Commentary(\"close > Highest(close[1],period)\" + Text(ret4)); Commentary(\"Portfolio_CurrentEquity:\" + Text(Portfolio_CurrentEquity())); Commentary(\"BigPointValue:\" + Text(BigPointValue())); Commentary(\"PriceScale:\" + Text(ContractSize())); Commentary(\"pointversedate:\"+(pointversedate)); // 初始逻辑and close >= Highest(close[1],period) if ((not breakflag) and postarget == 0) { if (pcg > pcgrationthresold and close >= highprice) { postarget = 1; currentpcg = pcg; breakflag = True; pointindex = CurrentBar; pointprice = close; pointdirection = 1; pointreadflag = True; Commentary(\"Long\" ); } if (pcg < -pcgrationthresold and close <= lowprice) { postarget = -1; currentpcg = pcg; breakflag = True; pointindex = CurrentBar; pointprice = close; pointdirection = -1; pointreadflag = True; } } // 更新阈值 if (breakflag == True) { // 更新 (close >= Highest(close[1],period)) or (pcg > currentpcg) if ((postarget == 1) and ((close >= highprice) or(pcg > currentpcg) ) and pointreverseflag == False) { postarget = 1; currentpcg = pcg; breakflag = True; pointreadflag = True; pointindex = CurrentBar; pointdirection = 1; pointprice = max(close,pointprice); Commentary(\"LONG update\"); } // 更新 if ((postarget == -1) and (pcg < currentpcg or close < lowprice) and pointreverseflag == False) { postarget = -1; currentpcg = pcg; breakflag = True; pointindex = CurrentBar; pointdirection = -1; pointprice = min(close,pointprice); } // 反转 if (postarget == 1 and pcg < -1 * pcgrationthresold) { postarget = -1; currentpcg = pcg; breakflag = True; pointindex = CurrentBar; pointreadflag = True; pointreverseflag = False; pointprice = close; pointdirection = -1; PRINT(\"LONG Reverse\"); } // 反转 if (postarget == -1 and pcg > 1 * pcgrationthresold) { postarget = 1; currentpcg = pcg; breakflag = True; pointindex = CurrentBar; pointreadflag = True; pointreverseflag = False; pointprice = close; pointdirection = 1; } } // 判断是否反弹 if(pointreadflag and not pointreverseflag) { // 反弹价格必须在一定的范围以内MinMove() * PriceScale() //if ( Abs(close - pointprice) >= 0 * MinMove() * PriceScale() and Abs(close - pointprice) <= 30 * MinMove() * PriceScale()) Commentary(\"回调准备:\"); if ((pointdirection == 1 and close > pointprice * (1 - drawback) ) or (pointdirection == -1 and close <= pointprice * (1 + drawback ))) { if ((pointdirection == 1 and (close < pointprice or close < open)) or (pointdirection == -1 and (close > pointprice or close > open) )) { Commentary(\"回调:\"); pointreverseflag = True; pointverseindex = CurrentBar; pointverseprice = close; pointversedate = Text(Date()); return ; } } } // 反弹太多 if(pointprice!=0) { //if ((pointprice - close) * pointdirection > 30 * MinMove() * PriceScale()) if ((pointprice - close) * pointdirection > pointprice * drawback ) { pointdirection = 0; pointindex = CurrentBar; pointreadflag = False; pointreverseflag = False; breakflag = False; currentpcg = 0; pointprice = 0; postarget = 0; Commentary(\"反弹太多:\"); } } // 准备开仓 if (pointreadflag AND pointreverseflag AND pointprice!=0 AND Text(Date()) > pointversedate) { // longAvgEntryPrice if (high >= pointprice and pointdirection == 1 and MarketPosition == 0) { rightrange = CurrentBar - pointindex ; if (rightrange < period and CurrentBar - pointverseindex >= 1) { //numeric TurtleUnits = max(1, IntPart(100000 / (ContractSize() * close))); Commentary(\"SEND Text:\" + Text(TurtleUnits)); //TurtleUnits = 1; //Buy(0,0); //Buy(1,pointprice); myEntryPrice = IIF(pointprice < Open, Open, pointprice); Buy(TurtleUnits, myEntryPrice); Openprice = myEntryPrice; StopLossPrice = Openprice - 0.25 * (highprice - lowprice); StopProfitPrice = Openprice + 0.25 * (highprice - lowprice); StopProfitPrice = max(StopProfitPrice,close); //StopLossPrice = Openprice - losstick * MinMove() * PriceScale(); //StopProfitPrice = Openprice + wintick * MinMove() * PriceScale(); direction = 1 ; Commentary(\"StopLossPrice:\" + Text(StopLossPrice)); Commentary(\"StopProfitPrice:\" + Text(StopProfitPrice)); /* pointdirection = 0; pointindex = CurrentBar; pointreadflag = False; pointreverseflag = False; breakflag = False; currentpcg = 0; pointprice = 0; postarget = 0; pointreadflag = False ; pointreverseflag = False; */ //return ; } else { pointdirection = 0; pointindex = CurrentBar; pointreadflag = False; pointreverseflag = False; breakflag = False; currentpcg = 0; pointprice = 0; postarget = 0; pointreadflag = False ; pointreverseflag = False; direction = 0; Commentary(\"时间太长:\"+Text(StopProfitPrice)); } } // short if (Low <= pointprice and pointdirection == -1 and MarketPosition == 0) { rightrange = CurrentBar - pointindex; if (rightrange < period and CurrentBar - pointverseindex >= 1) { //numeric unit = max(1, IntPart(1000000 / (ContractSize() * close))); //TurtleUnits = 1; myEntryPrice = IIF(pointprice > Open, Open, pointprice); SellShort(TurtleUnits, myEntryPrice); Openprice = myEntryPrice; StopLossPrice = Openprice + 0.25 * (highprice - lowprice); StopProfitPrice = Openprice - 0.25 * (highprice - lowprice); StopProfitPrice = min(StopProfitPrice,close); //StopLossPrice = Openprice + losstick * MinMove() * PriceScale(); //StopProfitPrice = Openprice - wintick * MinMove() * PriceScale(); direction = -1 ; Commentary(\"StopLossPrice:\"+Text(StopLossPrice)); Commentary(\"StopProfitPrice:\"+Text(StopProfitPrice)); Commentary(\"myEntryPrice:\"+Text(myEntryPrice)); /* pointdirection = 0; pointindex = CurrentBar; pointreadflag = False; pointreverseflag = False; breakflag = False; currentpcg = 0; pointprice = 0; postarget = 0; pointreadflag =False ; pointreverseflag = False; */ return ; } else { pointdirection = 0; pointindex = CurrentBar; pointreadflag = False; pointreverseflag = False; breakflag = False; currentpcg = 0; pointprice = 0; postarget = 0; pointreadflag =False ; pointreverseflag = False; direction = 0; Commentary(\"时间太长:\"+Text(StopProfitPrice)); } } } //平仓 If(MarketPosition == 1) { //and volume >= Highest(volume[1],period);and volume > Highest(volume[1], period) if (High >= StopProfitPrice or low < StopLossPrice) { Commentary(\"close1:\"); if(low < StopLossPrice ) {Sell(0, StopLossPrice); Commentary(\"stop1:\" +Text(StopLossPrice)); } if (High >= StopProfitPrice) { //Sell(0, StopProfitPrice); StopProfitPrice = StopProfitPrice + wintick * MinMove() * PriceScale(); StopProfitPrice = max(StopProfitPrice, close); StopLossPrice = StopProfitPrice - 1 * losstick * MinMove() * PriceScale(); /* if (close > StopProfitPrice) { StopProfitPrice = max(close,StopProfitPrice); StopLossPrice = StopProfitPrice - 2 * losstick * MinMove() * PriceScale(); } */ Commentary(\"profit:\"); Commentary(\"StopProfitPrice:\" + Text(StopProfitPrice)); } direction = 0 ; pointdirection = 0; pointindex = CurrentBar; pointreadflag = False; pointreverseflag = False; breakflag = False; currentpcg = 0; pointprice = 0; postarget = 0; Commentary(\"close2:\"); } } If(MarketPosition == -1) { if (Low < StopProfitPrice or High > StopLossPrice ) { if (High > StopLossPrice) {BuyToCover(0, StopLossPrice);} if (low < StopProfitPrice) { Commentary(\"profit:\"); StopProfitPrice = StopProfitPrice - wintick * MinMove() * PriceScale(); StopProfitPrice = min(StopProfitPrice, close); StopLossPrice = StopProfitPrice + 1 * losstick * MinMove() * PriceScale(); Commentary(\"StopProfitPrice:\" + Text(StopProfitPrice)); Commentary(\"StopLossPrice:\" + Text(StopLossPrice)); /* if (close < StopProfitPrice) { StopProfitPrice = Min(close,StopProfitPrice);; StopLossPrice = StopProfitPrice + 2 * losstick * MinMove() * PriceScale(); } */ } direction = 0 ; pointdirection = 0; pointindex = CurrentBar; pointreadflag = False; pointreverseflag = False; breakflag = False; currentpcg = 0; pointprice = 0; postarget = 0; } } Commentary(\"pointprice111111:::\" + Text(pointprice)); Commentary(\"StopProfitPrice:\" + Text(StopProfitPrice)); Commentary(\"StopLossPrice:\" + Text(StopLossPrice)); Commentary(\"pointreverseflag\" + Text(ret2)); Commentary(\"CurrentBar - pointverseindex :\" + Text(CurrentBar - pointverseindex)); } //下一个Bar开始前,重新执行当前bar最后一次,参数为当前bar的图层数组 OnBarClose(ArrayRef<Integer> indexs) { } //Tick更新事件函数,需要SubscribeTick函数订阅后触发,参数evtTick表示更新的tick结构体 OnTick(TickRef evtTick) { } //持仓更新事件函数,参数pos表示更新的持仓结构体 OnPosition(PositionRef pos) { } //策略账户仓更新事件函数,参数pos表示更新的账户仓结构体 OnStrategyPosition(PositionRef pos) { } //委托更新事件函数,参数ord表示更新的委托结构体 OnOrder(OrderRef ord) { } //成交更新事件函数,参数ordFill表示更新的成交结构体 OnFill(FillRef ordFill) { } //定时器更新事件函数,参数id表示定时器的编号,millsecs表示定时间的间隔毫秒值 OnTimer(Integer id,Integer intervalMillsecs) { } //通用事件触发函数,参数evtName为事件名称,参数evtValue为事件内容 OnEvent(StringRef evtName,MapRef<String,String> evtValue) { } //当前策略退出时触发 OnExit() { } 这是源代码,麻烦帮我看看,为什么昨晚sc会发多单交易,之后又显示没有信号,监视器里提示信号匹配//------------------------------------------------------------------------// 编译版本 2024-01-03 130948// 版权所有 wyf15158043478// 更改声明 TradeBlazer Software保留对TradeBlazer平台// 每一版本的TradeBlazer公式修改和重写的权利//------------------------------------------------------------------------
回复:代码分析问题请看置顶帖发邮件投稿