tpubw9f1ojrd811b0r_x6e0wf0d
Download scriptThis tool is designed to analyze historical price action on a trading chart to identify significant structural "swings"—specifically the peaks and valleys where the market changes direction. By scanning through a specified number of recent bars, the script filters out minor market noise to highlight only the most prominent price movements.
Core Logic Overview
The script operates by scanning the price data backward from the most recent history. It looks for specific price patterns to determine whether the market is making higher highs, lower lows, or moving into a "swing" state. Its primary goal is to identify the structural boundaries of the market.
Key Functional Components:
- Dynamic Range Analysis: The script examines a small, user-defined window of candles (the "Length") at each point in time. This allows it to compare the current price against its immediate neighbors to ensure that a high or low is statistically significant rather than just a minor fluctuation.
- Swing Identification:
- It looks for moments where the price breaks out beyond the recent highs or lows.
- If a candle's range completely engulfs the preceding period's highs and lows, the script identifies this as a major shift in momentum (a "swing").
- Peak and Valley Mapping:
- When a High Swing is confirmed, the script records the lowest point of that movement.
- When a Low Swing is confirmed, the script records the highest point of that movement.
- Structural Tracking: The logic tracks the "current" state of the market. If the market transitions from an upward trend to a downward trend (or vice versa), the script captures these transition points. It essentially marks the "ceiling" and "floor" of various price waves.
Visual Output
Instead of just showing a single line, the script identifies specific coordinates on the chart. By identifying these structural anchors, it provides a visual representation of the market's history, highlighting where significant reversals occurred and defining the previous price boundaries that may act as support or resistance levels for future trading.
//+------------------------------------------------------------------+
//| |
//| Copyright © 2000-2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.ru |
//+------------------------------------------------------------------+
// Êàçàõñêèé Óäàâ.mq4
#property copyright "ñëîâà - Mandor, ìóçûêà - íàðîäíàÿ"
#property link "mandorr@gmail.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Green
//----
extern int Length=6;
extern int CountBars=1000; // Êîëè÷åñòâî îòîáðàæàåìûõ áàðîâ
//----
double buffer[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void init()
{
SetIndexStyle(0,DRAW_SECTION,0,1);
SetIndexBuffer(0,buffer);
SetIndexLabel(0,"Value");
SetIndexDrawBegin(0,0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void start()
{
int shift, zu, zd, Swing, Swing_n;
double HH, LL, BH, BL;
//----
Swing=0;
Swing_n=0;
shift=CountBars-1;
zu=shift;
zd=shift;
BH=High[shift];
BL=Low[shift];
//----
for(shift=CountBars-1; shift>=0; shift--)
{
HH=High[Highest(NULL,0,MODE_HIGH,Length,shift+1)];
LL=Low [Lowest (NULL,0,MODE_LOW ,Length,shift+1)];
if (Low[shift]<LL && High[shift]>HH)
{
Swing=2;
if (Swing_n== 1) zu=shift+1;
if (Swing_n==-1) zd=shift+1;
}
else
{
if (Low [shift]<LL) Swing=-1;
if (High[shift]>HH) Swing= 1;
}
if (Swing!=Swing_n && Swing_n!=0)
{
if (Swing== 2) {Swing=-Swing_n; BH=High[shift]; BL=Low[shift];}
if (Swing== 1) buffer[zd]=BL;
if (Swing==-1) buffer[zu]=BH;
BH=High[shift];
BL=Low [shift];
}
if (Swing== 1) {if (High[shift]>=BH) {BH=High[shift]; zu=shift;}}
if (Swing==-1) {if (Low [shift]<=BL) {BL=Low [shift]; zd=shift;}}
Swing_n=Swing;
}
}
//+------------------------------------------------------------------+
Comments