[原创]改写一个wh8使用的公式 (文华财经WH8赢智V8.2)

投资者咨询:[原创]改写一个wh8使用的公式 (文华财经WH8赢智V8.2)
来源:文华财经  日期:2018-7-25 13:22
 这个策略可以转化为文华8嘛

Params
Numeric Length(3); //中轨周期、标准差周期、平均通道宽度/平均成交量周期参数
Numeric Offset(2);  //标准差倍数
Numeric TrailStartPct(1);//跟踪止盈启动点,百分点--0.8%
Numeric Param(1);    //通道宽度百分比敞口参数,也是成交量放量参数
Numeric Pcnt(3);//初始固定比例止损,1%
Numeric Direction(1);//方向控制。0:多空都做,1:只做多;-1:只做空。
Numeric Lots(2);
Vars
NumericSeries UpLine;
NumericSeries DownLine;
NumericSeries MidLine;
NumericSeries Range;
NumericSeries AvgRange;
NumericSeries AvgVol;
Numeric Band; 
Numeric MyPrice;

BoolSeries Strailon(False);
BoolSeries Ltrailon(False);

NumericSeries count;
NumericSeries HighAfterEntry;//开仓后出现的最高价
NumericSeries LowAfterEntry;//开仓后出现的最低价

NumericSeries ProfitPcnt1; 
NumericSeries ProfitPcnt2;

NumericSeries PP;
NumericSeries TT;
Begin   
//布林轨
MidLine=AverageFC(Close,Length);
Band=StandardDev(Close,Length,2); 
UpLine=MidLine+Offset*Band;
DownLine=MidLine-Offset*Band; 
PlotNumeric("中轨",MidLine);
PlotNumeric("上轨",UpLine);
PlotNumeric("下轨",DownLine);

//平均通道宽度百分比
Range=2*Offset*Band/MidLine;
AvgRange=AverageFC(Range,Length);

//平均成交量 
AvgVol=AverageFC(V,Length);

//
PP=Min((Entryprice-Lowafterentry)/EntryPrice,0.1);
TT=Min((Highafterentry-Entryprice)/EntryPrice,0.1);//多头跟踪止盈,当盈利小于10%时,如8%时,回落至获利的80%止盈。当盈利大于10%时,立即止盈。
ProfitPcnt1=PP*10; //空头止盈幅度
ProfitPcnt2=TT*10;//多头止盈幅度

//-----------------------------进场--------------------------------------//
//布林开口,成交放量,连续两天突破上轨且创昨天新高
If (currentbar>Length and MarketPosition==0  and Range[1]>param*AvgRange[1] and V[1]>Param*AvgVol[1] and H[1]>Upline[1] and H[2]>Upline[2] and H>=High[1])
MyPrice=Max(O,High[1]);
If(Direction>=0) 
Buy(Lots,MyPrice);     
}  

If (currentbar>Length and MarketPosition==0  and Range[1]>param*AvgRange[1] and V[1]>Param*AvgVol[1] and L[1]<DownLine[1] and L[2]<DownLine[2] and L<=Low[1])
{  
MyPrice=Min(O,Low[1]);
If(Direction<=0)
SellShort(Lots,MyPrice);  
}  
   
//-------------------------------固定比例初始止损-----------------------------//
Myprice=entryprice*(1-Pcnt/100);
If(MarketPosition==1 and low<=Myprice and BarsSinceEntry>0)
{
MyPrice=Min(MyPrice,Open);
if(Myprice-EntryPrice<0)
{
Sell(Lots, Myprice);
Commentary("做多止损");
}
}
Myprice=EntryPrice*(1+Pcnt/100);
If(MarketPosition==-1 and High>=Myprice and BarsSinceEntry>0)
{
Myprice=Max(Myprice,Open);
if(Myprice-EntryPrice>0)
{
BuyToCover(Lots, Myprice);
Commentary("做空止损");
}
}
//---------------------------止盈--------------------------------//
If(MarketPosition==-1)
{   
If(BarsSinceEntry==0)
{
STrailOn=false;
}else 
if (BarsSinceEntry>0)
{
If(Lowafterentry <= EntryPrice*(1-TrailStartPct/100)) //启动止盈点
{
STrailon = True;
}
MyPrice = EntryPrice-(Entryprice-Lowafterentry)*ProfitPcnt1; //空头止盈
If(STrailon and High>=MyPrice)
{  
MyPrice = Max(Open,MyPrice);
BuyToCover(Lots,MyPrice);
Commentary("空头止盈");
}
}
}
 
If(MarketPosition==1)
{   
If(BarsSinceEntry==0)
{
LTrailOn=false;
}else 
if (BarsSinceEntry>0)
{
If(Highafterentry >= EntryPrice*(1+TrailStartPct/100))   //启动止盈点
{
LTrailon = True;
}
MyPrice = EntryPrice+(Highafterentry-EntryPrice)*ProfitPcnt2;  //多头止盈
If(LTrailon and Low<=MyPrice)
{  
MyPrice = Min(Open,MyPrice);
sell(Lots,MyPrice);
Commentary("多头止盈");
}
}
}
//记录入场后的最高价、最低价
If(MarketPosition == 1 and BarsSinceentry == 0)
{
HighAfterEntry = Max(EntryPrice, high);
LowAfterEntry = LowAfterEntry[1];
}else 
If(MarketPosition == -1 and BarsSinceentry == 0)
{
LowAfterEntry = Min(EntryPrice, low);
HighAfterEntry = HighAfterEntry[1];
}else 
if(MarketPosition != 0 and BarsSinceentry >= 1)
{
HighAfterEntry = Max(HighAfterEntry[1], high);
LowAfterEntry = Min(LowAfterEntry[1], low);
}

End
 
技术人员回复
日期:2018-7-25 13:43

不同软件函数机制不同,回测效果可能略有差异,改写参考

 

LENGTH:=3;
OFFSET:=2;
TRAILSTARTPCT:=0.008;
PARAM:=1;
PCNT:=3;
MIDLINE:MA(CLOSE,LENGTH);//求N个周期的收盘价均线,称为布林通道中轨
BAND:=STD(CLOSE,LENGTH);//求M个周期内的收盘价的标准差
UPLINE:MIDLINE+OFFSET*BAND;//布林通道上轨
DOWNLINE:MIDLINE-OFFSET*BAND;//布林通道下轨
//平均通道宽度百分比
RANGE1:=OFFSET*2*BAND/MIDLINE;
AVGRANGE:=MA(RANGE1,LENGTH);
//平均成交量
AVGVOL:=MA(V,LENGTH);
//-----------------------------进场--------------------------------------//
//布林开口,成交放量,连续两天突破上轨且创昨天新高
BARPOS>3&&BKVOL=0&&REF(RANGE1,1)>PARAM*REF(AVGRANGE,1)&&REF(V,1)>PARAM*REF(AVGVOL,1)&&REF(H,1)>REF(UPLINE,1)&&REF(H,2)>REF(UPLINE,2)&&H>=REF(HIGH,1),BK(2);
BARPOS>3&&SKVOL=0&&REF(RANGE1,1)>1*REF(AVGRANGE,1)&&REF(V,1)>1*REF(AVGVOL,1)&&REF(L,1)<REF(DOWNLINE,1)&&REF(L,2)<REF(DOWNLINE,2)&&L<=REF(L,1),SK(2);
//止损、止盈
BKVOL>0&&C<=BKPRICE*(1-3/100)&&ENTRYSIG_PLACE(1)>0&&MIN(BKPRICE*(1-3/100),O)-BKPRICE<0,SP(2);
SKVOL>0&&C>=SKPRICE*(1+3/100)&&ENTRYSIG_PLACE(1)>0&&MAX(SKPRICE*(1+3/100),O)-SKPRICE>0,BP(2);
PP:=MIN((SKPRICE-SKLOW)/SKPRICE,0.1);
TT:=MIN((BKHIGH-BKPRICE)/BKPRICE,0.1);
PROFITPCNT1:=PP*10; //空头止盈幅度
PROFITPCNT2:=TT*10;//多头止盈幅度
SKVOL>0&&SKLOW<=SKPRICE*(1-TRAILSTARTPCT)&&C>SKPRICE-(SKPRICE-SKLOW)*PROFITPCNT1,BP(2);
BKVOL>0&&BKHIGH>=BKHIGH*(1+TRAILSTARTPCT)&&C<BKPRICE+(BKHIGH-BKPRICE)*PROFITPCNT2,SP(2);
MULTSIG(0,0,1,0);