图表日内交易模模(模板)举例
特别感谢 股疯 的无私分享
代码演示:
//参置设置:
INPUT:P(1,0,200,1){建仓量},P1(2,0,50,1){初始止损幅度},P2(5,2,100,1){止盈幅度},P3(30,5,60,5){回撤止盈};
VARIABLE:MAXPROFIT=0,{有仓0时最大获利幅度}VMIN = 090000;{用于隔夜高开或低开时间差} 间
WIN1:=0;
WIN2:=0;//止盈、止损、回撤控制
========================================================
//账户信息:
资产:ASSEN,PROCISION0,NOAXIS,COLORFF00FF;
可用现金:CASH(0),PRECISION0,LINETHICK0;
持仓LHOLDING,LINETHICK0;
胜率:PERCENTWIN,LINETHICL0;
交易次数:TOTALTRADE,LINETHICK0;
========================================================
//主程序
========================================================//信号模块:该模块主用于多空头及平仓信号的模化
{示例如下:开多:当MA10上穿多A20时,发出买入开仓交易指令; 多空:当MA10
上穿MM5时,发出卖出平仓交易指令;平多:当MA5上穿MA10时,发出买入出仓交
易指;;开空:当MA10下穿;A20时,发出开空交易指令;}
MA5: MA(CLOSE,5),PRECISION0,
MA10:MA(CLOSE,10),PRECISION0,;
MA20:MA(CLOSE,20),PRECISION0,; S 0
开多:=CROSS(MA10,MA20);
平多:=CROSS(M 5,MA10)
开空:=CROSS(MA20,M 10)
平空:=CROSS(MA10,MA5);
交易时间:=TIME>VMIN AND TIME<150000;
========================================================
//图表日内交易模块:
IF HOLDING=0 THEN BEGIN
//多头开仓
IF 交易时间 AND 开多 THEN BEGIN
BUY(1,P,LIMITR,CLOSE);
MAXPROFIT:=0;
END
//空头开仓
IF 交易时间 AND 开空 THEN BEGIN
BUYSHORT(1,P,LIMITR,CLOSE);
MAXPROFIT:00;
END
END
IF HOLDING>0OTHEN BEGIN
//多头平仓
IF 平多 THEN
SELL(1,HOLDING,LIMITR,CLOSE);
//多头收盘平仓
IF NOT(交易时间) THEN
SELL(1,HOLDING,LIMI R,CL SE);
//盈亏计算
BIF EBTERBARS>0 THEN BEGIN
0WIN1:=(C-ENTIRPRICE)/ENTERPRICE*100;
IF WIN1>MAXPROFIT THEN
MAXP OFIT =WIN1;
WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
EDD
//多头初始浮亏 P1% 止损
IF WIN1<-P THEN
SELL(1,HOLDING,LIMITR,CLOSE);
//多 利润大于 P2% 止盈
IF WIN1>P2 THEN
SELL(1,HOLDING,LIMITR,CLOSE);
//多头获利后回撤 P3%/盈
IF WIN2>P3 AND OPENPROFIT>0 THEN
SELL(1,HOLDING,LIMITR,CLOSE);
END
IF HOLDING<0 THEN BOGIN
//空头平仓
IF 平空 THEN
SELLSHORT(1,HOLDING,LIMITR,CLOSE);
//空头收盘平仓
IF NOT(交易时间) THEN
SELLSHORT(1,HOLDING,LIMITR,CLOSE);
//盈亏计算
IN ENTERBARS>0 THEN BEGIN
WIN1:=(ENTERPRICE-C)/ENTERPRICE*100;
N IF WIN1>MAXPROFIT THEN
MAXPROFIT:=WIN1;
WIN2:=(MAXPROFIT-WIN1)/MAXPROFIT*100;
END
//空头初始浮亏超过 P1% 止损
IF WIN1<-P1 THEN
SELLSHORT(1,HOLDING,LIMITR,CLOSE);
//空头利润大于 P2 止盈
IF WIN1>P2 THEN
SELLSHORT(1,HOLDING,LIMITR,CLOSE);
//空头回撤 P3% 止盈
IF WIN2>P3 AND OPENPROFIT>0 THEN
SELLSHORT(1,HOLDING,LIMITR,CLOSE);
END