请问下面是实例中为什么已经有了sell, sellshort, buy, buyshort语句, 还要增加 tsellshort(1,cang,mkt,0,0,'800988'),allowrepeat; tbuyshort(1,cang,mkt,0,0,'800988'),allowrepeat; 干嘛?
另外xiadan800988:=cc800988-hold;cang:=min(xiadan800988,abs(hold));这两句分别是什么意思? 下了多少手成交和未成交实际上不是用tholding或者tholdingex来实现吗? 为什么要那么麻烦?
实例见此贴 http://www.weistock.com/bbs/dispbbs.asp?BoardID=10&ID=9112&replyID=&skin=1
//实例一、 K线走完模式的模型
Globalvariable:hold=drawnull;
cc800988:=holding;//这句放在信号稳定的地方
//蓝色部分改为你自己的模型(K线走完模型)
buycond:=count(c>o,2)=2;
sellcond:=count(c<o,2)=2;
if holding>0 and sellcond then sell(1,1,thisclose);
if holding<0 and buycond then sellshort(1,1,thisclose);
if holding=0 and buycond then buy(1,1,thisclose);
if holding=0 and sellcond then buyshort(1,1,thisclose);
drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc800988,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan800988:=cc800988-hold;//xiadan800988等于持仓
if xiadan800988>0.5 then begin//如果有下单的话
cang:=min(xiadan800988,abs(hold));//cang 的意思是仓位
if hold<0 then begin
tsellshort(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平空 %.0f',cang);
end
cang:=xiadan800988+min(hold,0);
if cang>0 then begin
tbuy(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开多 %.0f',cang);
end
end
if xiadan800988<-0.5 then begin
cang:=min(abs(xiadan800988),abs(hold));
if hold>0 then begin
tsell(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平多 %.0f',cang);
end
cang:=abs(xiadan800988)-max(hold,0);
if cang>0 then begin
tbuyshort(1,cang,mkt,0,0,'800988'),allowrepeat;
debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开空 %.0f',cang);
end
end
hold:=cc800988;
图表和后台下单函数只有在符合自己的所属交易环境下,才会执行。
这个问题你自己试一下就知道了,图表中使用后台下单函数是无效的,反之同理。
allowrepeat函数是不断重复委托下单,这个和用户需求有关。市价指令已经是可以保证一定成交的方式了。
他的代码注释中已经说得很清楚了。说白了就是当前holding和上根k对应的holding的差值,间接计算出下单手数。你自己用带入法去分析理解。
麻不麻烦和用户写代码的思路有关。没有为什么。至于用什么方式实现也是用户自己的爱好。
阿火提供的这个模板,你看不懂就不要看了,没多大意义,本身就是个鸡肋的东西。
[此贴子已经被作者于2020/2/13 9:41:21编辑过]
1.不是。常规情况下 同样的一句下单代码 在一个K周期内都只能触发一次。 这样如果有人需要某种反复触发条件 反复下单的情况。那么就只能新很多条件语句才能实现。因此有了allowrepeaz.这样 就不用那么麻烦了。
2.sell 和Tsell 前面是图表的下单语句 后面是后台程序化的语句。阿火这个例子里面的做法 主要是为了让部分客户的简单代码在图表和后台有个对照。复杂的思路 这样混杂肯定不合适的。
3.xiadan800988:=cc800988-hold;cang:=min(xiadan800988,abs(hold));
这个是把虚拟持仓 也就是holding的变化 计算成实际要下单的仓位数量。
如果你是后台程序化,不建议参考这个例子里面的做法。这个例子需要对图表和后台都很了解的情况下,可以参考学习。
不可以。hold就是图表虚拟持仓。 你说的这种方式受策略影响,无法保证图表开仓和后台开仓在手数上的一致性。
如果你基础比较差,建议你不要看这个代码。否者你只会越来越迷糊。
[此贴子已经被作者于2020/2/13 12:20:56编辑过]
hold就是图表虚拟持仓 ,4楼第二段话已经回复过你。
这个模板,压根就不牵扯实际持仓。都是按虚拟持仓holding处理的。
[此贴子已经被作者于2020/2/13 14:31:20编辑过]