This script is a visual trading tool designed to identify significant price movements on a chart by highlighting specific "strong" candles. Instead of providing every small fluctuation in the market, it filters the data to only display signals when a candle exceeds a predefined size, helping traders spot prominent trends more clearly.
How the Logic Works
1. Defining "Significant" Movement The script looks at the relationship between where a candle opens and where it closes. It uses a user-adjustable setting (the "Bars_Size") to determine the minimum distance a price must travel within a single bar to be considered noteworthy. If the movement is smaller than this threshold, the script ignores it.
2. Identifying Directional Strength The tool monitors two distinct types of movements:
- Bearish Movement: It detects instances where the price drops significantly from the opening point to the closing point.
- Bullish Movement: It detects instances where the price rises significantly from the opening point to the closing point.
3. Visual Signaling Once a movement meets the required size, the script places an arrow on the chart to alert the user:
- Red Arrows: These appear when a significant downward (bearish) move is detected.
- Green Arrows: These appear when a significant upward (bullish) move is detected.
4. Precision Placement To ensure the arrows do not clutter the actual price candles, the script calculates a specific distance above the high of the bar. It uses a technical calculation (the ATR, or Average True Range) to determine a consistent "offset." This places the visual signal just far enough above the candle so that it remains clearly visible without overlapping the trading data.
Summary for the User
In simple terms, this script acts as an automated filter. It scans the market history and "pings" you with an arrow only when the price makes a meaningful move in one direction. This allows you to ignore minor market noise and focus on the larger shifts in momentum.
//+------------------------------------------------------------------+
//| Stream.mq4 |
//| Yuriy Tokman (YTG) |
//| http://ytg.com.ua/ |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman (YTG)"
#property link "http://ytg.com.ua/"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_width1 4
#property indicator_width2 4
extern int Bars_Size = 50;
//---- buffers
double B0[];
double B1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,B0);
SetIndexBuffer(1,B1);
SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(0,242);
SetIndexArrow(1,241);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int limit=rates_total-prev_calculated;
if(prev_calculated==0)limit--;
else limit++;
for( int i=1; i<limit && !IsStopped(); i++)
{
if(Open[i]-Close[i]>=Bars_Size*Point)B0[i]=High[i]+iATR(Symbol(),0,21,i)/2;
if(Close[i]-Open[i]>=Bars_Size*Point)B1[i]=High[i]+iATR(Symbol(),0,21,i)/2;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments