Board logo

标题: 【MultiCharts(MC)程序化(量化)网上培训学习系列】第416节:经典策略范例“超级趋势(Supertrend)"量化策略、编写程式码、运行展示及进行初步回测 [打印本页]

作者: 龙听    时间: 2025-4-28 05:46     标题: 【MultiCharts(MC)程序化(量化)网上培训学习系列】第416节:经典策略范例“超级趋势(Supertrend)"量化策略、编写程式码、运行展示及进行初步回测

【MultiCharts(MC)程序化(量化)网上培训学习系列】第416节:经典策略范例“超级趋势(Supertrend)"量化策略、编写程式码、运行展示及进行初步回测

[mp4]http://mp4.qhlt.club/Rec%200416.mp4[/mp4]

1、注册论坛会员即可免费获得公开课视频源码及文档;升级至付费会员免回复查看策略源码、文档;升级至prime会员无阻碍畅游全站期货策略、源码、回测、优化、视频、教程、图书、文档,具体参考:http://www.qhlt.cn/thread-37840-1-1.html

2、通过期货论坛推荐新开立期货账号,可免费获得付费会员或prime会员资格并享受账户特惠政策,参考:http://www.qhlt.cn/thread-25049-1-1.html

3、通过期货论坛开立期货账号并绑定MC享受专属优惠政策:http://www.qhlt.cn/thread-80442-1-1.html

4、PC购买/服务器托管如何选择及量化软件相关设置指导:http://www.qhlt.cn/thread-105169-1-1.html

5、全网最大策略源码区:http://www.qhlt.cn/forum-109-1.html ;策略精选推荐优化区:http://www.qhlt.cn/forum-874-1.html;回测排名:http://www.qhlt.cn/forum-877-1.html

6、对视频中策略有困惑、想法、建议、优化?欢迎关注管理员微信进行切磋与交流。动动手,扫二维码加入微信群跟一众量化爱好者切磋吧:

管理员微信: 论坛官方微信群:电报群:
作者: 龙听    时间: 2025-4-28 05:47

程式码部分:
  1. Inputs:
  2.     ATRLength(10),
  3.     Multiplier(3.0);

  4. Variables:
  5.     ATR(0),
  6.     UpperBand(0),
  7.     LowerBand(0),
  8.     Trend(1),
  9.     Supertrend(0),
  10.     PrevSupertrend(0),
  11.     PrevTrend(1);

  12. // Calculate ATR
  13. ATR = AvgTrueRange(ATRLength);

  14. // Calculate Bands
  15. UpperBand = (High + Low) / 2 + Multiplier * ATR;
  16. LowerBand = (High + Low) / 2 - Multiplier * ATR;

  17. // Supertrend Calculation
  18. If CurrentBar = 1 then begin
  19.     Supertrend = UpperBand;
  20.     PrevTrend = 1;
  21. end
  22. else begin
  23.     if Close > PrevSupertrend then Supertrend = MaxList(LowerBand, PrevSupertrend)
  24.     else
  25.         Supertrend = MinList(UpperBand, PrevSupertrend);

  26.     if Close > Supertrend then Trend = 1
  27.     else if Close < Supertrend then  Trend = -1;
  28. end;

  29. // --- Entry and Exit Rules ---
  30. // Trend Change -> Entry Signals
  31. if Trend <> PrevTrend then begin
  32.     if Trend = 1 then  begin
  33.         // Close Short Position first
  34.         if MarketPosition < 0 then BuyToCover ("ExitShort") next bar at market;
  35.         // Open Long Position
  36.         Buy ("LongEntry") next bar at market;
  37.     end
  38.     else if Trend = -1 then begin
  39.         // Close Long Position first
  40.         if MarketPosition > 0 then Sell ("ExitLong") next bar at market;
  41.         // Open Short Position
  42.         SellShort ("ShortEntry") next bar at market;
  43.     end;
  44. end;

  45. // Save for next bar
  46. PrevSupertrend = Supertrend;
  47. PrevTrend = Trend;
复制代码

作者: 龙听    时间: 2025-4-28 06:15

运行交易回测





作者: 龙听    时间: 2025-4-28 06:16

视频中程式码部分:
本帖隐藏的内容需要回复才可以浏览

作者: 龙听    时间: 2025-4-28 06:17

1、只要出趋势都能抓住。
2、振荡市场会亏损。
3、这不是一个全天候的策略,适合半自动化交易。即通过分析认为后市会出现趋势性行情,再开启此策略。




欢迎光临 龙听期货论坛 (http://www.qhlt.cn/) Powered by Discuz! 7.2