以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://www.weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://www.weistock.com/bbs/list.asp?boardid=4)
----  [求助]加仓怎么写  (http://www.weistock.com/bbs/dispbbs.asp?boardid=4&id=164048)

--  作者:hksl1023
--  发布时间:2018/6/16 20:58:17
--  [求助]加仓怎么写

现有开多条件kd 开空条件kk   平多仓kk 平空仓kd 每次开平一手

我这个策略是反手策略 开多平仓后开空  开空平仓后开多

现在呢我想加入一个加仓策略 ,那么就是如果上一次平仓后亏损 ,那么这次开仓的手数是上一次开仓手数的N倍,然后跟随一个追踪移动平仓(也就是开仓后当最新高价或者最新低价与开仓均价大于M点回撤X点平仓),次加仓和追踪移动平仓只适合在加仓的情况下使用,也就是说如果上一平仓次盈利出局后再次开仓不适合此策略,则是按照一手去开仓;


--  作者:fly
--  发布时间:2018/6/19 9:01:18
--  
您的问题,正在查看,请您耐心等待
--  作者:FexTel
--  发布时间:2018/6/19 9:31:38
--  
以MA为例,如下代码仅做为示例参考。请您结合您的策略进行修改

VARIABLE:scsy=0,p=1;  //记录上次平仓亏损还是盈利
N:2;
m:20;
X:5;

m1:=ma(c,5);
m2:=ma(c,10);
kd:=cross(m1,m2);
kk:=cross(m2,m1);

if kd and holding<=0 then
begin
   sellshort(1,holding,market);
   if (close-enterprice)>0 then 
   begin
   p:=N;
   scsy:=1; //上次交易亏损
   end
   else
   begin
    p:=1;
   scsy:=0;
   end
   buy(1,1*p,market);
end

if kk and holding>=0 then
begin
   sell(1,holding,market);
   if (close-enterprice)<0 then 
   begin
   p:=N;
   scsy:=1; //上次交易亏损
   end
   else
   begin
   p:=1;
   scsy:=0;
   end
   
   buyshort(1,1*p,market);
end


   
zd:=llv(l,enterbars+1);// 开仓以来的最低价
zg:=hhv(h,enterbars+1);// 开仓以来的最高价
if  zg-enterprice>m and scsy=1 then
begin
   if zg-c>x then 多止损:sell(1,holding,market);
   scsy:=0;
end
if  enterprice-zd>m and scsy=1 then
begin
   if c-zd>x then 空止损:sellshort(1,holding,market);
   scsy:=0;
end