改成
if barslast(cross(ema8,ema21))>0 and close<=ema8 then begin buy(holding=0,1000,thisclose); drawtext(holding>0,low,"買入"); end;
老師,您好:
我在上面的程序段中,加入了提高止損判斷語句。
當頭寸持倉盈利超過+4%后,若再次跌破EMA21,則止損離場;若盈利超過+8%,則止盈。
但代碼還是顯示不出來。
麻煩您能看一下嗎?
ema8:ema(close,8);
ema21:ema(close,21);
if barslast(cross(ema8,ema21))>0 and close<=ema8 then
buy(holding=0,1000,thisclose);
if close<enterprice*0.96 and holding>0 then
sell(1,holding,thisclose);
if close>=enterprice*1.04 and holding>0 then
begin
sell(close>=enterprice*1.08,holding,thisclose);
sell(close<=ema21,holding,thisclose);
end
ema8:ema(close,8);
ema21:ema(close,21);
if barslast(cross(ema8,ema21))>0 and close<=ema8 then
buy(holding=0,1000,thisclose);
if close<enterprice*0.96 and holding>0 and enterbars>0 then
sell(1,holding,thisclose);
if barslast(close>=enterprice*1.04)>0 and close>=enterprice*1.08 and holding>0 and enterbars>0 then
begin
sell(holding>0,holding,thisclose);
end
if barslast(close>=enterprice*1.04)>0 and close<=ema21 and holding>0 and enterbars>0 then
begin
改成
if barslast(cross(ema8,ema21))>0 and close<=ema8 then begin buy(holding=0,1000,thisclose); drawtext(holding>0,low,"買入"); end;