Keltner_ATR_Band_v1
Download scriptThis script is designed to provide a visual tool for traders that helps identify market volatility and potential price boundaries. Rather than following standard market trends, this tool focuses on creating a dynamic "channel" or boundary around the current price action based on historical data.
How the Logic Works
The script functions by calculating two distinct lines on your trading chart. It achieves this through a three-step calculation process performed automatically:
1. Establishing the Baseline (Moving Average) The tool first looks at the closing prices of the market over a specific period of time (defined by the "Maperiod" setting). It calculates a Simple Moving Average, which acts as the center point or the "fair value" of the asset at any given moment.
2. Measuring Market Volatility (ATR) To determine how wide the boundaries should be, the script measures the Average True Range (ATR). This is a calculation that tracks how much the price typically moves up and down over a set period. In simple terms, if the market is moving wildly, the ATR will be high; if the market is calm, the ATR will be low.
3. Plotting the Upper and Lower Bands Finally, the script combines these two pieces of information to draw two separate lines:
- The Upper Band: This is created by taking the baseline price and adding a multiple of the volatility measurement to it.
- The Lower Band: This is created by taking the baseline price and subtracting that same multiple of volatility from it.
Summary for the Trader
Because the width of these bands is tied directly to market volatility, the "channel" will automatically expand when the market becomes erratic and contract when the market stabilizes. This allows you to see a visual representation of the market's "normal" range, helping you identify instances where the price might be stretching too far in one direction relative to its recent behavior.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Keltner ATR Bands .mq4 |
//| This is not Keltner Channels |
//| |
//| Converted by : Dr. Gaines |
//| dr_richard_gaines@yahoo.com |
//| |
//+------------------------------------------------------------------+
#property copyright " Copyright © 2005, MetaQuotes Software Corp."
#property link " http://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 White
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| Common External variables |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| External variables |
//+------------------------------------------------------------------+
extern double MAPeriod = 50;
extern double ATRMult = 3.75;
//+------------------------------------------------------------------+
//| Special Convertion Functions |
//+------------------------------------------------------------------+
double ExtHistoBuffer[];
double ExtHistoBuffer2[];
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(1, ExtHistoBuffer2);
return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
double ma = 0;
double atr = 0;
double KU = 0;
double KL = 0;
int limit, shift;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
/*[[
Name := Keltner ATR Bands
Author := Copyright © 2005, MetaQuotes Software Corp.
Link := http://www.metaquotes.net/
Separate Window := No
First Color := White
First Draw Type := Line
First Symbol := 217
Use Second Data := Yes
Second Color := White
Second Draw Type := Line
Second Symbol := 218
]]*/
// loop from first bar to current bar (with shift=0)
for(shift=limit;shift>=0 ;shift--){
ma = iMA(NULL, 0, MAPeriod, 0, MODE_SMA, PRICE_CLOSE, shift);
atr = iATR(NULL, 0, MAPeriod, shift);
KU = ma + ATRMult*atr;
KL = ma - ATRMult*atr;
ExtHistoBuffer[shift] = KU;
ExtHistoBuffer2[shift] = KL;
}
return(0);
}
Comments