//+------------------------------------------------------------------+
//| Keltner Channels.mq4 |
//| Coded by Gilani |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 White
double upper[], middle[], lower[];
extern int period = 10;
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,0);
SetIndexDrawBegin(0,0);
SetIndexBuffer(0,upper);
SetIndexStyle(1,DRAW_LINE);
SetIndexShift(1,0);
SetIndexDrawBegin(1,0);
SetIndexBuffer(1,middle);
SetIndexStyle(2,DRAW_LINE);
SetIndexShift(2,0);
SetIndexDrawBegin(2,0);
SetIndexBuffer(2,lower);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
double avg;
for(int x=0; x<limit; x++) {
middle[x] = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);
avg = findAvg(period, x);
upper[x] = middle[x] + avg;
lower[x] = middle[x] - avg;
}
return(0);
}
//+------------------------------------------------------------------+
double findAvg(int period, int shift) {
double sum=0;
for (int x=shift;x<(shift+period);x++) {
sum += High[x]-Low[x];
}
sum = sum/period;
return (sum);
}
//| Keltner Channels.mq4 |
//| Coded by Gilani |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 White
double upper[], middle[], lower[];
extern int period = 10;
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,0);
SetIndexDrawBegin(0,0);
SetIndexBuffer(0,upper);
SetIndexStyle(1,DRAW_LINE);
SetIndexShift(1,0);
SetIndexDrawBegin(1,0);
SetIndexBuffer(1,middle);
SetIndexStyle(2,DRAW_LINE);
SetIndexShift(2,0);
SetIndexDrawBegin(2,0);
SetIndexBuffer(2,lower);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
double avg;
for(int x=0; x<limit; x++) {
middle[x] = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);
avg = findAvg(period, x);
upper[x] = middle[x] + avg;
lower[x] = middle[x] - avg;
}
return(0);
}
//+------------------------------------------------------------------+
double findAvg(int period, int shift) {
double sum=0;
for (int x=shift;x<(shift+period);x++) {
sum += High[x]-Low[x];
}
sum = sum/period;
return (sum);
}
//+------------------------------------------------------------------+
//| Keltner Channels.mq4 |
//| Coded by Gilani |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 White
extern int period_ma = 20;
extern int period_atr = 20;
extern double multiplier = 2.0;
double upper[], middle[], lower[];
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,0);
SetIndexDrawBegin(0,0);
SetIndexBuffer(0,upper);
SetIndexStyle(1,DRAW_LINE);
SetIndexShift(1,0);
SetIndexDrawBegin(1,0);
SetIndexBuffer(1,middle);
SetIndexStyle(2,DRAW_LINE);
SetIndexShift(2,0);
SetIndexDrawBegin(2,0);
SetIndexBuffer(2,lower);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int x=0; x<limit; x++) {
middle[x] = iMA(NULL, 0, period_ma, 0, MODE_EMA, PRICE_CLOSE, x);
upper[x] = middle[x] + (multiplier * iATR(NULL, 0, period_atr, x));
lower[x] = middle[x] - (multiplier * iATR(NULL, 0, period_atr, x));
}
return(0);
}
//+------------------------------------------------------------------+
//| Keltner Channels.mq4 |
//| Coded by Gilani |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 White
extern int period_ma = 20;
extern int period_atr = 20;
extern double multiplier = 2.0;
double upper[], middle[], lower[];
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,0);
SetIndexDrawBegin(0,0);
SetIndexBuffer(0,upper);
SetIndexStyle(1,DRAW_LINE);
SetIndexShift(1,0);
SetIndexDrawBegin(1,0);
SetIndexBuffer(1,middle);
SetIndexStyle(2,DRAW_LINE);
SetIndexShift(2,0);
SetIndexDrawBegin(2,0);
SetIndexBuffer(2,lower);
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int x=0; x<limit; x++) {
middle[x] = iMA(NULL, 0, period_ma, 0, MODE_EMA, PRICE_CLOSE, x);
upper[x] = middle[x] + (multiplier * iATR(NULL, 0, period_atr, x));
lower[x] = middle[x] - (multiplier * iATR(NULL, 0, period_atr, x));
}
return(0);
}
//+------------------------------------------------------------------+
Why is there two postings, does the second one work ?
Thanks for the effort
Thanks for the effort
Ok first thanks for doing it...just a couple of errors
The moving average used is Exponential should be SIMPLE...oops thats the first posting...I try that.
The moving average used is Exponential should be SIMPLE...oops thats the first posting...I try that.
The iATR function is not correct for the keltner channel
I used AVGRANGE, which is incorrect. Should be Average true range..this code is from Ts2000i Omega Tradestation.
Inputs :Price, Length, Factor;
KeltnerChannel = Average(Price, Length) + AvgTrueRange(Length) * Factor;
{Average is simple moving average}
************
AvgTrueRange = Average(TrueRange, Length);
{Average is simple moving average}
************
TrueRange = TrueHigh - trueLow;
************
TrueHigh
If close(Previous) > High(current) then TrueHIgh = Close(previous) else Truehigh = high;
TrueLow
If close(previous) < Low(current) then TrueLow = Low(Previous) else TrueLow = low;
Can you please fix your second posting with the above amendments. thanks.
I used AVGRANGE, which is incorrect. Should be Average true range..this code is from Ts2000i Omega Tradestation.
Inputs :Price, Length, Factor;
KeltnerChannel = Average(Price, Length) + AvgTrueRange(Length) * Factor;
{Average is simple moving average}
************
AvgTrueRange = Average(TrueRange, Length);
{Average is simple moving average}
************
TrueRange = TrueHigh - trueLow;
************
TrueHigh
If close(Previous) > High(current) then TrueHIgh = Close(previous) else Truehigh = high;
TrueLow
If close(previous) < Low(current) then TrueLow = Low(Previous) else TrueLow = low;
Can you please fix your second posting with the above amendments. thanks.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I use Keltner Channel extensively. And I was surprised that you did not already have it.
Formula from : http://www.tssupport.com/support/base/?action=article&id=1263
INPUTS: PRICE(CLOSE),MALEN(10),CONST(.8);
VARS: CENTLINE(0), AVGRANGE(0), UPPER(0), LOWER(0);
CENTLINE=AVERAGE(PRICE,MALEN);
AVGRANGE=AVERAGE(TRUERANGE,MALEN);
UPPER=CENTLINE+(AVGRANGE*CONST);
LOWER=CENTLINE-(AVGRANGE*CONST);
PLOT1(CENTLINE,"CENTLINE");
PLOT2(UPPER,"UPPER");
PLOT3(LOWER,"LOWER");
********TRUERANGE*****
True Range = TrueHigh - TrueLow;
*****TrueHigh*****
If close previous > high current then use close, otherwise use current high.
Switch for true low...
Are you able to do this for me as a Customer idicator,
Thanks