,
下面是唐奇安通道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来分别获取周期内的高点和低点。


雷达卡



京公网安备 11010802022788号







