Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共14 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:如何得到特定条件下开仓以来的周期数?

1楼
onmidas 发表于:2015/5/10 22:08:15
连续n笔以上(n大于等于2笔)都是亏损,怎么得到第一笔亏损交易,开仓至今的周期数(即K线根数)?



[此贴子已经被作者于2015/5/10 22:08:55编辑过]
2楼
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就是所求周期数

 

 

3楼
onmidas 发表于:2015/5/11 10:09:55
这个nn是第一次亏损平仓以来的周期数吧,我想得到是开仓以来的周期数。
4楼
jinzhe 发表于:2015/5/11 10:15:43

在前面的代码基础上,加上下面的:

ss:=ref(enterbars,xx);

开仓到现在的总周期就是:ss+xx

5楼
onmidas 发表于:2015/5/16 13:08:44
上面的公式不能用于平仓即反手,用于反手的策略上,该怎么改写?


6楼
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
7楼
onmidas 发表于:2015/5/16 13:18:04
准确的说,是记录的连亏次数是错的
8楼
onmidas 发表于:2015/5/16 13:23:00
排版的比较差,将就的看了
9楼
jinzhe 发表于:2015/5/18 8:51:27
if PK and holding<0 then begin
 
pk里面不要加持仓判断,持仓判断写直接写在if判断里面
10楼
onmidas 发表于:2015/5/18 10:49:35
if PK and holding<0 then begin
 
pk里面不要加持仓判断,持仓判断写直接写在if判断里面

___________________

你说的不就是我上面代码写的么,得到的交易次数不对,只要pk条件满足,记录的亏损交易次数就会继续增加。


共14 条记录, 每页显示 10 条, 页签: [1] [2]


Powered By Dvbbs Version 8.3.0
Processed in 0.01953 s, 3 queries.