以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  每涨5%就卖出20%的仓位,怎么写  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=144393)

--  作者:chyhao
--  发布时间:2016/12/9 9:44:48
--  每涨5%就卖出20%的仓位,怎么写
请问下,图表程序化模型,相对于首次开仓价,每涨5%就卖出20%的原始多单仓位,这个应该怎么写呢?
--  作者:jinzhe
--  发布时间:2016/12/9 10:22:33
--  
一共平5次吗?
--  作者:chyhao
--  发布时间:2016/12/9 13:12:58
--  
这个例子里边最多就平5次
--  作者:jinzhe
--  发布时间:2016/12/9 14:04:18
--  

if 开仓条件 and holding=0 then begin

   buy(1,100,marketr);

   cc:=holding;

end

 

if c>=enterprice*1.05 and c<enterprice>1.1 then sell(1,cc*0.2,marketr);

if c>=enterprice*1.1 and c<enterprice>1.15 then sell(1,cc*0.2,marketr);

if c>=enterprice*1.15 and c<enterprice>1.2 then sell(1,cc*0.2,marketr);

if c>=enterprice*1.2 and c<enterprice>1.25 then sell(1,cc*0.2,marketr);

if c>=enterprice*1.30 then sell(1,0,marketr);


--  作者:chyhao
--  发布时间:2016/12/9 16:41:25
--  
这样写不合理吧,如果我连续几根K线都处于1.05*ENTERPRICEI和1.1*ENTERPRICE之间,那也会不断平仓的哦,我是想涨了5%平一次,后边再涨5%才平第二次10%
--  作者:jinzhe
--  发布时间:2016/12/9 16:45:18
--  

variable:n=0;

if 开仓条件 and holding=0 then begin

   buy(1,100,marketr);

   cc:=holding;

   n:=0;

end

 

if c>=enterprice*1.05 and c<enterprice>1.1 and n=0 and holding>0 then begin

  n:=1;

  sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.1 and c<enterprice>1.15 and n=1 and holding>0 then begin

  n:=2;

  sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.15 and c<enterprice>1.2 and n=2 and holding>0 then begin

  n:=3;

  sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.2 and c<enterprice>1.25 and n=3 and holding>0 then begin

   n:=4;

   sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.30 and n=4 then begin

   n:=5;

   sell(1,0,marketr);

end



--  作者:爬山虎福气
--  发布时间:2018/6/17 21:43:24
--  
以下是引用jinzhe在2016/12/9 16:45:18的发言:

variable:n=0;

if 开仓条件 and holding=0 then begin

   buy(1,100,marketr);

   cc:=holding;

   n:=0;

end

 

if c>=enterprice*1.05 and c<enterprice>1.1 and n=0 and holding>0 then begin

  n:=1;

  sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.1 and c<enterprice>1.15 and n=1 and holding>0 then begin

  n:=2;

  sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.15 and c<enterprice>1.2 and n=2 and holding>0 then begin

  n:=3;

  sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.2 and c<enterprice>1.25 and n=3 and holding>0 then begin

   n:=4;

   sell(1,cc*0.2,marketr);

end

if c>=enterprice*1.30 and n=4 then begin

   n:=5;

   sell(1,0,marketr);

end

 
倒数第2句,sell,仓位应该还是cc*0.2吧。
倒数第3句,可以取消。


--  作者:FireScript
--  发布时间:2018/6/19 9:30:18
--  
 因为例子说了最多平五次,因此最后一次直接全平了。