- 精华
- 0
- 在线时间
- 167 小时
- UID
- 71944
- 积分
- 376
- 帖子
- 76
- 阅读权限
- 50
- 注册时间
- 2011-10-16
- 最后登录
- 2020-2-8
- 精华
- 0
- UID
- 71944
- 积分
- 376
- 帖子
- 76
- 主题
- 22
- 阅读权限
- 50
- 注册时间
- 2011-10-16
- 最后登录
- 2020-2-8
|
为何止损语句不起作用呢?哪位大侠帮忙修改一下哦?
Params
Numeric Length1(60);
Numeric lots(1);
Numeric offSetDots(0); // 委托偏移点数
Vars
NumericSeries ma60;
Numeric stopLossPoint(200);//止损设置--亏200元就止损
Numeric MyEntryPrice(0); // 开仓价
Numeric MyExitPrice(0); // 平仓价
Numeric AvgEntryPrice(0);
Begin
ma60 = Average(Close,Length1); //60日均线
If(Close[1] > ma60[1]) //如果Close价格在60线之上,将60线涂成红色,否则涂成绿色
{PlotNumeric("Line",ma60,0,Red,0);}
Else
{PlotNumeric("Line",ma60,0,Green,0); }
If(Open>ma60[1] && Low[1]>ma60[1] )
{
Buy(lots,open);
AvgEntryPrice=open;
}
If(Open<ma60[1] && High[1]<ma60[1] )
{
SellShort(lots,open);
AvgEntryPrice=open;
}
// 止损处理
If(MarketPosition == 1) //若是多头持仓
{
myEntryPrice = AvgEntryPrice; //开仓价
If(low <= myEntryPrice - stopLossPoint) //如果亏了200元
{
myExitPrice = myEntryPrice - stopLossPoint;
If(open < myExitPrice) myExitPrice = open; // 如果该Bar开盘价有跳空,则以开盘价代替
Sell(0,myExitPrice-offSetDots); // 按委托偏移点数止损平多
}
}
else If (MarketPosition == -1) //若是空头持仓
{
myEntryPrice = AvgEntryPrice; //开仓价
If(High >= myEntryPrice + stopLossPoint) //如果亏了200元
{
myExitPrice = myEntryPrice + stopLossPoint;
If(open > myExitPrice) myExitPrice = open; // 如果该Bar开盘价有跳空,则以开盘价代替
BuyToCover(0,myExitPrice+offSetDots); // 按委托偏移点数止损平空
}
}
End
|
|