New_Fractals_Lines_v1_0_1
Download scriptThis script is designed for the MetaTrader platform to assist traders in identifying and visualizing specific price action patterns known as "Fractals." It automatically scans historical price data to detect structural turning points and draws visual trend lines on the chart based on these signals.
Core Logic Overview
The tool functions by monitoring the high and low price points of candles to identify "Fractals"—which are essentially local peaks or valleys in price movement. Instead of showing every single fractal, the script applies a specific set of filters to ensure that only significant movements are highlighted.
1. Detection and Filtering
The script scans the market history to find upward and downward fractals. It includes a "cleaning" logic where it ignores instances where both an upward and downward fractal appear on the same candle, as these are considered neutral or redundant.
2. Momentum and Volume Analysis
To prevent the chart from becoming cluttered with minor price fluctuations, the script performs a mathematical comparison between consecutive fractals:
- Relative Strength: It calculates the average range (High minus Low) of the candles surrounding a fractal.
- Volume Weighting: It measures the trading volume associated with those specific price movements.
- The Comparison: When a new fractal is detected, the script compares its relative strength and volume against the previous fractal. A signal is only confirmed if the current movement shows a specific relationship in momentum compared to the last one (e.g., identifying if the "push" in price was stronger or weaker than before).
3. Visual Representation
Once a valid signal meets the filtering criteria, the script performs the following actions:
- Markers: It places colored arrows on the chart to indicate the identified trend points.
- Dynamic Trend Lines: The script automatically manages two trend lines (one for upward movements and one for downward movements).
- Real-time Updates: As new valid fractals are confirmed, the script dynamically moves the endpoints of these trend lines. This creates a visual "bridge" between the most recent significant price peaks and valleys, helping traders see the current trajectory of the market more clearly.
Summary for the User
Essentially, this tool acts as an automated filter. It watches the market for turning points but uses volume and price range calculations to "veto" weak signals. Only the strongest, most momentum-backed turns are highlighted with trend lines, helping you visualize the underlying structure of the market without the noise of minor price fluctuations.
//+------------------------------------------------------------------+
//| New_Fractals_Lines v1.0.1 |
//| Copyright © -2007, olyakish |
//| plutonia-dmb#yandex.ru |
//+------------------------------------------------------------------+
// èñïðàâèë ãëþê ñ "invalid time value for ObjectMove function"
#property copyright "olyakish"
#property link "plutonia-dmb#yandex.ru"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green // Ïðèñåäàþùèé
#property indicator_color2 Red // Ïðèñåäàþùèé
//----
extern int Pips = 5;
double ExtLimeBuffer[];
double ExtRedBuffer[];
//----
double AllHLDown, AllVolDown, AllHLUp, AllVolUp, AllMFIDown, AllMFIUp;
int OldFractal = 2;
bool Up = false, Down = false;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
SetIndexShift(0, 0);
SetIndexShift(1, 0);
//----
SetIndexBuffer(0, ExtLimeBuffer);
SetIndexBuffer(1, ExtRedBuffer);
//----
SetIndexStyle(0, DRAW_ARROW, 0, 1);
SetIndexStyle(1, DRAW_ARROW, 0, 1);
//----
SetIndexArrow(0, 177);
SetIndexArrow(1, 177);
//----
ObjectCreate("Up", OBJ_TREND, 0, iTime(NULL, 0, 2), High[2],
iTime(NULL, 0, 1), High[1],0,0);
ObjectSet("Up", OBJPROP_COLOR, Blue);
ObjectSet("Up", OBJPROP_RAY, true);
//----
ObjectCreate("Down", OBJ_TREND, 0, iTime(NULL, 0, 2), Low[2],
iTime(NULL, 0, 1), Low[1],0,0);
ObjectSet("Down", OBJPROP_COLOR, Brown);
ObjectSet("Down", OBJPROP_RAY, true);
//----
Comment("New_Fractals_Lines v1.0.1");
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("Up");
ObjectDelete("Down");
//----
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
ArrayInitialize(ExtLimeBuffer, NULL);
ArrayInitialize(ExtRedBuffer, NULL);
for(int i = 1000; i >= 3; i--)
{
// íàñ èíòåðåñóåò òîëüêî ñèòóàöèÿ êîãäà íà áàðå îäèí ôðàêòàë
// (â ëþáóþ ñòîðîíó)
// åñëè äâà ôðàêòàëà íà îäíîì áàðå, òî îòñåèâàåì òàêèå ñèòóàöèè
if(iFractals(NULL, 0, MODE_UPPER, i) != 0)
{
Up = true;
Down = false;
}
if(iFractals(NULL, 0, MODE_LOWER, i) != 0)
{
Up = false;
Down = true;
}
// äâà ôðàêòàëà ñðàçó - èãíîðèðóåì
if(iFractals(NULL, 0, MODE_UPPER, i) != 0 &&
iFractals(NULL, 0, MODE_LOWER,i) != 0)
{
Up = false;
Down = false;
}
// íà òåêóùåì áàðå åñòü ôðàêòàë âíèç
if(Up == false && Down == true)
{
AllHLDown = 0;
AllVolDown = 0;
AllHLDown = High[i+2] - Low[i+2] + High[i+1] -
Low[i+1] + High[i] - Low[i] + High[i-1] -
Low[i-1] + High[i-2] - Low[i-2];
AllVolDown = Volume[i+2] + Volume[i+1] + Volume[i] +
Volume[i-1] + Volume[i-2];
AllMFIDown = AllHLDown / AllVolDown;
// ïðåäûäóùèé ôðàêòàë áûë ââåðõ - ñðàâíèâàåì äâà ôðàêòàëà
// (ââåðõ è òåêóùèé âíèç)
if(OldFractal == 1)
{
// èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
if(AllMFIDown < AllMFIUp && AllVolDown > AllVolUp)
{
// çàïîëíÿåì áóôåðû
ExtLimeBuffer[i] = NULL;
ExtRedBuffer[i] = Low[i]; // - Pips*Point;
}
}
OldFractal = 0;
}
// íà òåêóùåì áàðå åñòü ôðàêòàë ââåðõ
if(Up == true && Down == false)
{
AllHLUp = 0;
AllVolUp = 0;
AllHLUp = High[i+2] - Low[i+2] + High[i+1] - Low[i+1] +
High[i] - Low[i] + High[i-1] - Low[i-1] +
High[i-2] - Low[i-2];
AllVolUp = Volume[i+2] + Volume[i+1] + Volume[i] +
Volume[i-1] + Volume[i-2];
AllMFIUp = AllHLUp / AllVolUp;
// ïðåäûäóùèé ôðàêòàë áûë âíèç - ñðàâíèâàåì äâà ôðàêòàëà
// (ââåðõ è òåêóùèé âíèç)
if(OldFractal == 0)
{
// èìååì ïðèñåäàþùèé ôðàêòàë (MFI - îáúåì +)
if(AllMFIUp < AllMFIDown && AllVolUp > AllVolDown)
{
// çàïîëíÿåì áóôåðû
ExtLimeBuffer[i] = High[i]; // + Pips*Point;
ExtRedBuffer[i] = NULL;
}
}
OldFractal = 1;
}
}
double _Price[2,2];
int _Time[2,2];
ArrayInitialize(_Price, -1);
ArrayInitialize(_Time, -1);
for(i = 3; i <= 1000; i++)
{
//up
if(ExtLimeBuffer[i] != NULL && _Price[0,0] != -1 &&
_Price[1,0] == -1 )
{
_Price[1,0] = ExtLimeBuffer[i];
_Time[1,0] = iTime(NULL, 0, i);
}
if(ExtLimeBuffer[i]!=NULL && _Price[0,0]==-1)
{
_Price[0,0] = ExtLimeBuffer[i];
_Time[0,0] = iTime(NULL, 0, i);
}
// down
if(ExtRedBuffer[i] != NULL && _Price[0,1] != -1 &&
_Price[1,1] == -1)
{
_Price[1,1] = ExtRedBuffer[i];
_Time[1,1] = iTime(NULL, 0, i);
}
if(ExtRedBuffer[i] != NULL && _Price[0,1] == -1)
{
_Price[0,1] = ExtRedBuffer[i];
_Time[0,1] = iTime(NULL, 0, i);
}
}
ObjectMove("Up", 1, _Time[0,0], _Price[0,0]);
ObjectMove("Up", 0, _Time[1,0], _Price[1,0]);
//----
ObjectMove("Down", 1, _Time[0,1], _Price[0,1]);
ObjectMove("Down", 0, _Time[1,1], _Price[1,1]);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments