以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  这个图表程序化要怎么改成后台程序化  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=142442)

--  作者:zqs0595
--  发布时间:2016/11/9 16:30:39
--  这个图表程序化要怎么改成后台程序化

一分钟级别的策略,里面有调15分钟级别的指标

 

input:shakeRate(1,0.3,20,2);  

orderNum:=ROUNDS(ASSET/200/c,0); 

begintime:=(time>010300 and time<031000) or (time>130300 and time<184000);
endtime:=(time>032950 and time<033000) or (time>185950 and time<190000);

VARIABLE:cond:=\'none\';   
VARIABLE:pbxGoldPlus:=\'false\';
VARIABLE:pbxDeadPlus:=\'false\';
VARIABLE:pbxCond:=\'none\';
VARIABLE:pbxCondPre:=\'none\';
VARIABLE:outPrice:=0;

ma10:=ma(c,150);
last2h:=hhv(h,30);
last2l:=llv(l,30);

 

DIFF:=STKINDI(\'\',\'MACD.DIFF\',0,3);
DEA:=STKINDI(\'\',\'MACD.DEA\',0,3);

 

D1:STKINDI(\'\',\'PBX.D1\',0,3);
D2:STKINDI(\'\',\'PBX.D2\',0,3);
Z1:STKINDI(\'\',\'PBX.Z1\',0,3);
Z2:STKINDI(\'\',\'PBX.Z2\',0,3);
C1:STKINDI(\'\',\'PBX.C1\',0,3);
C2:STKINDI(\'\',\'PBX.C2\',0,3);

pbxGoldPlus:=\'false\';
pbxDeadPlus:=\'false\';

 

TR1:=STKINDI(\'\',\'ATR.TR1\',0,3);
ATR:=STKINDI(\'\',\'ATR.ATR\',0,3);

if HOLDING>0 and h>outPrice then outPrice:=h;
if HOLDING<0 and l<outPrice then outPrice:=l;

macdGoldPlus:=CROSS(DIFF,DEA);
macdDeadPlus:=CROSS(DEA,DIFF);

//多头仓位平仓 
if HOLDING>0 and (macdDeadPlus or pbxDeadPlus=\'true\' or endtime or c<ma10 or c<outPrice-2*ATR) then begin
    SELL(1,HOLDING,MARKET); 
end

//空头仓位平仓
if HOLDING<0 and (macdGoldPlus or pbxGoldPlus=\'true\' or endtime or c>ma10 or c>outPrice+2*ATR) then begin
    SELLSHORT(1,HOLDING,MARKET);
end

//开多

if HOLDING=0 and ((DIFF>DEA and pbxGoldPlus=\'true\') or (macdGoldPlus=\'true\' and pbxC))
   and begintime and (c-last2l)*100/last2l<shakeRate then begin
    BUY(1,orderNum,MARKET);

end

//开空  

if HOLDING=0 and ((DIFF<DEA and pbxDeadPlus=\'true\') or (macdDeadPlus=\'true\' and pbxC))
   and begintime and (last2h-c)*100/last2h<shakeRate then begin   
    BUYSHORT(1,orderNum,MARKET);

end

pbxCondPre:=pbxCond;


--  作者:jinzhe
--  发布时间:2016/11/9 16:47:03
--  

input:shakeRate(1,0.3,20,2);  

orderNum:=ROUNDS(ASSET/200/c,0); 

begintime:=(time>010300 and time<031000) or (time>130300 and time<184000);
endtime:=(time>032950 and time<033000) or (time>185950 and time<190000);

globalVARIABLE:cond:=\'none\';   
globalVARIABLE:pbxGoldPlus:=\'false\';
globalVARIABLE:pbxDeadPlus:=\'false\';
globalVARIABLE:pbxCond:=\'none\';
globalVARIABLE:pbxCondPre:=\'none\';
globalVARIABLE:outPrice:=0;

ma10:=ma(c,150);
last2h:=hhv(h,30);
last2l:=llv(l,30);

 

DIFF:=STKINDI(\'\',\'MACD.DIFF\',0,3);
DEA:=STKINDI(\'\',\'MACD.DEA\',0,3);

 

D1:STKINDI(\'\',\'PBX.D1\',0,3);
D2:STKINDI(\'\',\'PBX.D2\',0,3);
Z1:STKINDI(\'\',\'PBX.Z1\',0,3);
Z2:STKINDI(\'\',\'PBX.Z2\',0,3);
C1:STKINDI(\'\',\'PBX.C1\',0,3);
C2:STKINDI(\'\',\'PBX.C2\',0,3);

pbxGoldPlus:=\'false\';
pbxDeadPlus:=\'false\';


 

TR1:=STKINDI(\'\',\'ATR.TR1\',0,3);
ATR:=STKINDI(\'\',\'ATR.ATR\',0,3);

if tbuyHOLDING(0)>0 and h>outPrice then outPrice:=h;
if tsellHOLDING(0)>0 and l<outPrice then outPrice:=l;

macdGoldPlus:=CROSS(DIFF,DEA);
macdDeadPlus:=CROSS(DEA,DIFF);

//多头仓位平仓 
if tbuyHOLDING(0)>0 and (macdDeadPlus or pbxDeadPlus=\'true\' or endtime or c<ma10 or c<outPrice-2*ATR) then begin
    tSELL(1,0,mkT); 
end

//空头仓位平仓
if tsellHOLDING(0)>0 and (macdGoldPlus or pbxGoldPlus=\'true\' or endtime or c>ma10 or c>outPrice+2*ATR) then begin
    tSELLSHORT(1,0,mkt);
end

//开多

if tbuyHOLDING(0)=0 and ((DIFF>DEA and pbxGoldPlus=\'true\') or (macdGoldPlus=\'true\' and pbxC))
   and begintime and (c-last2l)*100/last2l<shakeRate then begin
    tBUY(1,orderNum,mkt);

end

//开空 

if tsellHOLDING(0)=0 and ((DIFF<DEA and pbxDeadPlus=\'true\') or (macdDeadPlus=\'true\' and pbxC))
   and begintime and (last2h-c)*100/last2h<shakeRate then begin   
    tBUYSHORT(1,orderNum,mkt);

end

pbxCondPre:=pbxCond;


--  作者:zqs0595
--  发布时间:2016/11/9 17:00:58
--  
我这个代码会复制成几份,修改参数后分别监控不同的品种,如果用globalVARIABLE,策略间相同的变量会冲突吗?
--  作者:jinzhe
--  发布时间:2016/11/9 17:01:36
--  

不会冲突,机制上和variable差不多,后台里面不会互相冲突


--  作者:zqs0595
--  发布时间:2016/11/10 8:59:41
--  
globalVARIABLE和工具-》数据管理-》全局变量里面的那些有什么区别啊?
--  作者:jinzhe
--  发布时间:2016/11/10 9:08:54
--  
这里的全局变量是全软件通用的,不管是哪个策略获取的全局变量都是同一个
--  作者:jinzhe
--  发布时间:2016/11/10 9:09:59
--  

比如这里的A1,不管在哪个策略里面,用extgbdata(\'A1\') 获取的全局变量一定是同一个值


图片点击可在新窗口打开查看此主题相关图片如下:2.png
图片点击可在新窗口打开查看

--  作者:zqs0595
--  发布时间:2016/11/11 9:21:07
--  

我把上面的这段代码加了一些日志打印,可是一出信号,为什么后台日志不是只打出一条,而是一秒内打出非常多条

//开空  
if EXTGBDATA(\'PBMACD_MA_SELL\')=0 and ((DIFF<DEA and pbxDeadPlus=\'true\') or (macdDeadPlus=\'true\' and pbxC))
   and (last2h-c)*100/last2h<shakeRate then begin   
    TBUYSHORT(1,orderNum,mkt);
    EXTGBDATASET(\'PBMACD_MA_SELL\',orderNum);
    DEBUGFILE2(logFilePath,\'b_pbMacd_MA:甲醇开空\',1,1);
    DEBUGFILE2(logFilePath,\'b_pbMacd_RB:数量=%.0f\',orderNum,1);  
    cond:=\'buy\';
    outPrice:=l;
end

 

2016-11-10 21:50:01.855    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.855    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.855    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.855    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.855    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.855    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.855    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.855    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.855    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.855    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空
2016-11-10 21:50:01.871    b_pbMacd_RB:数量=4
2016-11-10 21:50:01.871    b_pbMacd_MA:甲醇开空


--  作者:jinzhe
--  发布时间:2016/11/11 9:41:51
--  

因为你用的是debugfile2,这个是逐k打印的,后台监控了多少根k线,那么每来一笔行情就会输出对应的多少条件信息

你要用debugfile来输出


--  作者:zqs0595
--  发布时间:2016/11/11 10:03:39
--  
那需不需要在开平仓前面加上IF ISLASTBAR判断来过滤,以免一直下单