Params
Numeric bollingerLengths(60);
Numeric Offset(3);
Numeric Lots(1);
Numeric TickSize(1);
Vars
Series<Numeric> MidLine(0);
Numeric Band(0);
Series<Numeric> upBand(0);
Series<Numeric> DownBand(0);
Numeric entryPrice(0);
Numeric stopLossPrice(0);
Numeric stopLossPrice1(0);
Events
OnBar(ArrayRef<Integer> indexs)
{
MidLine = AverageFC(Close,bollingerLengths);
Band = StandardDev(Close,bollingerLengths,2);
upBand = MidLine + Offset*Band;
DownBand = MidLine - Offset*Band;
PlotNumeric(\"MidLine\",MidLine);
PlotNumeric(\"upBand\",upBand);
PlotNumeric(\"DownBand\",DownBand);
If(MarketPosition != 1 And Low <=DownBand[1])
{
entryPrice = Min(Low, DownBand[1]);
Buy(Lots, entryPrice); //开仓
}
If(MarketPosition == 1 And BarsSinceEntry >= 1 And (High - entryPrice) >= 20 * TickSize);
{
stopLossPrice = entryPrice + 1 * TickSize;
If(Low <= stopLossPrice)
{
Sell(1, stopLossPrice);//保本
}
stopLossPrice1 = entryPrice - 30 * TickSize;
If(Low <= stopLossPrice1)
Sell(1, stopLossPrice1);//止损
Else
{
Sell(1,Max(High,UpBand[1]));//止盈
}
}
}
///上面保本止损止盈代码编写错误。想实现:开仓后如果有浮盈20跳,就设开仓+1跳保本。止损30跳。 价格到上轨止盈。请老师指点。
TickSize这个就不规范吧 不能这样定义最小波动的