以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  条件满足不执行  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=50310)

--  作者:guobixiboy
--  发布时间:2013/3/27 9:52:22
--  条件满足不执行

算法描述:当第k根触及止损价不平仓,第k+n个周期或者价位达到某界限值平仓。

代码如下:

variable:DDZSPrice=10000;//多单止损价格。
variable:DDZSP=0;//多单止损位置。
variable:DDFlag=1;

 

variable:KDZSPrice=0;//空单止损价格。
variable:KDZSP=0;//空单止损位置。
variable:KDFlag=1;
N:=4;

//多单止损

DDZSPosition1:=ref(low,1)>(enterprice-zsd) ;//第一根k线最低值大于止损价
DDZSPosition2:=ref(low,2)>(enterprice-zsd)  ;//第二根k线最低值大于止损价
DDZSPosition3:=low<=(enterprice-zsd) and  holding>0 ;//第三根k线最低值小于止损价
if holding>0 then begin
if DDZSPosition1 AND DDZSPosition2 AND DDZSPosition3 THEN

DDZSP:=BARPOS;//定位止损价位k线位置。

if low<=(enterprice-zsd) and DDFlag=1 then begin
DDZSPrice:=o;
DDFlag:=0;
end
DDZSP1:=BARPOS;
dp1:=(c>=DDZSPrice)  or   (DDZSP1-DDZSP)>=N;//现价高于止损位置开盘价或者时间周期到,止损指令发出。
//dp1:= BARSLAST(DDZSPosition)>5 and holding>0;//现价高于止损位置开盘价或者时间周期到,止损指令发出。
end

//平单

//多单平仓
if holding>0 then
begin
    if dp1 then begin
         //myexitprice:=min(o,enterprice-zsd);     
           DDZSPrice:=10000; 
           DDFlag:=1;
           DDZSP:=0;
           end
   
         myexitprice:=open;
    if dp1 then sell(holding>0,lots,limitr,myexitprice-hd*mindiff);
end

 

//-----以上部分可以顺利的执行。问题出现在空单情形

 

//kp1:=h>=(enterprice+zsd);  //空仓止损
KDZSPosition1:=ref(HIGH,1)<(enterprice+zsd) ;//第一根k线最高值小于止损价
KDZSPosition2:=ref(HIGH,2)<(enterprice+zsd)  ;//第二根k线最高值小于止损价
KDZSPosition3:=HIGH>=(enterprice+zsd) and  holding<0 ;//第三根k线最高值大于止损价


if holding<0 then begin
if KDZSPosition1 AND KDZSPosition2 AND KDZSPosition3 THEN
     KDZSP:=BARPOS;//空单止损位k线位置。
     //-----问题在此:条件满足,KDZSP:=BARPOS不执行。
if HIGH>=(enterprice+zsd) and KDFlag=1 then begin
 KDZSPrice:=o;//空止损价格

//---条件满足,执行。
 KDFlag:=0;//空单止损标志

//-----条件满足,不执行。

end
KDZSP1:=BARPOS;

kp:=(c<=KDZSPrice)  or  (KDZSP1-KDZSP)>=N;//现价高于止损位置开盘价或者时间周期到,止损指令发出。
end

//平空单。

if holding<0 then
begin
    if kp then
         // myexitprice:=max(o,enterprice+zsd);
         KDZSPrice:=0;
         KDZSP:=0;
         KDFlag:=1;
         myexitprice:=open;
    if kp then sellshort(holding<0,lots,limitr,myexitprice+hd*mindiff);
end
---可以顺利执行。


--  作者:jinzhe
--  发布时间:2013/3/27 9:58:56
--  

DEBUGFILE----使用日志方式完善您的策略 

http://www.weistock.com/bbs/dispbbs.asp?boardid=4&Id=49428

 


--  作者:guobixiboy
--  发布时间:2013/3/27 10:20:05
--  
以下是引用jinzhe在2013-3-27 9:58:56的发言:

DEBUGFILE----使用日志方式完善您的策略 

http://www.weistock.com/bbs/dispbbs.asp?boardid=4&Id=49428

 

烦请您看看,逻辑中有没有发现错误。

这是我在调试中发现的。


--  作者:jinzhe
--  发布时间:2013/3/27 10:30:46
--  

DDZSPosition3:=low<=(enterprice-zsd) and  holding>0

 

if holding<0 then begin
if KDZSPosition1 AND KDZSPosition2 AND KDZSPosition3 THEN
     KDZSP:=BARPOS;//空单止损位k线位置。
     //-----问题在此:条件满足,KDZSP:=BARPOS不执行。
if HIGH>=(enterprice+zsd) and KDFlag=1 then begin
 KDZSPrice:=o;//空止损价格

//---条件满足,执行。
 KDFlag:=0;//空单止损标志

//-----条件满足,不执行。

end


--  作者:guobixiboy
--  发布时间:2013/3/27 13:00:00
--  
以下是引用jinzhe在2013-3-27 10:30:46的发言:

DDZSPosition3:=low<=(enterprice-zsd) and  holding>0

 

if holding<0 then begin
if KDZSPosition1 AND KDZSPosition2 AND KDZSPosition3 THEN
     KDZSP:=BARPOS;//空单止损位k线位置。
     //-----问题在此:条件满足,KDZSP:=BARPOS不执行。
if HIGH>=(enterprice+zsd) and KDFlag=1 then begin
 KDZSPrice:=o;//空止损价格

//---条件满足,执行。
 KDFlag:=0;//空单止损标志

//-----条件满足,不执行。

end

什么意思?没看明白。


--  作者:jinzhe
--  发布时间:2013/3/27 13:11:37
--  
看串了。。。
--  作者:jinzhe
--  发布时间:2013/3/27 13:16:22
--  

请提供一下调试的文件


--  作者:guobixiboy
--  发布时间:2013/3/27 15:27:56
--  

这是否与全局变量个数有关呢?

全局变量超过一定限度,如果超过了限度,之后的全局变量便无法再进行操作?

variable:DDZSPrice=10000;//多单止损价格。
variable:DDZSP=0;//多单止损位置。
variable:DDFlag=1;

variable:KDZSPrice=0;//空单止损价格。
variable:KDZSP=0;//空单止损位置。
variable:KDFlag=1;
在我的程序中,最后面两个全局变量无法赋值,即无论如何KDZSP=0,KDflag=1保持不变,而前面的可以进行赋值操作。


--  作者:jinzhe
--  发布时间:2013/3/27 15:32:28
--  
全局变量能定义50个
--  作者:jinzhe
--  发布时间:2013/3/27 15:33:03
--  
还是请提供一下调试的文档