stop_level0
Download scriptThis script functions as a multi-layered technical analysis tool designed to identify and visualize "50% correction" levels within price movements. It tracks significant price fluctuations (extremums) and calculates the midpoint of those movements to help traders identify potential reversal zones or support/resistance levels.
Core Logic Overview
The indicator operates by monitoring the price action to identify major high and low points. Unlike simple moving averages, this logic is "event-driven" based on price distance. It identifies a new price movement when the market moves significantly far enough in one direction to be considered a distinct trend.
Once a movement is identified, the script calculates the 50% retracement point of that specific move. If the price continues to move beyond certain limits, it resets the calculation to account for the new, larger trend.
Key Functional Components
1. Multi-Layered Tracking (The 4 Lines) The script does not just look at one type of movement; it runs four separate calculations simultaneously. Each "line" is configured with different sensitivity settings:
- Minimum Amplitude: The minimum distance a price must travel to be considered a new move.
- Maximum Amplitude: A cap that prevents the indicator from reacting to excessively large, outlier movements (intended to filter out "noise" or abnormal spikes).
By using four different sets of sensitivities, the tool allows you to see corrections across various timeframes or volatility levels at once—from small, fast fluctuations to larger, more significant trend shifts.
2. Movement Detection & Reset Logic The script continuously monitors whether the current price is breaking out into a new "extremum":
- If the price moves up significantly, it updates the high point and calculates the 50% correction level based on that growth.
- If the price moves down significantly, it updates the low point and calculates the 50% correction level relative to that drop.
- Smart Filtering: If a movement is too small (below the minimum threshold), the script ignores it to prevent the lines from "jittering." If a move is too large (above the maximum threshold), it caps the calculation to maintain stability.
3. Visual Output Options The user can toggle how these levels are displayed on the chart:
- Correction Mode: Displays the 50% midpoint of the current price movement.
- Stop Level Mode: Instead of the midpoint, the script calculates and displays a specific "stop level" based on the amplitude of the move. This is designed to show where a trend might be considered "broken" or invalidated.
Summary for the User
In plain terms, this tool helps you see "how far the price has come" and "where the halfway point is." By looking at four different versions of these halfway points (with different sensitivities), you can get a comprehensive view of where price might pull back or stall, providing a visual guide for potential entry or exit points based on market symmetry.
//+------------------------------------------------------------------+
//| stop_level0.mq4 |
//| (c)kukan |
//| http://www.kukan.ru |
//+------------------------------------------------------------------+
#property copyright "(c)kukan"
#property link "http://www.kukan.ru"
//27 ìàðòà 2006 ã.
//íà èäåþ ñîçäàíèÿ ýòîãî èíäèêàòîðà íàòîëêíóë íå÷àéíî ïîëó÷èâøèéñÿ èíäèêàòîð
//many_line_2, êîòîðûé ïîêàçûâàåò òðàåêòîðèþ 50-òè ïðîöåíòíîé êîððåêöèè.
//äàííûé èíäèêàòîð ñîâìåùàåò â ñåáå 4 îäèíàêîâûõ èíäèêàòîðà ñ ðàçíûìè íàñòðîéêàìè
//
//ïðèíöèï ðàáîòû ñëåäóþùèé.... åñëè öåíà ïåðåñåêàåò 50-ïðîöåíòíóþ êîððåêöèþ,
//òî ëèíèÿ ïåðåñêàêèâàåò íà 50-ïðîöåíòíóþ êîððåêöèþ îò òîãî äâèæåíèÿ êîòîðîå ïåðåñåêëî.
//åñëè öåíà óøëà äàëüøå ÷åì íà "max_reset"
//
//äîïèñóþ 29 ìàðòà äîìà..... áîëåþ ÷óòü ïðîñòóäèôèëèñîì :)
//
//çàêàí÷èâàþ ïåðâûé âàðèàíò, ïîïðèñìàòðèâàþñü ê íåìó.... íàñòðîéêàìè ïîèãðàþñü....
//ïîñìîòðþ ÷òî ìîæíî óëó÷øèòü....
//
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DarkOrange //
#property indicator_color2 Goldenrod //
#property indicator_color3 DarkGoldenrod //
#property indicator_color4 Sienna //
//---- input parameters
#define qty_line 4 //êîëè÷åñòâî ëèíèé èíäèêîòîðà
extern int mix_ampli_0=25; //ìèíèìàëüíàÿ àìïëèòóäà äëÿ îïðåäåëåíèÿ ýêñòðåìóìà
extern int max_ampli_0=60; //ìàêñèìàëüíàÿ àìïëèòóäà -><-
extern bool line_0_yes=true; //ðèñîâàòü èëè íåò
extern int mix_ampli_1=40;
extern int max_ampli_1=100;
extern bool line_1_yes=true;
extern int mix_ampli_2=50;
extern int max_ampli_2=140;
extern bool line_2_yes=true;
extern int mix_ampli_3=60;
extern int max_ampli_3=180;
extern bool line_3_yes=true;
//
extern bool spread_yes=true; //ó÷èòûâàòü ñïðåä
extern bool fl_ofset=true; //ñìåùåíèå íà ïèïñ ââåðõ êàæäîé ëèíèè äëÿ óäîáñòâà âèçóàëèçàöèè
extern bool corr_or_lsp=false; //ëèíèÿ ðèñóåò êîððåêöèþ èëè óðîâåíü ñòîïà
extern bool fl_price_level=true; //ðèñîâàòü îáüåêòû öåíû óðîâíåé
//
extern int limit_bars=30000; //îãðàíè÷åíèå íà êîëëè÷åñòâî ñ÷èòàåìûõ áàðîâ
//àêòóàëüíî äëÿ òåõ ó êîãî â òåðìèíàëàõ î÷åíü áîëüøàÿ èñòîðèÿ
int ampli[qty_line]; //àìïëèòóäû ôèêñàöèè ýêñòðåìóìà
int ext_hl[qty_line]; //òåêóùèé ýêñòðåìóì 0-ëîó 1-õàé
bool corr_50_valid[qty_line]; //ñîâïàäåíèå öåíû ëèíèè ñ ðåàëüíîé êîððåêöèåé
double price_max[qty_line],price_min[qty_line]; //öåíû ìåæäó êîòîðûìè èäåò êîððåêöèÿ
double corr_50[qty_line]; //50% êîðååêöèÿ
double level_stop[qty_line]; //óðîâåíü ñòîïà
int i,ia=0;
int spread; //çíà÷åíè ñïðåäà â ïóíêòàõ
//èíäèêàòîðíûå áóôåðà
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
SetIndexBuffer(3,ind_buffer4);
//
ArrayInitialize(ind_buffer1,EMPTY_VALUE);
ArrayInitialize(ind_buffer2,EMPTY_VALUE);
ArrayInitialize(ind_buffer3,EMPTY_VALUE);
ArrayInitialize(ind_buffer4,EMPTY_VALUE);
//
spread=0;
if (spread_yes) spread=MarketInfo("EURUSD",MODE_SPREAD);
if (Bars-1>limit_bars) i=limit_bars;
else i=Bars-1;
ArrayInitialize(price_max,High[i]+spread*Point);
ArrayInitialize(price_min,Low[i]);
ArrayInitialize(corr_50_valid,false);
//
//èíèöèàëèçàöèÿ ïàðàìåòðà ôèêñàöèè ýêñòðåìóìà
ampli[0]=mix_ampli_0;
ampli[1]=mix_ampli_1;
ampli[2]=mix_ampli_2;
ampli[3]=mix_ampli_3;
//
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
i=Bars-counted_bars-1;
//
if (i>1 && false)
{//ïðîïóùåíî êàêîåòî êîëè÷åñòâî áàðîâ (áîëüøå îäíîãî) íóæíî ïåðåñ÷èòàòü
//âåñü èíäèêàòîð, ÷òîá ýòîò ôðàãìåíò ðàáîòàë íóæíî óáðàòü false â if
init();
}
if (i>limit_bars) i=limit_bars; //åñëè áàðîâ áîëüøå limit_bars, òî áóäåì ñ÷èòàòü limit_bars, à òî òÿæåëî
#define ofset_vg 0
while(i>=0)
{
if (corr_or_lsp)
{
//........................................................
if (!calc_extr(0,i,max_ampli_0,mix_ampli_0) && line_0_yes)
{
ind_buffer1[i]=corr_50[0]+(ofset_vg+0)*Point*fl_ofset;
}
if (!calc_extr(1,i,max_ampli_1,mix_ampli_1) && line_1_yes)
{
ind_buffer2[i]=corr_50[1]+(ofset_vg+1)*Point*fl_ofset;
}
if (!calc_extr(2,i,max_ampli_2,mix_ampli_2) && line_2_yes)
{
ind_buffer3[i]=corr_50[2]+(ofset_vg+2)*Point*fl_ofset;
}
if (!calc_extr(3,i,max_ampli_3,mix_ampli_3) && line_3_yes)
{
ind_buffer4[i]=corr_50[3]+(ofset_vg+3)*Point*fl_ofset;
}
//........................................................
}
else
{
//........................................................
if (!calc_extr(0,i,max_ampli_0,mix_ampli_0) && line_0_yes)
{
ind_buffer1[i]=level_stop[0]+(ofset_vg+0)*Point*fl_ofset;
}
if (!calc_extr(1,i,max_ampli_1,mix_ampli_1) && line_1_yes)
{
ind_buffer2[i]=level_stop[1]+(ofset_vg+1)*Point*fl_ofset;
}
if (!calc_extr(2,i,max_ampli_2,mix_ampli_2) && line_2_yes)
{
ind_buffer3[i]=level_stop[2]+(ofset_vg+2)*Point*fl_ofset;
}
if (!calc_extr(3,i,max_ampli_3,mix_ampli_3) && line_3_yes)
{
ind_buffer4[i]=level_stop[3]+(ofset_vg+3)*Point*fl_ofset;
}
//........................................................
}
//
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//ãëàâíàÿ ïðîöåäó îáñëóæèâàíèÿ ïåðåïèñîâàíèé ýêñòðåìóìîâ
//âõîäíîé ïàðàìåòð íîìåð ðàñ÷åòà,íîìåð áàðà, ìàêñèìàëüíûé àìïëèòóäà è ìèíèìàëüíàÿ
//ïðîöåäóðà âîçâðàùàåò ïåðåâîðîò ëèíèè
bool calc_extr(int number, int n_bars,int max_aml,int min_aml)
{
//_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
//ðàñ÷åò ïåðåâîðîòà ëèíèè.... â áàðå êîòîðîì ïåðåïèñàí ýêñòðåìóì íå ìîæåò áûòü ïåðåâîðîòà
//ñîîòâåòâåííî íóæíî âûáèðàòü ïðàâèëüíî òàéì ôðåéì äëÿ ýòîãî èíäèêàòîðà
if (ext_hl[number]==1)
{//âûøå ëèíèè--ñìîòðèì ðîæäåíèå ýêñòðåìóìà
if (Low[n_bars]<=price_max[number]-ampli[number]*Point)
{//ðîæäåí ýêñòðåìóì - ïåðåâîðîò corr_50_valid
price_min[number]=Low[n_bars];
ext_hl[number]=0;
//..........................................
calc_ampli(number,max_aml,min_aml);
//..........................................
return(true);//ïðîèçîøåë ïåðåâîðîò
}
}//îò âûøå ëèíèè
else
{//íèæå ëèíèè
if (High[n_bars]+spread*Point>=price_min[number]+ampli[number]*Point)
{//ðîæäåí ýêñòðåìóì - ïåðåâîðîò corr_50_valid
price_max[number]=High[n_bars]+spread*Point;
ext_hl[number]=1;
//..........................................
calc_ampli(number,max_aml,min_aml);
//..........................................
return(true);//ïðîèçîøåë ïåðåâîðîò
}
}//îò íèæå ëèíèè
//íå áûëî ïåðåâîðîòà
if (High[n_bars]+spread*Point>price_max[number])
{
//ýêñòðåìóì ïåðåïèñàí
price_max[number]=High[n_bars]+spread*Point;
ext_hl[number]=1;
//..........................................
calc_ampli(number,max_aml,min_aml);
//..........................................
}
if (Low[n_bars]<price_min[number])
{
//ýêñòðåìóì ïåðåïèñàí
price_min[number]=Low[n_bars];
ext_hl[number]=0;
//..........................................
calc_ampli(number,max_aml,min_aml);
//..........................................
}
return(false);//íå áûëî ïåðåâîðîòà
}
//+------------------------------------------------------------------+
void calc_ampli(int number,int max_aml,int min_aml)
{
corr_50[number]=(price_max[number]-price_min[number])*0.5+price_min[number];
ampli[number]=MathAbs((price_max[number]-corr_50[number])/Point);
//..........................................
corr_50_valid[number]=true;
if (ampli[number]<min_aml)
{
ampli[number]=min_aml; //ñëèøêîì ìåëêèå äâèæåíèÿ äëÿ ðåàêöèè
corr_50_valid[number]=false;
}
if (ampli[number]>max_aml)
{
ampli[number]=max_aml; //ïåðåñòàëè óøèðÿòüñÿ-îáû÷íûé òðàë-- "ñëèøêîì ìíîãî ïðèáûëè :))"
corr_50_valid[number]=false;
}
//..........................................
if (ext_hl[number]==1) level_stop[number]=price_max[number]-ampli[number]*Point;
else level_stop[number]=price_min[number]+ampli[number]*Point;
}
//+------------------------------------------------------------------+
Comments