//方法1
//input: p(26,20,88,6),s(12,5,15,1),m(9,2,15,1);
//Diff: Ema(close,s)-ema(close,p);
//Dea: Ema(diff,m){,crossdot};
//macd: 2*(diff-dea), colorstick;
//建立多头进场的条件
long:=cross(diff,dea);
if long then
begin
sellshort(holding<0,holding,thisclose);
buy(long,1,thisclose);
end
//建立空头进场的条件
short:=cross(dea,diff);
if short then begin
sell(holding>0,holding,thisclose);
buyshort(short,1,thisclose);
end
上面的语言结果是它在任何时候都有仓位,不是空就是多。原理就是macd 金叉开多,死叉开空。我想到达这样的结果:
1.macd在0轴以上金叉开多。macd 在0轴以上死叉观望
2.macd在0轴以下死叉开空。macd 在0轴以下金叉观望
3.我想必要时,能让程序能空仓。
4.我还想把均线加进来:
比如说5单位线上穿10单位线类的。
请老师指点。现在刚接触,好多想法就是加不进去,请老师谅解!
1.long:=cross(diff,dea) and diff>0 and dea>0;
2.short:=cross(dea,diff) and diff<0 and dea<0;
3.这个能空仓指什么。
4.均线的上下串要加在哪里。
//方法1
input: p(26,20,88,6),s(12,5,15,1),m(9,2,15,1);
Diff: Ema(close,s)-ema(close,p);
Dea: Ema(diff,m){,crossdot};
macd: 2*(diff-dea), colorstick;
//建立多头进场的条件
long:=cross(diff,dea) and macd>0;
if long then
begin
sellshort(holding<0,holding,thisclose);
buy(long,1,thisclose);
end
//建立空头进场的条件
short:=cross(dea,diff) and macd<0;
if short then begin
sell(holding>0,holding,thisclose);
buyshort(short,1,thisclose);
end
空仓意思是:比如说在震荡行情,我想让他空仓。因为震荡行情它会不停得开仓,平仓。
不知道怎么回避。谢谢!