本帖最后由 技术006 于 2021-11-9 17:32 编辑
示例代码如下:
[PEL] 复制代码 EMA12:EMA(C,12);
EMA10:EMA(C,10);
EMA20:EMA(C,20);
EMA144:EMA(C,144);
EMA338:EMA(C,338);
atr:ma(TR,21);
//在EMA338日均线之上只做多(K线收盘价大于EMA338),K线收盘价格向上穿过EMA144日均线(指K线收盘价大于EMA144),同时EMA12向上穿过EMA144金叉(指EMA12金叉EMA144)。
KD1:close>EMA338 and close>ema144 and cross(ema12,ema144);
//EMA12均线向上穿过EMA338均线和E144均线金叉(EMA12与EMA338形成金叉,EMA12和E144形成金叉),EMA144均线向上穿过EMA338均线金叉(EMA144金叉EMA338)
KD2:cross(ema12,EMA338) AND cross(ema12,ema144) AND cross(ema144,ema338);
//条件1:在EMA338日均线之下只做空,K线收盘价格向下穿过EMA144日均线,同时EMA12向下穿过EMA144死叉。
KK1:close<EMA338 and close<ema144 and cross(ema144,ema12);
//条件2:EMA12均线向下穿过EMA338均线和E144均线死叉,EMA144均线向下穿过EMA338均线死叉,
KK2:cross(EMA338,ema12) AND cross(ema144,ema12) AND cross(ema338,ema144);
IF cross(ema20,ema10) and HOLDING>0 then BEGIN
sell(1,1,MARKETR);
END
IF cross(ema10,ema20) and HOLDING<0 then BEGIN
sellSHORT(1,1,MARKETR);
END
if kd1=1 or kd2=1 AND HOLDING=0 then BEGIN
buy(1,1,MARKETR);
END
if KK1=1 or KK2=1 AND HOLDING=0 then BEGIN
BUYSHORT(1,1,MARKETR);
END
//多头止损
if HHV(HIGH,ENTERBARS+1)-CLOSE>3*ATR and HOLDING>0 then BEGIN
sell(1,1,MARKETR);
END
//空头止损
if CLOSE-HHV(HIGH,ENTERBARS+1)>3*ATR and HOLDING<0 then BEGIN
sell(1,1,MARKETR);
END |