【MultiCharts(MC)程序化(量化)网上培训学习系列】第416节:经典策略范例“超级趋势(Supertrend)"量化策略、编写程式码、运行展示及进行初步回测
【MultiCharts(MC)程序化(量化)网上培训学习系列】第416节:经典策略范例“超级趋势(Supertrend)"量化策略、编写程式码、运行展示及进行初步回测[mp4]http://mp4.qhlt.club/Rec%200416.mp4[/mp4]
[size=14.4px]1、注册论坛会员即可免费获得公开课视频[/size][size=14.4px]源码[/size][size=14.4px]及文档;升级至付费会员免回复查看[/size][size=14.4px]策略源码[/size][size=14.4px]、文档;升级至prime会员无阻碍畅游全站[/size][size=14.4px]期货[/size][size=14.4px]策略、源码、回测、优化、视频、教程、图书、文档,具体参考:[/size][url=http://www.qhlt.cn/thread-37840-1-1.html]http://www.qhlt.cn/thread-37840-1-1.html[/url][size=14.4px];[/size]
[size=14.4px]2、通过期货论坛推荐新开立期货账号,可免费获得付费会员或prime会员资格并享受账户特惠政策,参考:[/size][url=http://www.qhlt.cn/thread-25049-1-1.html]http://www.qhlt.cn/thread-25049-1-1.html[/url][size=14.4px];[/size]
[size=14.4px]3、通过期货论坛开立期货账号并绑定MC享受专属优惠政策:[/size][url=http://www.qhlt.cn/thread-80442-1-1.html]http://www.qhlt.cn/thread-80442-1-1.html[/url][size=14.4px];[/size]
[size=14.4px]4、PC购买/服务器托管如何选择及量化软件相关设置指导:[/size][url=http://www.qhlt.cn/thread-105169-1-1.html]http://www.qhlt.cn/thread-105169-1-1.html[/url][size=14.4px];[/size]
[size=14.4px]5、全网最大策略源码区:[/size][url=http://www.qhlt.cn/forum-109-1.html]http://www.qhlt.cn/forum-109-1.html[/url][size=14.4px] ;策略精选推荐优化区:[/size][url=http://www.qhlt.cn/forum-874-1.html]http://www.qhlt.cn/forum-874-1.html[/url][size=14.4px];回测排名:[url=http://www.qhlt.cn/forum-877-1.html]http://www.qhlt.cn/forum-877-1.html[/url];[/size]
[size=14.4px]6、对视频中策略有困惑、想法、建议、优化?欢迎关注管理员微信进行切磋与交流。动动手,扫二维码加入微信群跟一众量化爱好者切磋吧:[/size]
[size=14.4px]管理员微信:[/size][img=120,120]http://www.qhlt.cn/link/wx.png[/img][size=14.4px] 论坛官方微信群:[/size][img=120,121]http://www.qhlt.cn/link/wg.png[/img][size=14.4px]电报群:[/size][img=120,120]http://p.algo2.net/2023/0622/54be45e3f790e.png[/img][size=14.4px];[/size] 程式码部分:[code]
Inputs:
ATRLength(10),
Multiplier(3.0);
Variables:
ATR(0),
UpperBand(0),
LowerBand(0),
Trend(1),
Supertrend(0),
PrevSupertrend(0),
PrevTrend(1);
// Calculate ATR
ATR = AvgTrueRange(ATRLength);
// Calculate Bands
UpperBand = (High + Low) / 2 + Multiplier * ATR;
LowerBand = (High + Low) / 2 - Multiplier * ATR;
// Supertrend Calculation
If CurrentBar = 1 then begin
Supertrend = UpperBand;
PrevTrend = 1;
end
else begin
if Close > PrevSupertrend then Supertrend = MaxList(LowerBand, PrevSupertrend)
else
Supertrend = MinList(UpperBand, PrevSupertrend);
if Close > Supertrend then Trend = 1
else if Close < Supertrend then Trend = -1;
end;
// --- Entry and Exit Rules ---
// Trend Change -> Entry Signals
if Trend <> PrevTrend then begin
if Trend = 1 then begin
// Close Short Position first
if MarketPosition < 0 then BuyToCover ("ExitShort") next bar at market;
// Open Long Position
Buy ("LongEntry") next bar at market;
end
else if Trend = -1 then begin
// Close Long Position first
if MarketPosition > 0 then Sell ("ExitLong") next bar at market;
// Open Short Position
SellShort ("ShortEntry") next bar at market;
end;
end;
// Save for next bar
PrevSupertrend = Supertrend;
PrevTrend = Trend;
[/code] 运行交易回测
[img]http://p.algo2.net/2025/0428/e1c5c084a50df.png[/img]
[img]http://p.algo2.net/2025/0428/e84027721f109.png[/img]
[img]http://p.algo2.net/2025/0428/cb91c4625a666.png[/img]
[img]http://p.algo2.net/2025/0428/f0e68f57d6281.png[/img]
[img]http://p.algo2.net/2025/0428/2de7d845dc48c.png[/img] 视频中程式码部分:
**** Hidden Message ***** 1、只要出趋势都能抓住。
2、振荡市场会亏损。
3、这不是一个全天候的策略,适合半自动化交易。即通过分析认为后市会出现趋势性行情,再开启此策略。
页:
[1]