Author: Crazy_Fox [UA]
BorChan

This script is designed to analyze market price movements by identifying significant structural turning points—specifically, the "highs" and "lows"—within a price chart. Instead of looking at every minor price flicker, the logic focuses on recognizing distinct peaks and valleys to help define the broader flow of the market.

How the Logic Works

1. Identifying Key Extremes The script scans the historical price data to locate two specific types of points:

  • Local Minimums: It looks for candles where the price bottom is lower than the candles immediately surrounding it (both on the left and the right).
  • Local Maximums: It looks for candles where the price peak is higher than the candles immediately surrounding it (both on the left and the right).

2. Establishing Market Structure Once these extremes are found, the script organizes them to determine the "path" of the market. It doesn't just look at one point in isolation; it compares the sequence of a minimum and a maximum to understand the direction of the trend:

  • If a low point occurs before a high point, it identifies a specific directional movement (an upward shift).
  • If a high point occurs before a low point, it identifies a downward shift.

3. Sequence Management The logic is programmed to handle complex scenarios where multiple peaks or valleys might occur close together. It intelligently selects the most relevant three points to form a structural sequence. This ensures that if the market creates a "double top" or "double bottom," the script can still correctly identify which point serves as the primary anchor for the trend.

4. Trend Orientation By calculating the chronological order of these peaks and valleys, the script determines a "Main Direction" (Up or Down). This allows it to categorize whether the current price action is moving towards a higher target or retreating toward a lower support level based on the most recent structural change.

Summary for the User

In simple terms, this tool acts like an automated scout that ignores the "noise" of the market and only marks down the significant mountains (highs) and valleys (lows). By connecting these points in order, it provides a clear picture of the market's primary structural direction.

10 Views
0 Downloads
0 Favorites
BorChan
#property copyright "Crazy_Fox [UA]"
#property link      "http://finlist.ru"
#property library

double x1=0.0, y1=0.0, x2=0.0, y2=0.0,
       x_l=0.0, y_l=0.0, x_f=0.0, y_f=0.0, x_m=0.0, y_m=0.0,
       step=0.0, l_border=0.0, h_border=0.0;

bool main_is_up=true;

int Extremum[3], f_bar=0, m_bar=0, l_bar=0;

//--------------------------------------- min_ext -----------------------------------------------
int min_ext(int bar)
{
	int i=bar, result=0;
	bool find=false;
	while (!find)
	{ // Åñëè i ìåíüøå ëèáî ðàâíî äâóì áëèçñòîÿùèì ñâå÷àì è ñîñåäÿì ýòèõ ñâå÷åé - ýòî íàø ìèíèìóì
		if ((Low[i-2]>=Low[i])&&(Low[i-1]>=Low[i])&&(Low[i]<=Low[i+1])&&(Low[i]<=Low[i+2]))
		{  result=i; find=true; }
		i++;
	}
	return(result);
}

//--------------------------------------- max_ext -----------------------------------------------
int max_ext(int bar)
{
	int i=bar, result=0;
	bool find=false;

	while (!find)
	{ // Åñëè i áîëüøå ëèáî ðàâíî äâóì áëèçñòîÿùèì ñâå÷àì è ñîñåäÿì ýòèõ ñâå÷åé - ýòî íàø ìàêñèìóì
		if ((High[i-2]<=High[i])&&(High[i-1]<=High[i])&&(High[i]>=High[i+1])&&(High[i]>=High[i+2]))
		{  result=i; find=true; }
	 	i++;
	}
	return(result);
}

//--------------------------------------- find_extremums ----------------------------------------
void find_extremums(int i)
{
	ArrayInitialize(Extremum,0);
 
	Extremum[0]=min_ext(i); y1=Low[Extremum[0]];  x1=Time[Extremum[0]]; // Èùåì ïåðâûé ìèíèìóì, îïðåäåëÿåì êîîðäèíàòû
	Extremum[1]=max_ext(i); y2=High[Extremum[1]]; x2=Time[Extremum[1]]; // Èùåì ïåðâûé ìàêñèìóì, îïðåäåëÿåì êîîðäèíàòû
           
	if (Extremum[0]<Extremum[1])  // Åñëè ìèíèìóì âñòðå÷àåòñÿ ðàíüøå ìàêñèìóìà - òðåòèé ýêñòðåìóì èùåì âíèçó
	{
		Extremum[2]=min_ext(Extremum[1]);  // Ôóíêöèÿ min_ext âîçâðàùàåò íîìåð ïåðâîãî ìèíèìóìà, ïîèñê íà÷èíàåòñÿ ñ
		y_l=Low[Extremum[2]]; x_l=Time[Extremum[2]];
		y_f=y1; x_f=x1; y_m=y2; x_m=x2;
		f_bar=Extremum[0]; m_bar=Extremum[1]; l_bar=Extremum[2];
		main_is_up=false;
	}
	if (Extremum[0]>Extremum[1])
	{
		Extremum[2]=max_ext(Extremum[0]);
		y_l=High[Extremum[2]]; x_l=Time[Extremum[2]];
		y_f=y2; x_f=x2; y_m=y1; x_m=x1;
		f_bar=Extremum[1]; m_bar=Extremum[0]; l_bar=Extremum[2];
		main_is_up=true;
	}

	if (Extremum[0]==Extremum[1])
		if (min_ext(Extremum[0]+1)<max_ext(Extremum[0]+2))
		{
			Extremum[2]=min_ext(Extremum[0]+2);
			y_l=Low[Extremum[2]]; x_l=Time[Extremum[2]];
			y_f=y1; x_f=x1; y_m=y2; x_m=x2;
			f_bar=Extremum[0]; m_bar=Extremum[1]; l_bar=Extremum[2];
			main_is_up=false;
		}
		else
		{
			Extremum[2]=max_ext(Extremum[0]+2);
			y_l=High[Extremum[2]]; x_l=Time[Extremum[2]];
			y_f=y2; x_f=x2; y_m=y1; x_m=x1;
			f_bar=Extremum[0]; m_bar=Extremum[1]; l_bar=Extremum[2];
			main_is_up=true;
		}
}

Comments