tb公式想改文华wh8 [文华财经]
-
咨询内容:
ParamsNumeric Length1(88); //均线 Numeric LEntry(25); //进场M根K线最高点 Numeric LSell(48); //进场n根K线最低点 Numeric StopPCT(0.1); //固定比例止损 Numeric FixXIELV(27); //斜率界定 Numeric FixJump(1); Numeric TrailingStart1(10); // 跟踪止损启动设置1 Numeric TrailingStop1(10); // 跟踪止损设置1
Numeric TrailingStart2(100); // 跟踪止损启动设置1 Numeric TrailingStop2(60); // 跟踪止损设置1 Numeric KaiD(-20); Numeric KaiK(-40);
vars Numeric XIELV; //MA斜率,用于过滤 NumericSeries MA1; //MA均线,用于过滤信号 NumericSeries ShortStop; NumericSeries LongStop; NumericSeries EntryHi; NumericSeries EntryLo; NumericSeries SellHi; NumericSeries SellLo; NumericSeries TradeNum; //记录信号开始天数 Numeric MinPoint; // 一个最小变动单位,也就是一跳 Numeric MyEntryPrice; // 开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格 Numeric MyExitPrice; // 平仓价格 NumericSeries HighestAfterEntry; // 开仓后出现的最高价 NumericSeries LowestAfterEntry; // 开仓后出现的最低价
begin MinPoint=MinMove*PriceScale; //Length1均线 MA1=Summation(Close,Length1)/Length1; PlotNumeric("MA1",MA1); //入场点,开多和开空点,突破LEntry天最高或最低 EntryHi = Highest(high[1],LEntry); EntryLo = Lowest(low[1],LEntry); //离场点,止盈点,LSell天较高或较低 SellHi=Highest(high[1],LSell); SellLo= Lowest(low[1],LSell); if (BarStatus==0 || TradeNum >=3) { TradeNum = -1; } if(Time!=Time[1] && tradenum>=0) { TradeNum = TradeNum[1]+1; } If(BarsSinceentry == 0) { HighestAfterEntry = Close; LowestAfterEntry = Close; If(MarketPosition <> 0) { HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice); // 开仓的Bar,将开仓价和当时的收盘价的较大值保留到HighestAfterEntry LowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice); // 开仓的Bar,将开仓价和当时的收盘价的较小值保留到LowestAfterEntry } }else { HighestAfterEntry = Max(HighestAfterEntry,High); // 记录下当前Bar的最高点,用于下一个Bar的跟踪止损判断 LowestAfterEntry = Min(LowestAfterEntry,Low); // 记录下当前Bar的最低点,用于下一个Bar的跟踪止损判断 } Commentary("MAID:"+Text(((High -MA1[1])*10000/MA1[1])-FixXIELV)); Commentary("MAIK:"+Text(((Low -MA1[1])*10000/MA1[1])-FixXIELV)); if(MarketPosition ==0 and TradeNum<0 ) { If( high>EntryHi && (((High -MA1[1])*10000/MA1[1])-FixXIELV) >KaiD )////CrossOver(high,EntryHi) high>MA1 && { TradeNum = 0; myEntryPrice = min(high,EntryHi ); myEntryPrice = IIF(myEntryPrice < Open, Open,myEntryPrice); Buy(0,myEntryPrice+FixJump*MinPoint); //止损点,两天较低 //LongStop=low[1]; LongStop=Max(Highest(low[1],2),myEntryPrice*(1-StopPCT/100)); } If( Low<EntryLo && (((Low -MA1[1])*10000/MA1[1])+FixXIELV)< KaiK) //// CrossUnder(Low,EntryLo) low <MA1 && { TradeNum = 0; myEntryPrice = max(low,EntryLo ); myEntryPrice = IIF(myEntryPrice > Open, Open,myEntryPrice); SellShort(0,myEntryPrice-FixJump*MinPoint); //止损点,两天较高 ShortStop= Min(Lowest(high[1],2),myEntryPrice*(1+StopPCT/100)); } } If(MarketPosition ==1) { if (BarsSinceEntry>0 && Low<LongStop) { myExitPrice = max(low,LongStop ); myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); Sell(0,myExitPrice-FixJump*MinPoint); }else if (BarsSinceEntry>0 && Low<SellLo) //(XIELV<0) { myExitPrice = max(low,SellLo ); myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); Sell(0,myExitPrice-FixJump*MinPoint); }else if(HighestAfterEntry[1] >= EntryPrice + TrailingStart2*MinPoint)// 第一级跟踪止损的条件表达式 { If(Low <= HighestAfterEntry[1] - TrailingStop2*MinPoint) { MyExitPrice = Max(Low,HighestAfterEntry[1] - TrailingStop2*MinPoint); myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替 Sell(0,MyExitPrice-FixJump*MinPoint); } }else if(HighestAfterEntry[1] >= EntryPrice + TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式 { If(Low <= HighestAfterEntry[1] - TrailingStop1*MinPoint) { MyExitPrice = Max(Low,HighestAfterEntry[1] - TrailingStop1*MinPoint); myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替 Sell(0,MyExitPrice-FixJump*MinPoint); } }
} If(MarketPosition ==-1) { if(BarsSinceEntry>0 && high>ShortStop) { myExitPrice = min(high,ShortStop ); myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); BuyToCover(0,myExitPrice+FixJump*MinPoint); }else if(BarsSinceEntry>0 && high>SellHi) //(XIELV>0) { myExitPrice = min(high,SellHi); myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); BuyToCover(0,myExitPrice+FixJump*MinPoint); }else if(LowestAfterEntry[1] <= EntryPrice - TrailingStart2*MinPoint)// 第一级跟踪止损的条件表达式 { If(High >= LowestAfterEntry[1] + TrailingStop2*MinPoint) { MyExitPrice = min(high,LowestAfterEntry[1] + TrailingStop2*MinPoint); myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替 BuyToCover(0,MyExitPrice+FixJump*MinPoint); } }else if(LowestAfterEntry[1] <= EntryPrice - TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式 { If(High >= LowestAfterEntry[1] + TrailingStop1*MinPoint) { MyExitPrice = min(high,LowestAfterEntry[1] + TrailingStop1*MinPoint); myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替 BuyToCover(0,MyExitPrice+FixJump*MinPoint); } } } Commentary("TradeNum:"+Text(TradeNum)); Commentary("Time:"+TimeToString(TIME[1])); end来源:程序化99
-
文华技术人员:
WH8是麦语言编写平台,直接改写您的模型是很复杂的
但我们提供MQ软件,兼容了TB的编写方式,您模型进行简单修改,就能在MQ上使用了
您到官网下载mq即可 http://mq.wenhua.com.cn/
代码如下修改
ParamsNumeric Length1(88); //均线Numeric LEntry(25); //进场M根K线最高点Numeric LSell(48); //进场n根K线最低点Numeric FixXIELV(27); //斜率界定Numeric FixJump(1);Numeric TrailingStart1(10); // 跟踪止损启动设置1Numeric TrailingStop1(10); // 跟踪止损设置1Numeric TrailingStart2(100); // 跟踪止损启动设置1Numeric TrailingStop2(60); // 跟踪止损设置1Numeric KaiD(-20); varsNumeric StopPCT; //固定比例止损Numeric XIELV; //MA斜率,用于过滤Numeric KaiK(-40); NumericSeries MA1; //MA均线,用于过滤信号NumericSeries ShortStop;NumericSeries LongStop;NumericSeries EntryHi; NumericSeries EntryLo; NumericSeries SellHi;NumericSeries SellLo; NumericSeries TradeNum;//记录信号开始天数Numeric MinPoint; // 一个最小变动单位,也就是一跳Numeric MyEntryPrice; // 开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格Numeric MyExitPrice;// 平仓价格NumericSeries HighestAfterEntry;// 开仓后出现的最高价NumericSeries LowestAfterEntry; // 开仓后出现的最低价beginStopPCT=0.1;MinPoint=MinMove*PriceScale;MA1=Summation(Close,Length1)/Length1;PlotNumeric("MA1",MA1);EntryHi = Highest(high[1],LEntry);EntryLo = Lowest(low[1],LEntry);SellHi=Highest(high[1],LSell);SellLo= Lowest(low[1],LSell);if (BarStatus==0 || TradeNum >=3){TradeNum = -1;}
if(Time!=Time[1] && tradenum>=0){TradeNum = TradeNum[1]+1;}If(BarsSinceentry == 0){HighestAfterEntry = Close;LowestAfterEntry = Close;If(MarketPosition <> 0){HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice); // 开仓的Bar,将开仓价和当时的收盘价的较大值保留到HighestAfterEntryLowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice); // 开仓的Bar,将开仓价和当时的收盘价的较小值保留到LowestAfterEntry}}else{HighestAfterEntry = Max(HighestAfterEntry,High); // 记录下当前Bar的最高点,用于下一个Bar的跟踪止损判断LowestAfterEntry = Min(LowestAfterEntry,Low);// 记录下当前Bar的最低点,用于下一个Bar的跟踪止损判断}Commentary("MAID:"+Text(((High -MA1[1])*10000/MA1[1])-FixXIELV));Commentary("MAIK:"+Text(((Low -MA1[1])*10000/MA1[1])-FixXIELV));if(MarketPosition ==0 and TradeNum<0 ){If( high>EntryHi && (((High -MA1[1])*10000/MA1[1])-FixXIELV) >KaiD )////CrossOver(high,EntryHi) high>MA1 &&{TradeNum = 0;myEntryPrice = min(high,EntryHi );myEntryPrice = IIF(myEntryPrice < Open, Open,myEntryPrice); Buy(0,myEntryPrice+FixJump*MinPoint);LongStop=Max(Highest(low[1],2),myEntryPrice*(1-StopPCT/100));}If( Low<EntryLo && (((Low -MA1[1])*10000/MA1[1])+FixXIELV)< KaiK) ////CrossUnder(Low,EntryLo) low <MA1 &&{TradeNum = 0;myEntryPrice = max(low,EntryLo );myEntryPrice = IIF(myEntryPrice > Open, Open,myEntryPrice); SellShort(0,myEntryPrice-FixJump*MinPoint);ShortStop= Min(Lowest(high[1],2),myEntryPrice*(1+StopPCT/100));}}If(MarketPosition ==1){if (BarsSinceEntry>0 && Low<LongStop){
myExitPrice = max(low,LongStop );
myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice);
Sell(0,myExitPrice-FixJump*MinPoint);
}else if (BarsSinceEntry>0 && Low<SellLo) //(XIELV<0)
{
myExitPrice = max(low,SellLo );
myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice);
Sell(0,myExitPrice-FixJump*MinPoint);
}else if(HighestAfterEntry[1] >= EntryPrice + TrailingStart2*MinPoint)// 第一级跟踪止损的条件表达式{If(Low <= HighestAfterEntry[1] - TrailingStop2*MinPoint){MyExitPrice = Max(Low,HighestAfterEntry[1] - TrailingStop2*MinPoint);myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替Sell(0,MyExitPrice-FixJump*MinPoint);}}else if(HighestAfterEntry[1] >= EntryPrice + TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式{If(Low <= HighestAfterEntry[1] - TrailingStop1*MinPoint){MyExitPrice = Max(Low,HighestAfterEntry[1] - TrailingStop1*MinPoint);myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替Sell(0,MyExitPrice-FixJump*MinPoint);}}}If(MarketPosition ==-1){if(BarsSinceEntry>0 && high>ShortStop){myExitPrice = min(high,ShortStop );myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice);BuyToCover(0,myExitPrice+FixJump*MinPoint);}else if(BarsSinceEntry>0 && high>SellHi) //(XIELV>0){myExitPrice = min(high,SellHi); myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice);BuyToCover(0,myExitPrice+FixJump*MinPoint);}else if(LowestAfterEntry[1] <= EntryPrice - TrailingStart2*MinPoint)// 第一级跟踪止损的条件表达式{If(High >= LowestAfterEntry[1] + TrailingStop2*MinPoint){MyExitPrice = min(high,LowestAfterEntry[1] + TrailingStop2*MinPoint);myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替BuyToCover(0,MyExitPrice+FixJump*MinPoint);}}else if(LowestAfterEntry[1] <= EntryPrice - TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式{If(High >= LowestAfterEntry[1] + TrailingStop1*MinPoint){MyExitPrice = min(high,LowestAfterEntry[1] + TrailingStop1*MinPoint);myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); // 如果该Bar开盘价有跳空触发,则用开盘价代替BuyToCover(0,MyExitPrice+FixJump*MinPoint);}}}Commentary("TradeNum:"+Text(TradeNum));Commentary("Time:"+TimeToString(TIME[1]));end来源: WWW.CXH99.COM
-
文华客服:
想改成WH8麦语言的 这个TB的交易方式不是很稳定 我实际运行的时候和回测的时候价格老是不一致
-
网友回复:
MQ(wh9)的回测运行机制和wh8一样的,只是模型语言不一样。
回测和运行的一致性,和wh8也是一样的,请放心使用 -
网友回复:
我加载到MQ里没有交易
但是我在TB里是有的
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容