tbuyhd1:tbuyholdingex('',stock1,2);
tsellhd1:tsellholdingex('',stock1,2);
tbuyhd2:tbuyholdingex('',stock2,2);
tsellhd2:tsellholdingex('',stock2,2);
if CONDSELLshort and tbuyhd2>0 and tsellhd1>0 then
BEGIN
tsell (1,0,Mkt,0,0,'',stock2),ORDERQUEUE;
tsellshort(1,0,Mkt,0,0,'',stock1),ORDERQUEUE;
end
实际是有持空头STOCK1,多头STOCK2各一手
条件出现了,就是平不了
后台代码无法在图表上下单的,你可以直接用模拟账号在后台测试的,可以使用调试语句把一些关键变量输出出来,作为观察的依据。
http://www.weistock.com/bbs/dispbbs.asp?boardid=4&id=1246&page=1&star=1
这里有后台调试的方法介绍。
stock1:='rb00';
stock2:='rb01';
MID : MA(o,50);//布林中轨
UPPER:MID + 1.25*STD(o,50);//布林上轨
LOWER:MID - 1.25*STD(o,50);//布林下轨
CONDBUY:=l<=LOWER;
CONDSELL:=h>=UPPER;
CONDBUYshort:=h>=UPPER;
CONDSELLshort:=l<=LOWER;
tbuyhd1:tbuyholdingex('',stock1,2);
tsellhd1:tsellholdingex('',stock1,2);
tbuyhd2:tbuyholdingex('',stock2,2);
tsellhd2:tsellholdingex('',stock2,2);
if CONDBUY and tbuyhd1=0 and tsellhd2=0 then
BEGIN
tbuy(1,1,Mkt,0,0,'',stock1),ORDERQUEUE;
tbuyshort (1,1,Mkt,0,0,'',stock2),ORDERQUEUE;
end
if CONDSELL and tbuyhd1>0 and tsellhd2>0 then
BEGIN
tsell (1,0,Mkt,0,0,'',stock1),ORDERQUEUE;
tsellshort(1,0,Mkt,0,0,'',stock2),ORDERQUEUE;
end
if CONDBUYshort and tbuyhd2=0 and tsellhd1=0 then
BEGIN
tbuyshort(1,1,Mkt,0,0,'',stock1),ORDERQUEUE;
tbuy (1,1,Mkt,0,0,'',stock2),ORDERQUEUE;
end
if CONDSELLshort and tbuyhd2>0 and tsellhd1>0 then
BEGIN
tsell (1,0,Mkt,0,0,'',stock2),ORDERQUEUE;
tsellshort(1,0,Mkt,0,0,'',stock1),ORDERQUEUE;
end
帮我看一下是否正确
从代码看写的是套利,语法上没啥问题。只是你这个监控的价格是单一品种的价格吗?
通常套利都会获取一个价差之类的:

此主题相关图片如下:temp.png

来作为开平仓条件的判断的。
其他地方没什么问题。另外输出语句得话,你可以自己尝试加一下,方便观察。
[此贴子已经被作者于2019/4/8 13:23:41编辑过]