以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  后台限制日内连续亏损次数  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=139918)

--  作者:lc1227
--  发布时间:2016/9/22 13:53:10
--  后台限制日内连续亏损次数
请帮忙写一个代码,限制日内连续亏损次数的代码,例如限制当天连续亏损次数超过3次就停止交易(交易所时间)
--  作者:jinzhe
--  发布时间:2016/9/22 14:01:38
--  

用全局变量来记录一下

globalvariable:cs=0,tt=0;

 

if 平多条件 and 持仓判断 then begin

   tsell();

   sleep(1000);//暂停1秒等成交

   if tnumprofit(1)>=0 then cs:=0;

   if tnumprofit(1)<0 and tt<>time then begin

         cs:=cs+1;

         tt:=time;//用记录time的方式来防止反复迭代

   end

end

 

 

if 平空条件 and 持仓判断 then begin

   tsellshort();

   sleep(1000);//暂停1秒等成交

   if tnumprofit(1)>=0 then cs:=0;

   if tnumprofit(1)<0 and tt<>time then begin

         cs:=cs+1;

         tt:=time;

   end

end

 

if time=closetime(0) then cs:=0;//收盘后重置全局变量

 

开平仓条件加入:cs<3;