以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  逐k线计算改成序列  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=143052)

--  作者:tanyongde
--  发布时间:2016/11/21 11:49:06
--  逐k线计算改成序列

逐k线计算改成序列,有问题吗?能显示资金,仓位?只能模拟调试后才能有没问题?


input:p(10,2,200,1);
input:avglen(30,5,100,5);
upperma:ema(high,avglen);
lowerma:ema(low,avglen);

//建立多头的进场条件
long:=open>upperma+mindiff;
if long then begin
tsellshort(tholding<0,0,mkt);
//sellshort(holding<0,0,limitr ,upperma+mindiff);
//sellshort(holding<0,0,marketr);
tbuy(tholding=0,p,mkt);
//buy(holding=0,p, limitr ,upperma+mindiff);
//buy(holding=0,p, marketr);
end
//建立空头的进场条件
short:=open<lowerma-mindiff;
if short then begin
tsell(tholding>0,0,mkt);
//sell(holding>0,0,limitr,lowerma-mindiff);
//sell(holding>0,0,marketr);
tbuyshort(tholding=0,p,mkt);
//buyshort(holding=0,p,limitr,lowerma-mindiff);
//buyshort(holding=0,p,marketr);
end

{持仓:tholding,linethick0;
资产:asset,noaxis;
可用现金:cash(0),linethick0;}



--  作者:jinzhe
--  发布时间:2016/11/21 13:05:44
--  
可以,这段代码里面没有必须要逐k线的函数,这段代码可以用序列计算
--  作者:tanyongde
--  发布时间:2016/11/21 14:42:47
--  


      1.跨周期引用指标线,三个周期开平信号合成一起模板,改成序列计算提示似乎使用逐k线,有问题吗? 
      2 引用其它模块开平仓信号,用stkindi(\'\',\'line.开仓条件\',0,3)引用没信号,只能引用指标线吗?(如下:zline:stkindi(\'\',\'line.line1\',0,3);)
图片点击可在新窗口打开查看此主题相关图片如下:qq截图20161121142504.png
图片点击可在新窗口打开查看
input:cang1(10,0,10,1),cang2(10,0,10,1),cang3(10,0,10,1);
variable:cc1=0,cc2=0,cc3=0;
zh1:\'614251\';
pz1:\'nioo\';
a:=ref(close,1);
line:=ma(a,30);


if not(islastbar) or workmode<>1 then begin
      exit;
      goto continueline@  ;
   end
if islastbar then begin
   if cc1>0 and c<line then begin
    //pc:=min(max(holding,0),cang1);
    pc:=min(tbuyholdingex( zh1,pz1 ,0 ),cang1);
    kc:=cang1-pc;
    //if pc>0 then sell(1,pc,limitr,open-mindiff);
    if pc>0 then tsell(1,pc,mkt,0,zh1,pz1);
    //if kc>0 then buyshort(1,kc,limitr,open+mindiff);
    if kc>0 then tbuyshort(1,kc,mkt,0,zh1,pz1);
    cc1:=0;
   end
  if cc1<0 and c>line  then begin
   // pc:=min(abs(min(holding,0)),cang1);
    pc:=min(abs(tsellholdingex( zh1,pz1 ,0 )),cang1);
    kc:=cang1-pc;
    //if pc>0 then sellshort(1,pc,limitr,open+mindiff);
    if pc>0 then tsellshort(1,pc,mkt,0,zh1,pz1);
   //if kc>0 then buy(1,kc,limitr,open+mindiff);
   if kc>0 then tbuy(1,kc,mkt,0,zh1,pz1);
   cc1:=0;
  end
  if cc1=0 and c>line  then begin
    //pc:=min(abs(min(holding,0)),cang1);
    pc:=min(abs(tsellholdingex( zh1,pz1 ,0 )),cang1);
    kc:=cang1-pc;
    //if pc>0 then sellshort(1,pc,limitr,open+mindiff);
    if pc>0 then tsellshort(1,pc,mkt,0,zh1,pz1);
    //if kc>0 then buy(1,kc,limitr,open+mindiff);
    if kc>0 then tbuy(1,kc,mkt,0,zh1,pz1);
    cc1:=1;
   end
  if cc1=0 and c<line then begin
     //pc:=min(max(holding,0),cang1);
     pc:=min(tbuyholdingex( zh1,pz1 ,0 ),cang1);
     kc:=cang1-pc;
   // if pc>0 then sell(1,pc,limitr,open-mindiff);
     if pc>0 then tsell(1,pc,mkt,0,zh1,pz1);
    //if kc>0 then buyshort(1,kc,limitr,open-mindiff);
    if kc>0 then tbuyshort(1,kc,mkt,0,zh1,pz1);
     cc1:=-1;
    end

   zline:stkindi(\'\',\'line.line1\',0,3);
  if cc2>0 and c<zline then begin
    // pc:=min(max(holding,0),cang1);
    pc:=min(tbuyholdingex( zh1,pz1 ,0 ),cang2);
    kc:=cang2-pc;
    //if pc>0 then sell(1,pc,limitr,open-mindiff);
    if pc>0 then tsell(1,pc,mkt,0,zh1,pz1);
    //if kc>0 then buyshort(1,kc,limitr,open+mindiff);
    if kc>0 then tbuyshort(1,kc,mkt,0,zh1,pz1);
    cc2:=0;
   end
  if cc2<0 and c>zline  then begin
    //pc:=min(abs(min(holding,0)),cang1);
    pc:=min(abs(tsellholdingex( zh1,pz1 ,0 )),cang2);
    kc:=cang2-pc;
    //if pc>0 then sellshort(1,pc,limitr,open+mindiff);
    if pc>0 then tsellshort(1,pc,mkt,0,zh1,pz1);
   //if kc>0 then buy(1,kc,limitr,open+mindiff);
   if kc>0 then tbuy(1,kc,mkt,0,zh1,pz1);
   cc2:=0;
  end
  if cc2=0 and c>zline  then begin
    //pc:=min(abs(min(holding,0)),cang1);
    pc:=min(abs(tsellholdingex( zh1,pz1 ,0 )),cang2);
    kc:=cang2-pc;
    //if pc>0 then sellshort(1,pc,limitr,open+mindiff);
    if pc>0 then tsellshort(1,pc,mkt,0,zh1,pz1);
    //if kc>0 then buy(1,kc,limitr,open+mindiff);
    if kc>0 then tbuy(1,kc,mkt,0,zh1,pz1);
    cc2:=1;
   end
  if cc2=0 and c<line then begin
     //pc:=min(max(holding,0),cang1);
     pc:=min(tbuyholdingex( zh1,pz1 ,0 ),cang2);
     kc:=cang2-pc;
     //if pc>0 then sell(1,pc,limitr,open-mindiff);
     if pc>0 then tsell(1,pc,mkt,0,zh1,pz1);
     //if kc>0 then buyshort(1,kc,limitr,open-mindiff);
     if kc>0 then tbuyshort(1,kc,mkt,0,zh1,pz1);
     cc2:=-1;
    end
  

    zline1:stkindi(\'\',\'line.line1\',0,5);


    if cc3>0 and c<zline1 then begin
       //pc:=min(max(holding,0),cang3);
       pc:=min(tbuyholdingex( zh1,pz1 ,0 ),cang3);
       kc:=cang3-pc;
       //if pc>0 then sell(1,pc,limitr,open-mindiff);
       if pc>0 then tsell(1,pc,mkt,0,zh1,pz1);
       //if kc>0 then buy(1,kc,limitr,open-mindiff);
       if kc>0 then tbuy(1,kc,mkt,0,zh1,pz1);
       cc3:=0;
      end
     if cc3<0 and c>zline1 then begin
        //pc:=min(abs(min(holding,0)),cang3);
        pc:=min(abs(tsellholdingex( zh1,pz1 ,0 )),cang3);
        kc:=cang3-pc;
        //if pc>0 then sellshort(1,pc,limitr,open+mindiff);
        if pc>0 then tsellshort(1,pc,mkt,0,zh1,pz1);
        //if kc>0 then buy(1,kc,limitr,open+mindiff);
        if kc>0 then tbuy(1,kc,mkt,0,zh1,pz1);
        cc3:=0;
       end
     if cc3=0 and c>zline1 then begin
        //pc:=min(abs(min(holding,0)),cang3);
        pc:=min(abs(tsellholdingex( zh1,pz1 ,0 )),cang3);
        kc:=cang3-pc;
        //if pc>0 then sellshort(1,pc,limitr,open+mindiff);
        if pc>0 then tsellshort(1,pc,mkt,0,zh1,pz1);
        //if kc>0 then buy(1,kc,limitr,open+mindiff);
        if kc>0 then tbuy(1,kc,mkt,0,zh1,pz1);
        cc3:=1;
       end
     if cc3=0 and c<zline1 then begin
       // pc:=min(max(holding,0),cang3);
        pc:=min(abs(tsellholdingex( zh1,pz1 ,0 )),cang3);
        kc:=cang3-pc;
        //if pc>0 then sell(1,pc,limitr,open-mindiff);
        if pc>0 then tsell(1,pc,mkt,0,zh1,pz1);
        //if kc>0 then buyshort(1,kc,limitr,open-mindiff);
        if kc>0 then tbuyshort(1,kc,mkt,0,zh1,pz1);
       cc3:=-1;
      end
end
     continueline@ 

--  作者:jinzhe
--  发布时间:2016/11/21 14:53:57
--  
因为使用图表全局变量variable的关系,所以改成适合后台的超全局变量globalvariable即可
--  作者:tanyongde
--  发布时间:2016/11/21 15:32:38
--  
   谢谢!改了正常。
  另外,可以直接其他模块开仓平仓信号吗?
  如:long :stkindi(\'\',\'line.开仓信号\',0,3);
       if long then buy(1,1,market0;

--  作者:jinzhe
--  发布时间:2016/11/21 15:45:28
--  
不能引用信号,只能引用触发信号的条件