某策略,想实行加减仓,加仓部分如何计算均价,比如最大加仓到6手,那么下列代码如何编写:
比如加仓是这样的代码:
buy(开多 and holding<=5,1,market);
问题:
1,如何计算后面加仓的1-5手的均价?
2,如何计算第一次加仓后至今的最高价?
3,最高价每回撤20跳,平仓1手?
谢谢!
1 avgenterprice
2 nn:=barslast(条件条件 and holding=1);
hh:hhv(h,nn);
3
if mod(hh-h,20)=0 then 平仓1手
1 avgenterprice
2 nn:=barslast(条件条件 and holding=1);
hh:hhv(h,nn);
3
if mod(hh-h,20)=0 then 平仓1手
谢谢,我试试。
第一个问题,我要的是加仓部分的均价,不包含首单。
我知道怎么算了 (avgenterprice*abs(holding)-首单开仓价)/(abs(holding)-1)
另外,浮盈函数openprofit在计算加仓后的浮盈结果是错的