此主题相关图片如下:201310289532995415.png
参考止盈止损模版写了平仓策略,测试有问题,就像图中这样,开仓点是对的,但是所有平仓点都出现在开仓点同一根K上
怎么改都还是这样
做多后,跌破开仓均价10点止损。
做多后,如果开仓均价盈利大于50点但小于100点时,跌破盈利段的一半止盈。
做多后,如果开仓均价盈利大于100点时,以盈利100点的位置为低点,100+N点为高点,这段距离回落一半止盈。
应该怎么写呢
1.平仓和开仓不同K线,那么平仓条件要加上
enterbars>0
2
if close<avgenterprice-10*mindiff then 平仓语句;
3
variable:n=0;
if holding=0 and 开仓条件 then begin
开仓语句;
n:=h;
end
if h>n then n:=h;
if n-avgenterprice>50*mindiff and n-avgenterprice<100*mindiff and h-avgenterprice<0.5*(n-avgenterprice) then 平仓语句;
4.
variable:n=0;
if holding=0 and 开仓条件 then begin
开仓语句;
n:=h;
end
if h>n then n:=h;
if n-avgenterprice>100*mindiff and and h-avgenterprice>100*mindiff and h-avgenterprice<0.5*m then 平仓语句;
100+N中的N,在我的代码里面用M代替了
variable:n=0;
IF HOLDING=0 AND 多头条件 THEN BEGIN
BUY(1,1,THISCLOSE);
n:=h;
END
if enterbars>0 and holding>0 and L<avgenterprice-10*mindiff then sell(1,0,THISCLOSE); //止损
if h>n then n:=h;
if enterbars>0 and holding>0 and n-avgenterprice>50*mindiff and nn-avgenterprice<100*mindiff and h-avgenterprice<0.5*(n-avgenterprice) then sell(1,0,THISCLOSE); //止盈
if enterbars>0 and holding>0 and n-avgenterprice>100*mindiff and h-avgenterprice>100*mindiff and h-avgenterprice<0.5*M then sell(1,0,THISCLOSE); //折返止盈
写成这样后,为啥老提示“变量名N重复”呢
那说明你代码里面有其他地方也用N定义了
你把我代码里面的N改成其他字母,或者把你的N改成其他字母
if n-avgenterprice>100*mindiff and and h-avgenterprice>100*mindiff and h-avgenterprice<0.5*m then 平仓语句;
100+N中的N,在我的代码里面用M代替了
最后一行中的“h-avgenterprice<0.5*m ”,好像不能表达出“均价盈利大于100点时,以盈利100点的位置为低点,100+M点为高点,这段距离回落一半止盈”
M点是未知的,就是超过100点后的距离,需要自动判断
止盈保底线是100点,100点后多出的部分需要自动判断,这部分回撤一半就止盈
variable:n=0;
if holding=0 and 开仓条件 then begin
开仓语句;
n:=h;
end
if h>n then n:=h;
if n-avgenterprice>100*mindiff and and h-avgenterprice>100*mindiff and h-avgenterprice<(n-avgenterprice-100)/2 then 平仓语句;
明白了,多谢指导