一下内容实际执行的不一样,想要的结果是当前周期开仓后条件不成立(信号消失了),则立即恢复上一次交易信号的持仓,但是执行的结果不对,不仅不对,连开仓信号也不对。
给看看问题出在哪里。
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;
我在表述清楚一点吧
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就恢复持仓。
平仓并恢复持仓
这个恢复持仓做何解释?
就是恢复上一次原有持仓
比如均线交叉系统,盘中肯定有交叉后又不成功的,那么当交叉后平反手的仓位在,交叉信号消失后,应该恢复原来的仓位。
如果原来是金叉,现在死叉成立,就平多做空,随着行情的发展死叉消失,那么平多做空就不成立,这样就需要把现在的空单平掉,并迅速恢复原来的多单仓位。这样说可说明白了?
这个在图表上很难实现的,建议你使用后台