以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 公式模型编写问题提交 (http://weistock.com/bbs/list.asp?boardid=4) ---- exgbdata全局变量莫名变化 (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=96346) |
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 15:39:52 -- exgbdata全局变量莫名变化 斑竹好,问题出在后台程式化交易的实盘过程中。我为了实现在同一个品种上执行同一策略的五组参数(可以视为不同的策略在同一品种上运行),要记录每个策略单独的持仓量和离场价格,因此使用exgbdata类型的全局变量来记录。请参见以下代码。今天下午出现的问题是exgbdata全局变量在未经后台程序改动的情况下自己发生了变化,导致下了本来不该下的单,我找不出原因出在哪里,请帮忙看一下。 整个后台程序的代码都贴在下面。代码中有许多debugfile输出,输出的txt也贴在下面。从txt中可以看出来,在14:55:07.341的时候,5c本来是-4的,表示PTA已经持空仓4手,但是在14:55:07.845的时候,5c莫名其妙变成0了,就是这个导致了在PTA第五组参数上的重复下单,又再下了4手空单。之前的4手空单是14:54:22下的。 另,该策略是在1分钟线上的固定时间轮询,轮询时间是1秒,并且我勾选了后台程式化窗口下方的“不间断监控刷新频率”为500毫秒,所以每半秒跑一次。 恳请帮助!! --------------------------------------------------------- WARNING_DISABLE:4; INPUT: ATRN(15,5,150,1); INPUT: INISTOP(0.5,0.2,2,0.1); INPUT: 1ent(0.4,0.1,1.5,0.2); INPUT: 1ext(2.0,0.5,5,0.3); INPUT: 1inir(0.001,0,0.03,0.001); INPUT: 2ent(0.55,0.1,1.5,0.2); INPUT: 2ext(2.5,0.5,5,0.3); INPUT: 2inir(0.001,0,0.03,0.001); INPUT: 3ent(0.7,0.1,1.5,0.2); INPUT: 3ext(3,0.5,5,0.3); INPUT: 3inir(0.001,0,0.03,0.001); INPUT: 4ent(0.85,0.1,1.5,0.2); INPUT: 4ext(3.6,0.5,5,0.3); INPUT: 4inir(0.001,0,0.03,0.001); INPUT: 5ent(1.0,0.1,1.5,0.2); INPUT: 5ext(4.2,0.5,5,0.3); INPUT: 5inir(0.001,0,0.03,0.001); 1c:= extgbdata(\'PTA1c\'); 1p:= extgbdata(\'PTA1p\'); 1j:= extgbdata(\'PTA1j\'); 2c:= extgbdata(\'PTA2c\'); 2p:= extgbdata(\'PTA2p\'); 2j:= extgbdata(\'PTA2j\'); 3c:= extgbdata(\'PTA3c\'); 3p:= extgbdata(\'PTA3p\'); 3j:= extgbdata(\'PTA3j\'); 4c:= extgbdata(\'PTA4c\'); 4p:= extgbdata(\'PTA4p\'); 4j:= extgbdata(\'PTA4j\'); 5c:= extgbdata(\'PTA5c\'); 5p:= extgbdata(\'PTA5p\'); 5j:= extgbdata(\'PTA5j\'); atr:= stkindi(\'\', \'truedayrange.matr1\',0,6); closeyd:= callstock(stklabel, vtclose, 6, -1); ou1:= closeyd + 1ent * atr; od1:= closeyd - 1ent * atr; ou2:= closeyd + 2ent * atr; od2:= closeyd - 2ent * atr; ou3:= closeyd + 3ent * atr; od3:= closeyd - 3ent * atr; ou4:= closeyd + 4ent * atr; od4:= closeyd - 4ent * atr; ou5:= closeyd + 5ent * atr; od5:= closeyd - 5ent * atr;
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'开始1c=%.0f\',1c);
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'开始2c=%.0f\',2c);
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'开始3c=%.0f\',3c);
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'开始4c=%.0f\',4c);
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'开始5c=%.0f\',5c);
//品种内第1套参数的交易代码
(注:这些代码与下面第五组完全相同,只是编号改了,为避免太长,就删去了)
//品种内第2套参数的交易代码
//品种内第3套参数的交易代码
//品种内第4套参数的交易代码
//品种内第5套参数的交易代码
if 5c > 0 then begin
if close > 5j then 5j := close; //更新极值
if (5j - 5ext * atr) > 5p then 5p := 5j - 5ext * atr; //更新平仓价格
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'tsell前5p=%.0f\',5p); (注:该行代码在第四套漏了没加上,故PTA.txt会看不见这行输出,但是第1、2、3套都有)
if close <= min(ceiling(ou5),ceiling(5p)) then begin //平仓并清零所有全局变量
tsell(1, 5c, mkt);
5j := 0;
5p := 0;
5c := 0;
end;
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'tsell后5c=%.0f\',5c);
extgbdataset(\'PTA5c\', 5c);
extgbdataset(\'PTA5p\', 5p);
extgbdataset(\'PTA5j\', 5j);
end;
if 5c < 0 then BEGIN
if close < 5j then 5j := close; //更新极值
if (5j + 5ext * atr) < 5p then 5p := 5j + 5ext * atr; //更新平仓价格
if close >= max(floor(od5),floor(5p)) then begin
tsellshort(1, abs(5c), mkt);
5j := 0;
5p := 0;
5c := 0;
end;
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'tsellshort后5c=%.0f\',5c);
extgbdataset(\'PTA5c\', 5c);
extgbdataset(\'PTA5p\', 5p);
extgbdataset(\'PTA5j\', 5j);
end;
if 5c = 0 then begin
if close >= floor(ou5) then begin
5j := close;
5p := close - inistop * atr;
5c := round((tasset * 1inir) / (inistop * atr * MULTIPLIER));
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'tbuy前5c=%.0f\',5c);
tbuy(1, 5c, mkt);
extgbdataset(\'PTA5c\', 5c);
extgbdataset(\'PTA5p\', 5p);
extgbdataset(\'PTA5j\', 5j);
end;
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'tbuy后5c=%.0f\',5c);
if close <= ceiling(od5) then begin
5j := close;
5p := close + inistop * atr;
5c := round((tasset * 1inir) / (inistop * atr * MULTIPLIER));
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'tbuyshort前5c=%.0f\',5c);
tbuyshort(1, 5c, mkt);
extgbdataset(\'PTA5c\', -5c);
extgbdataset(\'PTA5p\', 5p);
extgbdataset(\'PTA5j\', 5j);
end;
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'tbuyshort后5c=%.0f\',5c);
end;
debugfile(\'C:\\Users\\95\\Desktop\\New Folder\\程序化\\debugfile\\PTA.txt\',\'PTA运行结束\',0); ----------------------------------------------------------------------------------------------------------------- 2016-04-15 14:55:07.087 开始1c=4 2016-04-15 14:55:07.089 开始2c=4 2016-04-15 14:55:07.091 开始3c=4 2016-04-15 14:55:07.093 开始4c=4 2016-04-15 14:55:07.093 开始5c=-4 2016-04-15 14:55:07.094 tsell前1p=4792 2016-04-15 14:55:07.094 tsell后1c=4 2016-04-15 14:55:07.095 tsell前2p=4770 2016-04-15 14:55:07.095 tsell后2c=4 2016-04-15 14:55:07.098 tsell前3p=4783 2016-04-15 14:55:07.098 tsell后3c=4 2016-04-15 14:55:07.099 tsell后4c=4 2016-04-15 14:55:07.101 tsellshort后5c=-4 2016-04-15 14:55:07.103 PTA运行结束 2016-04-15 14:55:07.335 开始1c=4 2016-04-15 14:55:07.335 开始2c=4 2016-04-15 14:55:07.336 开始3c=4 2016-04-15 14:55:07.336 开始4c=4 2016-04-15 14:55:07.337 开始5c=-4 2016-04-15 14:55:07.337 tsell前1p=4792 2016-04-15 14:55:07.338 tsell后1c=4 2016-04-15 14:55:07.338 tsell前2p=4770 2016-04-15 14:55:07.339 tsell后2c=4 2016-04-15 14:55:07.340 tsell前3p=4783 2016-04-15 14:55:07.340 tsell后3c=4 2016-04-15 14:55:07.341 tsell后4c=4 2016-04-15 14:55:07.341 tsellshort后5c=-4 2016-04-15 14:55:07.341 PTA运行结束 2016-04-15 14:55:07.845 开始1c=4 2016-04-15 14:55:07.846 开始2c=4 2016-04-15 14:55:07.846 开始3c=4 2016-04-15 14:55:07.847 开始4c=4 2016-04-15 14:55:07.847 开始5c=0 2016-04-15 14:55:07.848 tsell前1p=4792 2016-04-15 14:55:07.848 tsell后1c=4 2016-04-15 14:55:07.849 tsell前2p=4770 2016-04-15 14:55:07.850 tsell后2c=4 2016-04-15 14:55:07.851 tsell前3p=4783 2016-04-15 14:55:07.851 tsell后3c=4 2016-04-15 14:55:07.852 tsell后4c=4 2016-04-15 14:55:07.852 tbuy后5c=0 2016-04-15 14:55:07.852 tbuyshort前5c=4 2016-04-15 14:55:07.854 tbuyshort后5c=4 2016-04-15 14:55:07.854 PTA运行结束 2016-04-15 14:55:08.357 开始1c=4 2016-04-15 14:55:08.358 开始2c=4 2016-04-15 14:55:08.358 开始3c=4 2016-04-15 14:55:08.359 开始4c=4 2016-04-15 14:55:08.359 开始5c=-4 2016-04-15 14:55:08.360 tsell前1p=4792 2016-04-15 14:55:08.360 tsell后1c=4 2016-04-15 14:55:08.360 tsell前2p=4770 2016-04-15 14:55:08.361 tsell后2c=4 2016-04-15 14:55:08.362 tsell前3p=4783 2016-04-15 14:55:08.363 tsell后3c=4 2016-04-15 14:55:08.363 tsell后4c=4 2016-04-15 14:55:08.363 tsellshort后5c=-4 2016-04-15 14:55:08.364 PTA运行结束 2016-04-15 14:55:08.845 开始1c=4 2016-04-15 14:55:08.846 开始2c=4 2016-04-15 14:55:08.847 开始3c=4 2016-04-15 14:55:08.847 开始4c=4 2016-04-15 14:55:08.848 开始5c=-4 2016-04-15 14:55:08.848 tsell前1p=4792 2016-04-15 14:55:08.849 tsell后1c=4 2016-04-15 14:55:08.849 tsell前2p=4770 2016-04-15 14:55:08.849 tsell后2c=4 2016-04-15 14:55:08.850 tsell前3p=4783 2016-04-15 14:55:08.850 tsell后3c=4 2016-04-15 14:55:08.851 tsell后4c=4 2016-04-15 14:55:08.851 tsellshort后5c=-4 2016-04-15 14:55:08.851 PTA运行结束 |
||||
-- 作者:yukizzc -- 发布时间:2016/4/15 17:04:07 -- 看程序看不出问题,这个情况您出行的频率怎么样? 程序发我这边下周测试卡看吧 |
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 17:22:34 -- 行,怎么发你? |
||||
-- 作者:yukizzc -- 发布时间:2016/4/15 17:23:07 -- 压缩包私信我把 |
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 17:23:09 -- 这个情况半个月来出现过3次,一般都是正常的 |
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 17:25:49 -- 我给你发fla吧,论坛短信好像不能发附件 |
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 17:27:38 -- 可以加我qq 1544088114 |
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 17:50:32 -- 怎么发压缩包?论坛短信只能发文字 |
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 17:59:00 -- 我在这上传吧,里面还有一个指标公式,也需要导入,因为交易系统会引用。
另,交易系统是根据北京时间写的,如果您本地测试是金字塔时区,需要修改相应的代码。
|
||||
-- 作者:xiebooo -- 发布时间:2016/4/15 18:10:40 -- 还有,请问版主,如果我在后台预警开启的时候,同时在图表上打开了预警品种,该品种的行情上加载了后台预警的条件公式,是否会导致图表交易下单发生? |