This tool is designed to act as a visual guide on your trading charts, helping you identify potential momentum shifts by combining two primary market factors: trend direction and market volatility. Instead of just looking at price movement in isolation, the logic evaluates how the "average" price behaves relative to how much the market is currently swinging.
How the Logic Works
The script operates by calculating a specific moving average (the "smooth" path of the price) over a set period. It then compares the current state of this moving average against its previous position to determine the trend:
- Upward Momentum: If the moving average is currently higher than it was in the previous period, the script identifies an upward trend.
- Downward Momentum: If the moving average is lower than it was in the previous period, the script identifies a downward trend.
The "Volatility Buffer"
What makes this specific logic unique is that it doesn't just signal a trend; it measures the strength of that trend using a volatility indicator (ATR). By calculating the difference between the moving average and this volatility measure, the script creates a calculated buffer.
Visual Representation
On your chart, this logic translates into visual markers:
- Trend Signals: When the moving average moves upward, the script prepares to display a signal based on that rise.
- Counter-Trend Signals: When the moving average moves downward, it identifies the corresponding opposite signal.
In simple terms, the script filters out the "noise" of the market by looking for consistent shifts in the trend line while simultaneously accounting for how much the price is fluctuating. It highlights these specific moments on your screen so you can see where the momentum is trending and how much "room" there is based on current market volatility.
//+------------------------------------------------------------------+
//| buy_sell.mq4 |
//| "pip" |
//+------------------------------------------------------------------+
#property copyright "pupok"
#property link "bobik@trah.guchka.eu"
#property indicator_chart_window
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_buffers 2
int Range=14;
int ATR=60;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];
//----------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
SetIndexBuffer(1, ExtHistoBuffer2);
SetIndexArrow(1,159);
SetIndexArrow(0,159);
return(0);
}
void start()
{
ExtHistoBuffer[0] = EMPTY_VALUE;
ExtHistoBuffer2[0] = EMPTY_VALUE;
int counted = IndicatorCounted();
if (counted < 0) return (-1);
if (counted > 0) counted--;
int limit = Bars-counted;
for (int i=limit; i >= 0; i--)
{
double ma=iMA(NULL,0,Range,0,0,4,i);
double ma1=iMA(NULL,0,Range,0,0,4,i+1);
double dma;
dma=iATR(NULL, 0, ATR, i);
if (ma>ma1)
ExtHistoBuffer[i] =ma-dma;
if (ma<ma1)
ExtHistoBuffer2[i] =ma+dma ;
}
}
Comments