- 精华
- 0
- 在线时间
- 63 小时
- UID
- 275910
- 积分
- 54
- 帖子
- 34
- 阅读权限
- 30
- 注册时间
- 2019-2-22
- 最后登录
- 2020-4-7
- 精华
- 0
- UID
- 275910
- 积分
- 54
- 帖子
- 34
- 主题
- 16
- 阅读权限
- 30
- 注册时间
- 2019-2-22
- 最后登录
- 2020-4-7
|
我是通过设置当前bar的初始布尔值为false, 做buy或sellshort交易后变成true,
然后止损的条件是当前bar的布尔值还是初始值false时,
但是我编译成功后,还是在K线图中看到了同一个K线上出现sellshort和止损的情况。
这是该如何处理呢?
Vars
Numeric PercentOfRange(0.8);
Numeric UpperLine;
Numeric LowerLine;
Numeric preDAYRange;
Numeric stopLine1;
Numeric stopLine2;
Numeric stopPrice;
Numeric myPrice;
Bool timerange;
Bool THISbar(False);设置当前bar初始值布尔变量为false
Begin
timeRange = time>0.0900 && time<0.1400;
preDAYRange = HighD[1]-LowD[1];
UpperLine = Open+preDAYRange*PercentOfRange;
LowerLine = Open-preDAYRange*PercentOfRange;
stopPrice = AvgEntryPrice;//平均建仓价格
stopLine1 = stopPrice*1.01;
stopLine2 = stopPrice*0.99;
If(MarketPosition==0 &&timeRange&& High>UpperLine){
myPrice=UpperLine;
If(open>myprice){myprice = open;}
Buy(1,myprice);
THISbar==True;//做交易后当前bar布尔值变成true
}
If(marketposition==1&&THISbar==false){//当前bar未做交易时布尔值为初始值false
If(low<=stopLine2){
Sell(0,Min(Low,stopLine2));//多头止损
}
}
If(MarketPosition==0 && timeRange&& Low<LowerLine){
myprice=lowerLine;
If(open<myprice){myprice = open;}
SellShort(1,myprice);
THISbar==True;//做交易后当前bar布尔值变成true
}
If(marketposition==-1&&THISbar==false){//当前bar未做交易时布尔值为初始值false
If(High>=stopLine1){
BuyToCover(0,Max(High,stopLine1));//空头止损
}
}
|
|