Volatility.Pivot_v1
Download scriptThis tool is designed to help traders visualize market volatility and identify potential price "pivot" levels by calculating dynamic support and resistance zones. Rather than using fixed numbers, it adapts to the current behavior of the market, making it useful for identifying where price might react or stall.
Core Logic Overview
The script functions by analyzing two primary elements: Market Volatility and Price Action Trajectory. Here is a breakdown of how it processes data to create the visual output:
1. Measuring Market Movement (Volatility)
The tool first measures how much the market is currently "swinging." It calculates an Average True Range (ATR), which provides a baseline for normal price movement over a specific period. By smoothing this data, the script creates a "volatility buffer"—a measurement of how much the price typically moves in a given timeframe.
2. Dynamic Distance Calculation
Depending on your settings, the tool determines how far away from the current price it should look for a reaction:
- Volatility-Based Mode: It takes the smoothed volatility measurement and multiplies it by a specific factor. This means that during high-volatility periods (large moves), the "buffer" expands; during quiet periods (small moves), the "buffer" shrinks.
- Fixed Price Mode: It uses a constant, pre-defined price distance regardless of market conditions.
3. The Pivot Tracking Mechanism
The script then tracks the "Stop" level (the line you see on your chart). Its logic follows these three behaviors:
- Stability: If the current closing price is exactly on the previous stop level, the line holds steady.
- Trend Following: If the price is moving consistently in one direction (staying above or below the previous level), the script attempts to "trail" that movement. It adjusts the line only enough to maintain a specific distance from the price based on the volatility buffer calculated in step 2.
- Reaction Detection: If the price suddenly crosses the previous stop level, the script immediately resets and "anchors" a new level at a set distance from that crossing point.
Summary for the Trader
Essentially, this script acts as a dynamic trailing boundary. It tries to stay "behind" the price movement, maintaining a gap that adjusts automatically based on how fast or slow the market is moving. This helps traders visualize a "no-man's land"—a zone where, if the price penetrates it, the current trend may be losing steam or undergoing a significant shift in sentiment.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Volatility.Pivot.mq4 |
//+------------------------------------------------------------------+
#property copyright "thanks to S.B.T. (Japan)"
#property link "http://sufx.core.t3-ism.net/" //<<< convert this from VT, thanks mate !!!
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DarkSeaGreen
//---- input parameters
extern double atr_range=100;
extern double ima_range = 10;
extern double atr_factor=3;
extern int Mode = 0;
extern double DeltaPrice = 30;
//---- buffers
double TrStop[];
double ATR[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(0, TrStop);
SetIndexStyle(1, DRAW_NONE);
SetIndexBuffer(1, ATR);
string short_name = "!! RisenbergVolatilityCapture";
IndicatorShortName(short_name);
SetIndexLabel(1,"range base");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit;
int i;
double DeltaStop;
limit = Bars;
for(i = 0; i < limit; i ++) {
ATR[i] = iATR(NULL,0,atr_range,i);
}
for(i = limit - 1; i >= 0; i --) {
if (Mode == 0) {
DeltaStop = iMAOnArray(ATR,0,ima_range,0,MODE_EMA,i) * atr_factor;
//DeltaStop = iATR(NULL,0,atr_range,i) * atr_factor;
} else {
DeltaStop = DeltaPrice*Point;
}
if (Close[i] == TrStop[i + 1]) {
TrStop[i] = TrStop[i + 1];
} else {
if (Close[i+1]<TrStop[i+1] && Close[i]<TrStop[i+1]) {
TrStop[i] = MathMin(TrStop[i + 1], Close[i] + DeltaStop);
} else {
if (Close[i+1]>TrStop[i+1] && Close[i]>TrStop[i+1]) {
TrStop[i] = MathMax(TrStop[i+1], Close[i] - DeltaStop);
} else {
if (Close[i] > TrStop[i+1]) TrStop[i] = Close[i] - DeltaStop; else TrStop[i] = Close[i] + DeltaStop;
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments