NRTR WATR-hist_v1
Download scriptThis tool is designed to analyze market price movements by calculating and visualizing volatility-adjusted trends directly on your trading chart. It helps traders identify the underlying momentum of a currency pair or asset by filtering out "noise" and focusing on significant price shifts.
Core Logic Overview
The script operates by measuring the average range of price movement (the distance between the highs and lows) over a specific timeframe. It then uses this data to determine whether the market is currently in an upward or downward trend based on several key mechanics:
1. Volatility Calculation (WATR) The indicator calculates a custom volatility value, often referred to as "WATR." This is not just a simple average; it applies a weighted calculation to the price range of recent candles. By looking back at a defined period, the script determines how much the market typically moves. It also includes specific adjustments for Japanese Yen pairs (USDJPY, GBPJPY, EURJPY) to account for different decimal scales in those markets.
2. Trend Identification The script tracks the direction of the market by comparing current closing prices against historical highs and lows.
- Bullish Movement: If the price breaks above a certain threshold relative to the calculated volatility, the tool identifies an upward trend.
- Bearish Movement: If the price drops below a corresponding threshold, it switches to identifying a downward trend.
3. Dynamic Adaptation The logic is designed to be flexible through "Variants." Depending on how you configure these settings, the script can prioritize different types of data:
- It can focus on very recent price action for immediate signals.
- It can look at a larger historical window to identify broader market structures.
- It can dynamically recalculate volatility on every single bar to ensure the trend detection stays current as market conditions change.
4. Visual Representation Instead of just providing a simple line, the script translates these mathematical calculations into visual histograms on your chart. It uses two distinct colors (Tomato and DeepSkyBlue) to represent different trend states:
- One color highlights when the price action is conforming to an upward trajectory.
- The other color highlights when the price action is moving downward.
How it works in practice
When you load this on a chart, the script looks at the historical data you have specified (e.g., the last 300 bars). It calculates the "strength" of the move based on your chosen average period and then paints the chart to show you where the market is currently trending. If the price moves against the established trend with enough force—exceeding the calculated volatility—the script automatically flips the visual indicator to reflect the new direction.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| NRTR WATR.mq4 |
//| |
//| Ramdass - Conversion only |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Tomato
#property indicator_color2 DeepSkyBlue
//---- input parameters
extern int AveragePeriod=10;
extern int Variant=2;
extern int CountBars=300;
//---- buffers
double value1[];
double value2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_HISTOGRAM,0,2);//SetIndexStyle(0,DRAW_ARROW);
//SetIndexArrow(0,167);
SetIndexStyle(1,DRAW_HISTOGRAM,0,2);//SetIndexStyle(1,DRAW_ARROW);
//SetIndexArrow(1,167);
SetIndexStyle(2,DRAW_HISTOGRAM,0,2);
SetIndexStyle(3,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(0,value1);
SetIndexBuffer(1,value2);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| NRTR WATR |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars - AveragePeriod - 2;
// CountBars = CountBars - AveragePeriod - 3;
SetIndexDrawBegin(0,Bars-CountBars+1);
SetIndexDrawBegin(1,Bars-CountBars+1);
int i,i2,bar,counted_bars=IndicatorCounted();
double value,WATR;
double trend=1,dK,AvgRange,price,AveragePeriod_D;
AveragePeriod_D=AveragePeriod;
//----
if(Bars<=AveragePeriod) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=AveragePeriod;i++) value1[Bars-i]=0.0;
for(i=1;i<=AveragePeriod;i++) value2[Bars-i]=0.0;
}
AvgRange=0;
if ((Variant == 2) || (Variant == 3))
{
for (i=AveragePeriod; i>=1; i--)
{
dK = 1+(AveragePeriod_D-i)/AveragePeriod_D;
AvgRange=AvgRange + dK*MathAbs(High[i]-Low[i]);
}
if (Symbol()=="USDJPY" || Symbol()=="GBPJPY" || Symbol()=="EURJPY")
{WATR = AvgRange/AveragePeriod_D/100;}
else
{WATR = AvgRange/AveragePeriod_D;}
}
if (Variant == 1)
{
for (i=1; i<=AveragePeriod; i++)
{
dK = 1+(AveragePeriod_D-i)/AveragePeriod_D;
AvgRange=AvgRange + dK*MathAbs(High[CountBars + i]-Low[CountBars + i]);
}
WATR = AvgRange/AveragePeriod_D;
}
if (Close[CountBars-1] > Open[CountBars-1])
{
value1[CountBars - 1] = Close[CountBars - 1] * (1 - WATR);
trend = 1; value2[CountBars - 1] = 0.0;
}
if (Close[CountBars-1] < Open[CountBars-1])
{
value2[CountBars - 1] = Close[CountBars - 1] * (1 + WATR);
trend = -1; value1[CountBars - 1] = 0.0;
}
//----
bar=CountBars;
while(bar>=0)
{
value1[bar]=0.0; value2[bar]=0.0;
if (Variant == 3)
{
AvgRange=0;
for (i=1; i<=AveragePeriod; i++)
{
dK = 1+(AveragePeriod_D-i)/AveragePeriod_D;
AvgRange=AvgRange+ dK*MathAbs(High[bar + i]-Low[bar + i]);
}
WATR = AvgRange/AveragePeriod_D;
}
if (trend == 1)
{
if (Close[bar] > price) price = Close[bar];
value = price * (1 - WATR);
if (Close[bar] < value)
{
price = Close[bar];
value = price * (1 + WATR);
trend = -1;
}
}
if (trend == -1)
{
if (Close[bar] < price) price = Close[bar];
value = price * (1 + WATR);
if (Close[bar] > value)
{
price = Close[bar];
value = price * (1 - WATR);
trend = 1;
}
}
if (trend == 1) {value1[bar]=Low[bar]; value2[bar]=High[bar];}//if (trend == 1) {value1[bar]=value; value2[bar]=0.0;}
if (trend == -1) {value2[bar]=Low[bar]; value1[bar]=High[bar];}//if (trend == -1) {value2[bar]=value; value1[bar]=0.0;}
bar--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments