以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  请问这个怎么写,大师们给看下。  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=12267)

--  作者:masterxl
--  发布时间:2012/6/6 19:32:29
--  请问这个怎么写,大师们给看下。

一下内容实际执行的不一样,想要的结果是当前周期开仓后条件不成立(信号消失了),则立即恢复上一次交易信号的持仓,但是执行的结果不对,不仅不对,连开仓信号也不对。

给看看问题出在哪里。

bOpen:=false;

sopen:=false;

if QQ and SS=1 and T0 then begin
 
  if O>=AA2 and H>MAX(ref(High,1),ref(High,2)) then begin //第一种开仓买
  
   if L>AA1 then
   Buy(bOpen = false and barpos>2,Q,market);
    bOpen := True;
   
   if L<=AA1 and enterbars=0  then//达到这个条件后立刻平仓
   
   Sell(holding>0,Q,market);
  
   bOpen := False; 
  end 
  
 
  
  if O<AA2 and H>AA3 then begin
  
   if L>ref(Low,1) then
   
        Buy(bopen=false,Q,market);
        bOpen := True;
   
   if L<=ref(Low,1) and enterbars=0 then//达到这个条件后立刻平仓
   
    
    Sell(holding>0,Q,market);
    
    bOpen := False;
   
  end
end
 
 //卖开仓
if QQ and XX=1 and T0 then begin
 
  if O>=AA2 and L<AA1 then begin //卖开
  
   if H<ref(high,1) then
   
    buyShort(sopen=false,Q,market);
    sOpen := True;
   
   if H>=ref(high,1) and enterbars=0 then //达到这个条件后立刻平仓
   
    sellshort(holding<0,Q,market);
    sOpen := False;
   
  end
  
  if O<AA2 and L<MIN(ref(Low,1),ref(Low,2)) then begin //卖开
  
   if H<AA3 then   
    
    buyShort(sopen=false,Q,market);
    sOpen := True;
   
   if H>=AA3  and enterbars=0 then //达到这个条件后立刻平仓
   
    
    buyshort(holding<0,Q,market);
    sOpen := False;
   
    end
end

 
//买平仓 
if sopen=true then begin

 if JZ or TT then 
 
  sellshort(sopen=true,Q,market);
  sOpen := False;
 
 if SS=1 then begin
 
  if O>=AA2 and H>ref(High,1) then begin
  
   if L>AA1 then
   
    
    sellshort(sopen=true,Q,market);
    sOpen := False;
   
   if L<=AA1 and type(1)=3   then//达到这个条件立刻恢复持仓
   
    
    buyShort(holding=0,Q,market);
    sOpen := True;
    
   
  end
  if O<AA2 and  H>AA3 then begin
  
   if L>ref(Low,1) then
   
    //BPPrice = Q_BidPrice+Y;
    sellshort(sopen=true,Q,market);
    sOpen := False;
   
   if L<=ref(Low,1) and type(1)=3  then //达到这个条件立刻恢复持仓
   
    
    buyShort(holding=0,Q,market);
     sOpen := True;
  end
end

end  
//卖平仓
if bopen=true then begin

 if JD or TT then
 
  
  Sell(bopen=true,Q,market);
  bOpen := False;
 
 if XX=1 then begin
   if O<AA2 and L<ref(Low,1) then begin
   if H<AA3 then
    Sell(bopen=true,Q,market);
    bOpen := False;
   
   if H>=AA3 and type(1)=1 then//达到这个条件立刻恢复持仓   
    
    Buy(holding=0,Q,market);
    bOpen := True;
   
   end
  if O>=AA2  and L<AA1 then begin
  
   if H<ref(High,1) then
   
    
    Sell(bopen=true,Q,market);
   
    bOpen := False;
   
   if H>=ref(High,1) and type(1)=1 then //达到这个条件立刻恢复持仓   
    
    Buy(holding=0,Q,market);
    bOpen := True;
   
  end
end
end;


--  作者:masterxl
--  发布时间:2012/6/7 6:23:17
--  

我在表述清楚一点吧

K1  and C>O//买开仓条件

K2 and C<O//卖开仓条件

S1 and C<O //平多仓条件

B1 and C>O //平空仓条件

 

要达到的结果如果K1满足且C>o则买入,否则一旦C<=O则平仓并恢复持仓;同样,如果K2满足且C<O则卖出开仓,否则一旦C>=O就平仓并恢复持仓;

如果S1满足且C<O,就平多,否则一旦C>=O就恢复持仓,如果B1满足且C>O就平空,否则一旦C<=O就恢复持仓。


--  作者:jinzhe
--  发布时间:2012/6/7 9:54:01
--  

平仓并恢复持仓

 

这个恢复持仓做何解释?


--  作者:masterxl
--  发布时间:2012/6/7 12:15:05
--  

就是恢复上一次原有持仓

比如均线交叉系统,盘中肯定有交叉后又不成功的,那么当交叉后平反手的仓位在,交叉信号消失后,应该恢复原来的仓位。

 

如果原来是金叉,现在死叉成立,就平多做空,随着行情的发展死叉消失,那么平多做空就不成立,这样就需要把现在的空单平掉,并迅速恢复原来的多单仓位。这样说可说明白了?


--  作者:masterxl
--  发布时间:2012/6/7 12:18:22
--  
其实就是有些软件里面的“全自动交易信号消失后,自动恢复持仓”,这个和“信号消失后次周期恢复持仓”或者“当前K线走完恢复持仓”差别还是很大的
--  作者:王锋
--  发布时间:2012/6/7 12:58:16
--  

这个在图表上很难实现的,建议你使用后台