以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  如果回撤幅度到达10%,想暂停,如何实现?  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=71467)

--  作者:左岸
--  发布时间:2014/10/28 23:15:58
--  如果回撤幅度到达10%,想暂停,如何实现?

zichan:asset,noaxis;
if barpos=1 then begin
 MaxAsset:=zichan;
 Maxhc:=0; end
if zichan>MaxAsset then MaxAsset:=zichan;
if MaxAsset-zichan>Maxhc then Maxhc:=MaxAsset-zichan;
最大回撤:Maxhc,linethick0;
回撤幅度:(MaxAsset-asset)/MaxAsset,linethick0;//请问如何求回撤幅度的百分比?并能显示出来(问题一)

MA5:=MA(C,5);
MA10:=MA(C,10);
COND1:=CROSS(MA5,MA10);
COND2:=CROSS(MA10,MA5);
 
IF  COND1 THEN
     BEGIN
     SELLSHORT(1,1,MARKET);
     BUY(1,1,MARKET);
     END
IF  COND1 THEN
     BEGIN
     SELL(1,1,MARKET);
     BUYSHORT(1,1,MARKET);
     END
.........
.........
.........

问题二:帮忙编写剩余部分,当“回撤幅度”>10% 时,平掉现有持仓,并且接下来2根K线一直空仓(暂停交易),直到第三根K线再根据条件重新判断入场。

[此贴子已经被作者于2014/10/28 23:17:35编辑过]

--  作者:jinzhe
--  发布时间:2014/10/29 8:48:17
--  

variable:n=0

if 回撤幅度>0.1 and holding<>0 and n=0 then begin

    sellshort(1,0,market);

    sell(1,0,market);

    n:=1;

end

 

开仓条件加上 barslast(n=1 and ref(n=0))>2

 


--  作者:期货螺子
--  发布时间:2014/10/29 9:13:22
--  
 barslast(n=1 and ref(n=0))>2    ??
--  作者:jinzhe
--  发布时间:2014/10/29 9:15:22
--  
 barslast(n=1 and ref(n=0,1))>2
--  作者:期货螺子
--  发布时间:2014/10/29 9:41:46
--  
图片点击可在新窗口打开查看
[此贴子已经被作者于2014/10/29 9:42:41编辑过]

--  作者:左岸
--  发布时间:2014/10/29 9:43:36
--  
不行~
--  作者:jinzhe
--  发布时间:2014/10/29 10:01:17
--  

zichan:asset,noaxis;
if barpos=1 then begin
 MaxAsset:=zichan;
 Maxhc:=0; end
if zichan>MaxAsset then MaxAsset:=zichan;
if MaxAsset-zichan>Maxhc then Maxhc:=MaxAsset-zichan;
最大回撤:Maxhc,linethick0;
回撤幅度:(MaxAsset-asset)/MaxAsset,linethick0;//请问如何求回撤幅度的百分比?并能显示出来(问题一)

MA5:=MA(C,5);
MA10:=MA(C,10);
COND1:=CROSS(MA5,MA10);
COND2:=CROSS(MA10,MA5);
variable:kk=0;
IF  COND1 and holding<0 and kk=0 THEN
     BEGIN
     SELLSHORT(1,1,MARKET);
     BUY(1,1,MARKET);

     kk:=1;
     END
IF  COND1 and holding>0 and kk=0 THEN
     BEGIN
     SELL(1,1,MARKET);
     BUYSHORT(1,1,MARKET);

     kk:=1;
     END

 

variable:n=0;

if 回撤幅度>0.1 and holding<>0 and n=0 then begin

    sellshort(1,0,market);

    sell(1,0,market);

    n:=1;

end

cc:=barslast(n=1 and ref(n=0,1))>2 ;

 IF  COND1  and kk=1 and n=1 and holding<0  and cc THEN
     BEGIN
     SELLSHORT(1,1,MARKET);
     BUY(1,1,MARKET);

     n:=0;
     END
IF  COND1  and kk=1 and nn=1 and holding>0 and cc THEN
     BEGIN
     SELL(1,1,MARKET);
     BUYSHORT(1,1,MARKET);

     n:=0;
     END



--  作者:左岸
--  发布时间:2014/10/29 10:35:44
--  
不好意思,不行。

还有,你里面有许多错误

--  作者:jinzhe
--  发布时间:2014/10/29 10:48:33
--  

zichan:asset,noaxis;
if barpos=1 then begin
 maxasset:=zichan;
 maxhc:=0; end
if zichan>maxasset then maxasset:=zichan;
if maxasset-zichan>maxhc then maxhc:=maxasset-zichan;
最大回撤:maxhc,linethick0;
回撤幅度:(maxasset-asset)/maxasset,linethick0;//请问如何求回撤幅度的百分比?并能显示出来(问题一)
variable:n=0;
ma5:=ma(c,5);
ma10:=ma(c,10);
cond1:=cross(ma5,ma10);
cond2:=cross(ma10,ma5);

if  cond1 and n=0   then
begin
     sellshort(1,0,market);
     buy(holding=0,1,market);
end
 
if  cond2  and n=0  then
begin
     sell(1,0,market);  
     buyshort(holding=0,1,market);
end
    


if 回撤幅度>0.1 and holding<>0 and n=0 then
begin
    sellshort(1,0,market);
    sell(1,0,market);
    n:=1;
end

cc:=barslast(n=1 and ref(n=0,1))>2 ;

if  cond1   and n=1 and holding=0  and cc then
begin   
     buy(1,1,market);
     n:=0;
end

if  cond1   and n=1 and holding=0 and cc then
begin
     buyshort(1,1,market);
     n:=0;
end

 


--  作者:jinzhe
--  发布时间:2014/10/29 10:48:48
--  
感觉是这样的,但是没有发现有回撤10%的来验证我的想法