楼主: suffic
2941 0

[源码分享] MT5唐奇安通道【MQL5源码】 [推广有奖]

  • 2关注
  • 2粉丝

已卖:43份资源

大专生

20%

还不是VIP/贵宾

-

威望
0
论坛币
891 个
通用积分
3.8754
学术水平
10 点
热心指数
13 点
信用等级
11 点
经验
732 点
帖子
13
精华
0
在线时间
57 小时
注册时间
2018-3-30
最后登录
2025-9-13

楼主
suffic 发表于 2021-5-14 14:20:01 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
今天分享一个黄金的唐奇安通道图片。从图上来看,这么多年来,黄金基本上沿着通道的上轨上涨,中间回调到下轨之后,又开始拐头上涨。

月线黄金.png
下面是唐奇安通道MQL5的源码
//+------------------------------------------------------------------+
//|                                           AhaDonchainChannel.mq5 |
//|                                              Copyright 2021, AHA |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AHA"
#property link      "https://664849305.qq.com"
#property version   "1.00"
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_plots   2
//--- plot xian
#property indicator_label1  "highbound"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot jiantou
#property indicator_label2  "lowbound"
#property indicator_type2     DRAW_LINE
#property indicator_color2  clrOrange
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

input int donchain_period = 55;
//--- indicator buffers
double         highboundBuffer[];
double         lowboundBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,highboundBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,lowboundBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
//---
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, donchain_period);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, donchain_period);
   //ArraySetAsSeries(highboundBuffer, true);
   //ArraySetAsSeries(lowboundBuffer, true);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
      if(rates_total < donchain_period+1)
        {
            return 0;
        }
//---
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0)
      to_copy=rates_total;
   else
     {
      to_copy=prev_calculated;
      //if(prev_calculated>0)
      //   to_copy++;
     }
   for(int i=to_copy; i<rates_total; i++)
     {
      int start = i - donchain_period;
      if(start >= 0)
        {
         int high_index = ArrayMaximum(high, start, donchain_period);
         if(high_index >= 0)
           {
            highboundBuffer = high[high_index];
           }
         int lowindex = ArrayMinimum(low, start, donchain_period);
         if(lowindex >= 0)
           {
            lowboundBuffer = low[lowindex];
           }
        }

     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


代码非常简单,核心代码是调用ArrayMaximum和ArrayMinimum来分别获取周期内的高点和低点。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MT5 Indicator calculate Copyright iteration 量化交易策略 唐奇安通道

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jr
拉您进交流群
GMT+8, 2026-1-5 13:25