示例:
假设某投资者是个半自动交易者,手动开仓,自动平仓。那我们如果做到使用tholding呢?
让holding=tholding!!就是让前面有开仓,OK,buy(barpos=datacount-1,实际持仓,market)。
可是在逐周期模式下,tholding只在最后一个周期有值,其余都=0,怎么办?用extgbdata。
完整代码如下:
aa:tholding,linethick0;
bb:=extgbdata('quanju');
if bb>0 then buy(barpos=datacount-1,bb,thisclose);
if aa>0 then
begin
sell(1,0,market);
end
if islastbar then extgbdataset('quanju',aa);
//以上代码可实现 手动开仓,自动平仓。
搜索到以上代码,想加个卖空方向的,写成
aa:tholding,linethick0;
bb:=extgbdata('quanju');
if bb<0 then buyshort(barpos=datacount-1,-bb,thisclose);
if aa<0 then
begin
sellshort(1,0,market);
end
if islastbar then extgbdataset('quanju',aa);
效果是不会自动平仓,请问是什么问题?
bb:=extgbdata('quanju');
这句每次执行的话,会每次都赋值为0吗?不是的话 是什么值?是原来的值吗?
请版主答复一下,谢谢
应该可以吧。采用固定轮询模式
另外我想问一下,如果我把
if aa<0 then
begin
sellshort(1,0,market);
end
改为
if aa<0 then
sellshort(1,0,market);
有什么不同?
一样.