- 精华
- 0
- 在线时间
- 165 小时
- UID
- 11672
- 积分
- 179
- 帖子
- 59
- 阅读权限
- 40
- 注册时间
- 2010-6-5
- 最后登录
- 2019-5-28
- 精华
- 0
- UID
- 11672
- 积分
- 179
- 帖子
- 59
- 主题
- 19
- 阅读权限
- 40
- 注册时间
- 2010-6-5
- 最后登录
- 2019-5-28
|
写了个简单的代码想看看交易开拓者的运行机制,头根K线开仓,根据前个K线的最低价调整止损
代码如下:
Params
Numeric stoploss(30);
Vars
Bool Con1;
Bool movestop;
NumericSeries longstop;
Begin
Con1 = MarketPosition==0;
//始终开多头入场
if (Con1)
{
Buy(1,Open+10);
longstop=EntryPrice-stoploss;
fileappend("e:\\text.txt"," the entry price is "+Text(EntryPrice));
}
if (MarketPosition==1)
{
movestop=Low[1]-stoploss>=longstop;
if(movestop)
{
longstop=Low[1]-stoploss;
}
Else
{
longstop=longstop[1];
}
FileAppend("e:\\text.txt","the stop number is "+Text(longstop)+" the last low is "+Text(low[1])+" the entry price is "+Text(EntryPrice));
}
End
去看日志文件发现开仓了两次,请帮忙看看,谢谢!
PS:
我的前几行日志如下
the entry price is 25720
the stop number is 25690 the last low is 25225 the entry price is 25720
the entry price is 25300
the stop number is 25690 the last low is 25225 the entry price is 25300
the stop number is 25690 the last low is 25234 the entry price is 25300
the stop number is 25690 the last low is 25319 the entry price is 25300
the stop number is 25690 the last low is 25296 the entry price is 25300 |
|