肯特纳通道(MT4 MT5指标) 是 由Chester W. Keltner于1960年创建的一种经典的技术分析指标。该指标在某种程度上与布林带和轨道线指标类似。该指标使用三根线:中线是使用10日简单移动平均线来表示典型的价格,上线和下线分别由加上或者减去距离中线的日价格范围移动平均数值(高位和低位的差值)组成。这样,就创建了一个基于波动范围的通道。您可以修改该指标这种版本移动平均线的所有参数。 输入参数:MA_Period (默认 = 10) — 移动平均线的时段(中线)。 Mode_MA (默认 = MODE_SMA) — 移动平均线的模式(中线)。 Price_Type (默认 = PRICE_TYPICAL) — 移动平均线应用的价格(中线)。
使用该指标进行交易的策略为:当价格收于带状上轨的上方时,做多;当价格收于带状下轨的下方时,做空。该指标是一种不错的进场系统。您可以使用传统的止损(正如您在图表中看到的,错误的信号并不常见),止盈以及与中线的交叉作为离场信号。部分交易商还建议使用其它指标进行确认。
MT4源码:
//+------------------------------------------------------------------+
//| Keltner Channel.mq4 |
// |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright � 2011, EarnForex.com"
#property link "; /*
Displays classical Keltner Channel technical indicator.
You can modify main MA period, mode of the MA and type of prices used in MA.
Buy when candle closes above the upper band.
Sell when candle closes below the lower band.
Use *very conservative* stop-loss and 3-4 times higher take-profit.
*/ #property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red //---- input parameters
extern int MA_Period = 10;
// 0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA
extern int Mode_MA = 0;
// 0 - Close, 1 - Open, 2 - High, 3 - Low, 4 - Median, 5 - Typical, 6 - Weighted
extern int Price_Type = 5; //----
double upper[], middle[], lower[]; //+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0, upper);
SetIndexStyle(0, DRAW_LINE);
SetIndexShift(0, 0);
SetIndexDrawBegin(0, 0); SetIndexBuffer(1, middle);
SetIndexStyle(1, DRAW_LINE, STYLE_DASHDOT);
SetIndexShift(1, 0);
SetIndexDrawBegin(1, 0); SetIndexBuffer(2, lower);
SetIndexStyle(2, DRAW_LINE);
SetIndexShift(2, 0);
SetIndexDrawBegin(2, 0); SetIndexLabel(0, "KC-Up(" + MA_Period + ")");
SetIndexLabel(1, "KC-Mid(" + MA_Period + ")");
SetIndexLabel(2, "KC-Low(" + MA_Period + ")"); return(0);
} //+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
double avg;
int counted_bars = IndicatorCounted();
if (counted_bars < 0) return(-1);
if (Bars < MA_Period) return(0);
if (counted_bars > 0) counted_bars--;
limit = Bars - counted_bars;
if (limit > Bars - MA_Period) limit = Bars - MA_Period; for (int i = 0; i < limit; i++)
{
middle = iMA(NULL, 0, MA_Period, 0, Mode_MA, Price_Type, i);
avg = findAvg(MA_Period, i);
upper = middle + avg;
lower = middle - avg;
}
return(0);
} //+------------------------------------------------------------------+
//| Finds the moving average of the price ranges |
//+------------------------------------------------------------------+
double findAvg(int period, int shift)
{
double sum = 0; for (int i = shift; i < (shift + period); i++)
sum += High - Low; sum = sum / period;
return(sum);
}
//+------------------------------------------------------------------+
MT5源码:
//+------------------------------------------------------------------+
//| Keltner Channel.mq5 |
// |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright � 2011, *;
#property link "*;
#property version "1.0" #property description "Displays classical Keltner Channel technical indicator."
#property description "You can modify main MA period, mode of the MA and type of prices used in MA."
#property description "Buy when candle closes above the upper band."
#property description "Sell when candle closes below the lower band."
#property description "Use *very conservative* stop-loss and 3-4 times higher take-profit." #property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 3
#property indicator_width1 1
#property indicator_color1 Red
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_label1 "KC-Up"
#property indicator_width2 1
#property indicator_color2 Blue
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_DASHDOT
#property indicator_label2 "KC-Mid"
#property indicator_width3 1
#property indicator_color3 Red
#property indicator_type3 DRAW_LINE
#property indicator_style3 STYLE_SOLID
#property indicator_label3 "KC-Low" //---- input parameters
input int MA_Period = 10;
input ENUM_MA_METHOD Mode_MA = MODE_SMA;
input ENUM_APPLIED_PRICE Price_Type = PRICE_TYPICAL; //----
double upper[], middle[], lower[], MA_Buffer; //+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
SetIndexBuffer(0, upper, INDICATOR_DATA);
SetIndexBuffer(1, middle, INDICATOR_DATA);
SetIndexBuffer(2, lower, INDICATOR_DATA); IndicatorSetString(INDICATOR_SHORTNAME, "KC(" + IntegerToString(MA_Period) + ")");
} //+------------------------------------------------------------------+
//| 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[])
{
int limit;
double avg;
int counted_bars = prev_calculated; if (counted_bars < 0) return(-1);
if (counted_bars > 0) counted_bars--;
limit = counted_bars; if (limit < MA_Period) limit = MA_Period; int myMA = iMA(NULL, 0, MA_Period, 0, Mode_MA, Price_Type);
if (CopyBuffer(myMA, 0, 0, rates_total, middle) != rates_total) return(0); for (int i = rates_total - 1; i >= limit; i--)
{
avg = findAvg(MA_Period, i, High, Low);
upper = middle + avg;
lower = middle - avg;
}
return(rates_total);
} //+------------------------------------------------------------------+
//| Finds the moving average of the price ranges |
//+------------------------------------------------------------------+
double findAvg(int period, int shift, const double &High[], const double &Low[])
{
double sum = 0; for (int i = shift; i > (shift - period); i--)
sum += High - Low; sum = sum / period;
return(sum);
}
//+------------------------------------------------------------------+
|