金肯特纳交易策略&改 (已编辑)
[font=inherit][size=17pt][font=inherit]金肯特纳交易策略&改[/font][/size][/font]
[p=22, 2, left][img=500,777]https://forum.multicharts.cn/forum/resc/post_images/1254/a6646c33ba9d40a9f8145fbe4e204e2d.png[/img][/p][list][*][b]前言[/b][/list] [font=inherit]最近有一些用户私信我:老师,我之前用XX软件做交易,现在想转到MC,策略不知道怎么写,能请给我一个范例好让我知道要怎么把自己的逻辑转换过来吗?我想了一下,这个需求有一定普遍性,所以有了今天这篇文章。[/font][list][*]原始策略逻辑[*][/list][font=inherit][size=17.3333px]
系统构成:[/size][/font][font=inherit][size=11pt]基于最高价、最低价、收盘价三者平均值计算而来的三价均线 [/size][/font][font=inherit][size=11pt]基于三价均线加减真实波幅计算而来的通道上下轨 [/size][/font][font=inherit][size=17.3333px]
入场条件:[/size][/font][font=inherit][size=11pt]三价均线向上,并且价格上破通道上轨,开多单 [/size][/font][font=inherit][size=11pt]三价均线向下,并且价格下破通道下轨,开空单 [/size][/font]
[font=inherit][size=17.3333px]出场条件:[/size][/font][font=inherit][size=11pt]持有多单时,价格下破三价均线,平多单 [/size][/font][font=inherit][size=11pt]持有空单时,价格上破三价均线,平空单 [/size][/font]
[font=inherit][size=17.3333px]
[/size][/font]
[font=inherit][size=17.3333px]回测设置:[/size][/font][font=inherit][size=11pt]HKEX.MHI HOT 5分钟,2016.10.25~至今,初始资金3w,固定一手[/size][/font][list][*][font=inherit][size=17pt]绩效[/size][/font][/list][img=500,716]https://forum.multicharts.cn/forum/resc/post_images/1254/d565530ce8670cb977b8bef4da1d68df.png[/img] 一共交易3328次,[font=inherit][size=11pt]已实现净利11.7w,账户资金收益比518%,初始资金收益比392%,最大潜在亏损31.4%,年化收益195%。[/size][/font][font=inherit][size=11pt] 这种通道突破类型的策略,我们去检查信号就会发现,在盘整期有太多不必要的进场。[/size][/font][p=22, 2, left][font=inherit][size=11pt][img=500,187]https://forum.multicharts.cn/forum/resc/post_images/1254/4db17647dd1f4e97f6a6e3dab1a0dfb5.png[/img][/size][/font][/p][font=inherit][size=11pt]因此,尝试结合上一次和大家分享的RSRS指标判断,看能否过滤一些不必要的进场。[/size][/font] [list][*][font=inherit][size=17pt]更改策略绩效[/size][/font][/list][font=inherit][size=17pt][img=800,703]https://forum.multicharts.cn/forum/resc/post_images/1254/df25def58e31a8a6ed9a3497c128f550.png[/img][/size][/font][font=inherit][size=11pt] 对比原始策略,交易次数减少到了2415笔,已实现净利增加2w,账户资金收益比增加36个百分点,初始资金收益比增加了66个百分点,最大潜在亏损降低7个百分点,年化收益增加33个百分点,可以说是全面胜出了。[/size][/font][font=inherit][size=11pt]再来看盘整部分的信号,超过一半的无效信号被过滤了。[/size][/font][p=22, 2, left][font=inherit][size=11pt][img=800,331]https://forum.multicharts.cn/forum/resc/post_images/1254/6c7f1fd0829ba90172eece0bb3e2ce3c.png[/img][/size][/font][/p][list][*]后记[/list] [font=inherit][size=11pt]有不少用户之前用其他软件在做量化交易,[font=inherit]因为MC有更佳的稳定性和自由度,现在要转换到MC平台上,遇到的问题主要是两个方面:一、语法;二、逻辑。[/font]本篇选择这样一个比较有代表性的策略转换到MC,文末提供源码下载,可以自己对照着MC的代码,领会一下如何转换,有问题欢迎给我留言。[/size][/font] 主图指标源码:
[code]
input:avglength(40),atrlength(40);
var:movavgval(0),upBand(0),downBand(0),mp(0);
movavgval=average((high+low+close)/3,avglength);
upBand=movavgval+AvgTrueRange(atrlength);
downBand=movavgval-AvgTrueRange(atrlength);
plot1(movavgval);
plot2(upBand);
plot3(downBand);
[/code]
信号策略源码:
**** Hidden Message *****
效果图如下:
[img]http://p.qhlt.cn/filestores/2018/12/25/2a501dbcd29aea3b097deb50911c8346.png[/img] 导入文档下载:**** Hidden Message ***** 感謝 谢谢分享 看看 感謝 謝謝 谢谢 谢谢! 谢谢分享 感谢 {:smile:} 谢谢 谢谢!好好学习。 看看 谢谢 老师发个改进的文华版源码出来吧,谢谢 谢谢分享 感谢版主分享! 感谢版主分享 感谢 Input:price1(close of data1),price2(close of data2);
var:mp(0),timecondition(False),timecondition1(False),timecondition2(False),filtercondition1(False),filtercondition2(False),buycondition(False),sellcondition(False),hltime1(False),hltime2(False),hltime(False);{global var}
var:ma1(0),ma2(0);{filter var}
var:VAR1(0),VAR2(0),beginbar(0),std(0),ma(0);{strategy var}
mp = marketposition;
//trading session model
timecondition1 = time>0930 and time< 1455;
timecondition2 = time>2130 and Time< 2255;
timecondition = timecondition1 or timecondition2;
hltime1 = time > 0905 and Time < 0915;{2high2sell or 2low2buy time}
hltime2 = time > 2105 and time < 2115;
hltime = hltime1 or hltime2;
//filter net model
ma1 = Average(close,5) of data2;
ma2 = Average(close,10)of data2;
filtercondition1 = ma1 > ma2 and Close > minlist(ma1,ma2); //bulltrend
filtercondition2 = ma1 < ma2 and Close < maxlist(ma1,ma2); //beartrend
//strategy model-{Aberration}
{first enter}
ma = Average(price1,35);
std = StandardDev(price1,35,1);
var1 = ma + 2*std;
var2 = ma - 2*std;
buycondition = price1 > var1;
sellcondition = price1 < var2;
{second entry}
condition1 = close[1] < var2[1] and Close > var2;
condition2 = Close[1] > var1[1] and Close < var1;
{buy/sell model}
if mp=0 then begin
if filtercondition1 and buycondition and timecondition then begin
buy("breakout-buy") 1 shares next bar at market;
end;
if filtercondition1 and condition1 and hltime then begin
buy("2low-buy") 1 shares next bar at market;
end;
if filtercondition2 and sellcondition and timecondition then begin
sellshort("breakdown-sell") 1 shares next bar at market;
end;
if filtercondition2 and condition2 and hltime then begin
sellshort("2high-sell") 1 shares next bar at market;
end;
end;
//strategy-exit
if mp=1 and Close < ma and Close-entryprice >= 5 then sell("long-exit") 1 shares next bar at market;
if mp=-1 and Close > ma and entryprice - Close>= 5 then buytocover("short-exit") 1 shares next bar at market;
//time-exit model
if mp<>0 then begin
if Time>1455 and time <1500 then begin
if mp=-1 then buytocover("short-exit at 14:55")1 shares next bar at market;
if mp= 1 then sell("long-exit at 14:55")1 shares next bar at market;
end;
if Time>2255 and time <2300 then begin
if mp=-1 then buytocover("short-exit at 22:55") 1 shares next bar at market;
if mp= 1 then sell("long-exit at 22:55") 1 shares next bar at market;
end;
end;
//set-stop model
if mp<>0 then begin
SetStopContract;
SetProfitTarget(150);
SetPercentTrailing(140,50);
end;
//check model {if strategy has problem,use print check}
{print(ma1);} 谢谢分享! 谢谢! 感謝分享 谢谢分享 学习学习 学习
页:
[1]