网友回复:
回复 1# qdczy
Params
Numeric Length(26);
Numeric Offset(2);
Vars
NumericSeries UpLine; //上轨
NumericSeries DownLine; //下轨
Numeric MidLine; //中间线
Numeric Band;
BoolSeries Condition1;
BoolSeries Condition2;
BoolSeries Condition3;
BoolSeries Condition4;
NumericSeries WW;
Numeric MA1;
NumericSeries MA2;
Begin
MidLine = AverageFC(Close,Length);//布林中轨:26日均线
Band = StandardDev(Close,Length,2); //收盘价在26日内的标准差
UpLine = MidLine + Offset * Band;//上轨
DownLine = MidLine - Offset * Band; //下轨
PlotNumeric("UpLine",UpLine);
PlotNumeric("DownLine",DownLine);
PlotNumeric("MidLine",MidLine);
WW=UpLine-DownLine; //布林带宽
MA1=AverageFC(CLOSE,22); //22日均线
MA2=AverageFC(CLOSE,99); //99日均线
PlotNumeric("MA1",MA1);
PlotNumeric("MA2",MA2);
Condition1 = CrossOver(MA1,MA2);
Condition2 = CrossUnder(MA1,MA2);
Condition3 = MA2+0.13>MA2[1];
Condition4 = MA2-0.13<MA2[1];
//买开条件:22日均线上叉99日均线、收盘价小于布林上轨、布林带宽小于31、99日均线+0.13大于前一周期99日均线
if (Condition1[1]&&C<UpLine[1]&&WW[1]<31&&Condition3[1])
{
Buy(1,Open);
}
if(Condition2[1])
Sell(0,Open);
//卖开条件:99日均线上叉22日均线、收盘价大于布林下轨、布林带宽小于31、99日均线-0.13小于前一周期99日均线
if (Condition2[1]&&C>DownLine&&WW[1]<31&&Condition4[1])
{
SellShort(1,Open);
}
if(Condition1[1])
BuyToCover(0,Open); |