if(marketposition==0 and BarsSinceExit>=2)
{
k=Max(1,k0*Power(slowatr[1]/fastatr[1],4));
longstop=Highest(close[1],barssinceexit)-k*atr[BarsSinceExit];
shortstop=Lowest(close[1],BarsSinceExit)+k*atr[BarsSinceExit];
PlotNumeric("shortstop",shortstop,0,yellow);
PlotNumeric("longstop",longstop,0,cyan);
}
以上代码在V5 和 V6里的返回结果不同,且V6中有明显错误。请问如何解决。
a = Highest(close[1],barssinceexit)
if(marketposition==0 and BarsSinceExit>=2)
{ ...}
在if外先赋值了再用
已这样修改过,结果仍然不对,且和V5有很大差别。
if(marketposition==0 and BarsSinceExit>=2)
{
k=Max(1,k0*Power(slowatr[1]/fastatr[1],4));
longstop=Highest(close[1],barssinceexit)-k*atr[BarsSinceExit];
shortstop=Lowest(close[1],BarsSinceExit)+k*atr[BarsSinceExit];
}
If(MarketPosition==1)
{
k=Min(K1,K1*Power(er/waer,4));
//PlotNumeric("k",k);
longstop=Highest(high,BarsSinceEntry)-k*Lowest(atr,BarsSinceEntry);
longstop=Highest(longstop,BarsSinceEntry);
k=Min(p,p*Power(er/waer,4));
stoploss=close[1]-k*atr[1];
If(MarketPosition==-1)
{
k=Min(K1,K1*Power((waer/er),4));
//PlotNumeric("k",Sqr((50/RSIValue[1])));
shortstop=Lowest(low,BarsSinceEntry)+k*Lowest(atr,BarsSinceEntry);
shortstop=Lowest(shortstop,BarsSinceEntry);
k=Min(p,p*Power(waer/er,4));
stoploss=close[1]+k*atr[1];
}
另外这些变量赋值涉及到无持仓、持有多头和持有空头三种状态下的不同计算方法求得,这种写法在V5里是可以正确运行的,但是在V6和TBQ里均计算有误
顶
希望有老师可以来解答一下,谢谢
Highest这种函数不要放在IF语句里,出错是必然
受教了。可是还是请问为何不能用?而且V5里是可以正常使用的。另外请教,如果不能用highest,那应该用啥?谢谢
您好,我检查了一下返回的数据,V6里Highest(close[1],barssinceexit),这里的barssinceexit取到了上上次平仓,而不是最近一次平仓,导致计算错误。可是我不知道该怎么解决这个问题