- 精华
- 0
- 在线时间
- 2 小时
- UID
- 245838
- 积分
- 5
- 帖子
- 4
- 阅读权限
- 10
- 注册时间
- 2017-1-9
- 最后登录
- 2017-1-12
- 精华
- 0
- UID
- 245838
- 积分
- 5
- 帖子
- 4
- 主题
- 1
- 阅读权限
- 10
- 注册时间
- 2017-1-9
- 最后登录
- 2017-1-12
|
发表于 2017-1-12 11:48:24
|显示全部楼层
本人新手,在看了蔡老师的视屏后,尝试做日内交易和止损止盈一起结合是出现了问题。
在编译的时候提示:TradeEndTime 没有被声明 (38行,位置我用红色标出)
Params
Numeric RangeEndTime(930000);
Numeric TradeEndTIime(145500);
Numeric Lots(0);
Vars
NumericSeries UpperBand;
NumericSeries LowerBand;
Numeric MinPoint; // 一个最小变动单位,也就是一跳
Numeric MyEntryPrice; // 开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格
Numeric TakeProfitSet(0); // 止赢设置
Numeric StopLossSet(0); // 止损设置
Numeric MyExitPrice; // 平仓价格
Begin
MinPoint = MinMove*PriceScale; //一个跳的计算
MyEntryPrice = AvgEntryPrice; //开仓均价
If(CurrentBar == 0 or Date <> Date[1])
{
UpperBand = High;
LowerBand = Low;
}
Else if (Time <= RangeEndTime * 0.000001)
{
UpperBand = Max(High,UpperBand);
LowerBand = Min(Low, LowerBand);
}
Else if (Time >= TradeEndTime * 0.000001)
{
Sell(0,Open);
BuyToCover(0,Open);
}
Else
{
If (High >= UpperBand)
Buy(lots,Max(Open,UpperBand));
If (Low <= LowerBand)
SellShort(lots,Min(Open,LowerBand));
}
If(MarketPosition == 1 And BarsSinceEntry >= 1) // 有多仓的情况
{
If(High >= MyEntryPrice + TakeProfitSet*MinPoint) // 止赢条件表达式
{
MyExitPrice = MyEntryPrice + TakeProfitSet*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价即跳空触发,用开盘价代替
Sell(0,MyExitPrice);
}
Else If(Low <= MyEntryPrice - StopLossSet*MinPoint)// 止损条件表达式
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价即跳空触发,则用开盘价代替
Sell(0,MyExitPrice);
}
}Else If(MarketPosition == -1 And BarsSinceEntry >= 1) // 有空仓的情况
{
If(Low <= MyEntryPrice - TakeProfitSet*MinPoint) // 止赢条件表达式
{
MyExitPrice = MyEntryPrice - TakeProfitSet*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价即跳空触发,则用开盘价代替
BuyToCover(0,MyExitPrice);
}Else If(High >= MyEntryPrice + StopLossSet*MinPoint)// 止损条件表达式
{
MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价即跳空触发, 则用开盘价代替
BuyToCover(0,MyExitPrice);
}
}
PlotNumeric("Upperband",Upperband);
PlotNumeric("LowerBand",Lowerband);
End |
|