以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 公式模型编写问题提交 (http://weistock.com/bbs/list.asp?boardid=4) ---- 如何得到特定条件下开仓以来的周期数? (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=78441) |
|
-- 作者:onmidas -- 发布时间:2015/5/10 22:08:15 -- 如何得到特定条件下开仓以来的周期数? 连续n笔以上(n大于等于2笔)都是亏损,怎么得到第一笔亏损交易,开仓至今的周期数(即K线根数)? [此贴子已经被作者于2015/5/10 22:08:55编辑过]
|
|
-- 作者:jinzhe -- 发布时间:2015/5/11 9:14:01 -- variable:n=0; if 平多条件 and holding>0 then begin sell(1,0,market); if numprofit(1)>0 then n:=0; if numprofit(1)<0 then n:=n+1; end
if 平空条件 and holding>0 then begin sellshort(1,0,market); if numprofit(1)>0 then n:=0; if numprofit(1)<0 then n:=n+1; end
全局变量n来计数当前的连续亏损次数 那么需求第一次亏损且当前连亏大于2次到现在的周期就是: nn:=barslast(ref(n=0,1) and n=1); if n>2 then xx:=nn; xx就是所求周期数
|
|
-- 作者:onmidas -- 发布时间:2015/5/11 10:09:55 -- 这个nn是第一次亏损平仓以来的周期数吧,我想得到是开仓以来的周期数。 |
|
-- 作者:jinzhe -- 发布时间:2015/5/11 10:15:43 -- 在前面的代码基础上,加上下面的: ss:=ref(enterbars,xx); 开仓到现在的总周期就是:ss+xx |
|
-- 作者:onmidas -- 发布时间:2015/5/16 13:08:44 -- 上面的公式不能用于平仓即反手,用于反手的策略上,该怎么改写? |
|
-- 作者:onmidas -- 发布时间:2015/5/16 13:17:27 -- 我的代码如下,是平仓即反手,但加入了止损,按下面的写,记录不了连亏次数。 variable:cishu=0;//记录连亏次数 if PK then begin
平空:SELLSHORT(1,SS,THISCLOSE); //平空信号
if NUMPROFIT(1)>0 then cishu:=0;
if NUMPROFIT(1)<0 then cishu:=cishu+1; end if KD and holding=0 then begin
开多:BUY(1,SS,THISCLOSE);
//开多信号 end if PD then begin
平多:SELL(1,SS,THISCLOSE); //平多信号
if NUMPROFIT(1)>0 then cishu:=0;
if NUMPROFIT(1)<0 then cishu:=cishu+1; end if KK and holding=0 then begin
开空:BUYSHORT(1,SS,THISCLOSE);
//开空信号 end //多头止损 IF ENTERBARS>0 AND HOLDING>0 THEN BEGIN IF C<stoploss THEN BEGIN 多头止损:SELL(1,HOLDING,THISCLOSE);
if NUMPROFIT(1)<0 then cishu:=cishu+1; END END //空头止损 IF ENTERBARS>0 AND HOLDING<0 THEN BEGIN IF C>stoploss THEN BEGIN 空头止损:SELLshort(1,HOLDING,THISCLOSE); if NUMPROFIT(1)<0 then cishu:=cishu+1; END END
|
|
-- 作者:onmidas -- 发布时间:2015/5/16 13:18:04 -- 准确的说,是记录的连亏次数是错的 |
|
-- 作者:onmidas -- 发布时间:2015/5/16 13:23:00 -- 排版的比较差,将就的看了 |
|
-- 作者:jinzhe -- 发布时间:2015/5/18 8:51:27 -- if PK and holding<0 then begin
pk里面不要加持仓判断,持仓判断写直接写在if判断里面
|
|
-- 作者:onmidas -- 发布时间:2015/5/18 10:49:35 --
|