打印本文打印本文 关闭窗口关闭窗口

[求助]请教老师一个问题

作者:金字塔 来源:cxh99.com 发布时间:2015年02月11日
  • 咨询内容: 老师,您好~我想在代码里实现以下规则:一,买入条件当EMA8上穿EMA21成立后,K线回落至EMA8,即close<=ema8时,发出买入指令;二,平仓条件当CLOSE>=ENTERPRICE*1.08时,发出平仓指令;三,止损条件当CLOSE<=ENTERPRICE*0.96时,发出止损指令;四,当条件分别成立时,在发出指令的K线,做上标记;
    写的代码如下,但一直没有信号,请您改错并指正一下,非常感谢~
    ema8:=ema(close,8);ema21:=ema(close,21);
    if cross(ema8,ema21) then    begin        buy(close<=ema8,1000,thisclose);      drawtext(holding>0,low,"买入");    end;
    if holding>0 and close<enterprice*0.96 then  begin    sell(holding>0,holding,thisclose);    drawtext(holding=0,low,"止损");  end;
    if holding>0 and close>=enterprice*1.08 then   begin     sell(holding>0,holding,thisclose);     drawtext(holding=0,low,"平仓");   end;



     

  • 金字塔客服: if cross(ema8,ema21) then     begin         buy(close<=ema8,1000,thisclose);       drawtext(holding>0,low,"买入");     end;

     

     

    改成

     

    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因为barslast(cross(ema8,ema21))>0 代表了该条件成立,但当cross(ema21,ema8)之后,也会有做多信号发出。 若只想在可以cross(ema8,ema21))和cross(ema21,ema8)之间发出做多信号,需要添加什么条件? PS:非常感谢老师上面的解答~ 以下是引用jinzhe在2013/12/3 8:42:10的发言:
    if cross(ema8,ema21) then     begin         buy(close<=ema8,1000,thisclose);       drawtext(holding>0,low,"买入");     end;

     

     

    改成

     

    if barslast(cross(ema8,ema21))>0 and close<=ema8 then     begin         buy(holding=0,1000,thisclose);       drawtext(holding>0,low,"买入");     end;

打印本文打印本文 关闭窗口关闭窗口