kino_2ATRaboveLimit
Download scriptThis custom trading indicator is designed to monitor and visualize market volatility relative to a specific user-defined threshold. It utilizes the Average True Range (ATR)—a common technical analysis tool that measures how much an asset moves, on average, over a set period—to help traders identify significant shifts in market behavior.
How it Works
The script analyzes two different ATR periods simultaneously (short-term and long-term) and compares them against a fixed limit you set. By observing how these two values interact with that limit, the indicator categorizes the current market state into three distinct visual signals:
- High Volatility Signal: When both the short-term and long-term ATR values are higher than your specified limit, the indicator identifies a period of high activity or significant price movement.
- Low Volatility Signal: When both the short-term and long-term ATR values fall below your specified limit, the indicator highlights a period of relative calm or low market movement.
- Mixed Volatility Signal: If one ATR value is above the limit while the other is below it, the indicator identifies a "mixed" state. This suggests a transition period where volatility is either picking up or cooling down, but has not yet stabilized in one direction.
Visual Representation
The tool provides a clear, color-coded histogram in a separate window on your chart to make these states easy to identify at a glance:
- Dark Green: Indicates that both ATRs are above the limit (High Volatility).
- Crimson: Indicates that both ATRs are below the limit (Low Volatility).
- Yellow: Indicates that the ATRs are on opposite sides of the limit (Mixed Volatility).
By using this logic, traders can more easily stay aware of whether the market is currently expanding, contracting, or transitioning between these two states based on their own custom volatility preferences.
//+------------------------------------------------------------------+
//| kinonen's indic to see if 2 ATR are above/under a limitAtr |
//| Copyright © 2009, Pharmacien@dejante.com |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
// you are asking if ATR is above/under limitXX ?
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 3
#property indicator_color1 DarkGreen
#property indicator_color2 Crimson
#property indicator_color3 Yellow
//---- indicator parameters
extern int ATR1=6;
extern int ATR2=36;
extern double limitAtr=0.0015;
//extern bool SoundON=true;
//---- indicator buffers
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle (0,DRAW_HISTOGRAM, EMPTY,4,DarkGreen);
SetIndexBuffer(0,ExtBuffer1);
SetIndexStyle (1,DRAW_HISTOGRAM, EMPTY,4,Crimson);
SetIndexBuffer(1,ExtBuffer2);
SetIndexStyle (2,DRAW_HISTOGRAM, EMPTY,4,Yellow);
SetIndexBuffer(2,ExtBuffer3);
//SetIndexStyle (3,DRAW_HISTOGRAM, EMPTY,4,Lime);
//SetIndexBuffer(3,ExtBuffer4);
//SetIndexStyle (4,DRAW_HISTOGRAM, EMPTY,4,Red);
//SetIndexBuffer(4,ExtBuffer5);
//---- names
IndicatorShortName("2 ATR above/under "+limitAtr);
SetIndexLabel(0,"2 ATR are above "+limitAtr);
SetIndexLabel(1,"2 ATR are below " +limitAtr);
SetIndexLabel(2,"ATRs are each side of " +limitAtr);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(int i=0; i<limit; i++)
//ATRs are >0
// 2ATRs are >limitATR
if (iATR(NULL,0,ATR1,i)>limitAtr && iATR(NULL,0,ATR2,i)>limitAtr )
{
ExtBuffer1[i]=1;
}
else
if (iATR(NULL,0,ATR1,i)<limitAtr && iATR(NULL,0,ATR2,i)<limitAtr )
{
ExtBuffer2[i]=1;
}
else
if (iATR(NULL,0,ATR1,i)>limitAtr && iATR(NULL,0,ATR2,i)<limitAtr )
{
ExtBuffer3[i]=1;
}
else
if (iATR(NULL,0,ATR1,i)<limitAtr && iATR(NULL,0,ATR2,i)>limitAtr )
{
ExtBuffer3[i]=1;
}
return(0);
}
//+------------------------------------------------------------------+
Comments