- 精华
- 0
- 在线时间
- 19 小时
- UID
- 232390
- 积分
- 11
- 帖子
- 7
- 阅读权限
- 10
- 注册时间
- 2016-4-17
- 最后登录
- 2020-7-29
- 精华
- 0
- UID
- 232390
- 积分
- 11
- 帖子
- 7
- 主题
- 3
- 阅读权限
- 10
- 注册时间
- 2016-4-17
- 最后登录
- 2020-7-29
|
发表于 2018-6-14 16:30:51
|显示全部楼层
本帖最后由 inspirone 于 2018-6-14 21:40 编辑
我在策略中加入了止损,测试时当盘中止损和反向开新仓(我用收盘开仓)发生在同一bar时止损位本应该在盘中发生但系统将止损位移到收盘。这样止损和开新仓都发生在收盘了止损位本应该在盘中的。如何让测试时盘中止损和反向开新仓(我用收盘开仓)发生在同一bar时止损位不给移到收盘。
这是我的策略,红字是后加入的止损。很简单就是10日均线向上收阳做多10日均线向下收阴做空。
Params
Numeric FastLength(10);
Numeric StopLossSet(30); // 止损设置
Vars
NumericSeries AvgValue10;
Numeric MinPoint; // 最小变动单位
Numeric MyEntryPrice; // 开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格
Numeric MyExitPrice; // 平仓价格
Begin
MinPoint = MinMove*PriceScale;
MyEntryPrice = AvgEntryPrice;
AvgValue10 = AverageFC(Close,FastLength);
PlotNumeric("MA1",AvgValue10);
// 集合竞价和小节休息过滤
If(!CallAuctionFilter()) Return;
If( AvgValue10 > AvgValue10[1] && close > close[1] && close > AvgValue10)
{
Buy(1,Close);
}
else If(MarketPosition==1) // 有多仓的情况
{
if(Low <= MyEntryPrice - StopLossSet*MinPoint)// 止损条件表达式
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
Sell(0,MyExitPrice);
}
}
If(AvgValue10 < AvgValue10[1] && close < close[1] && close < AvgValue10)
{
SellShort(1,Close);
}
else if(MarketPosition==-1) // 有空仓的情况
{
if(High >= MyEntryPrice + StopLossSet*MinPoint)// 止损条件表达式
{
MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
BuyToCover(0,MyExitPrice);
}
}
//PlotNumeric("PL",Portfolio_TotalProfit);
End
|
|