This script is designed as a custom technical indicator for the MetaTrader platform. Its primary objective is to provide a smoothed momentum signal by identifying significant "extreme" price points and calculating a composite average based on those points.
Core Logic Overview
The script operates by looking back into historical price data to identify specific structural turns in the market. Instead of using a fixed time period (like a standard 14-day moving average), it dynamically searches for local peaks and troughs—referred to as "extremums"—to determine its calculation parameters.
Step-by-Step Process
1. Extremum Detection The script scans the preceding price candles to find points where the market direction shifted significantly. It specifically looks for structural "peaks" and "valleys." By identifying these local highs and lows, the tool attempts to filter out minor market noise and focus on the actual turning points of the price action.
2. Dynamic Period Assignment Once the script identifies these extreme points, it assigns them as dynamic periods. This means that if the market is volatile and moves quickly, the script adjusts its focus accordingly; if the market is calmer, it extends its look-back period to find more relevant data. It specifically tracks two different levels of these extremes to create a multi-layered analysis.
3. Momentum Calculation (RSI) For each of the identified extreme points, the script calculates a Relative Strength Index (RSI). The RSI is a standard momentum oscillator that measures the speed and change of price movements. By applying this to the dynamic periods discovered in the previous steps, the script generates two distinct momentum lines.
4. Composite Smoothing The final output displayed on the chart is a "smoothed" average. The script takes the two separate RSI values (derived from the different extreme points) and merges them into a single average line.
Summary for the User
Essentially, this tool acts as an intelligent momentum filter. Rather than telling you what the market is doing right now based on a static rule, it "scouts" the recent history to find where the real price turns occurred. It then calculates the momentum from those specific points and provides you with a single, averaged line that reflects the underlying trend of the market, filtered for stability.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Adaptosctry.mq4 - let it be |
//| Copyright © Telemah |
//| mailto:savemih@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © Telemah"
#property link "mailto:savemih@mail.ru"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DarkTurquoise
#property indicator_color2 Red
#property indicator_color3 Yellow
extern int CountBars=1000;
//extern double Po2=40; //Äëÿ âàðèàíòîâ ñ êîëè÷åñòâîì äâèæåíèÿ
//extern double Po1=120;
extern int nExtr1=3;
extern int nExtr2=6;
//extern int nFract1=2;
//extern int nFract2=6;
//extern int stochD=3; //Äëÿ ñòîõàñòèêà
//extern int stochslow=3;
//---- buffers
double Buf[];
double Buf1[];
double Buf2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(3);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(0,Buf);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Buf1);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,Buf2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Ind |
//+------------------------------------------------------------------+
int start()
{
SetIndexDrawBegin(0,Bars-CountBars+101);
SetIndexDrawBegin(1,Bars-CountBars+101);
SetIndexDrawBegin(2,Bars-CountBars+101);
int i,i1,i2,counted_bars=IndicatorCounted();
double con1,con2,Pe1,Pe2;
int iFlow[50],iFhigh[50],iEx[50],iExF[50],n,nl,nh,nf;
double BufCus[1000],BufFUP[1000],BufFLO[1000],pEx[50],pF[50],
pFhigh[50],pFlow[50],Fhigh[50],Flow[50],pEXhigh[50],pEXlow[50];
//----
if(CountBars<=101) return(0);
//---- initial zero
if(counted_bars<101)
{
for(i=1;i<=0;i++) Buf[CountBars-i]=0.0;
for(i=1;i<=0;i++) Buf1[CountBars-i]=0.0;
for(i=1;i<=0;i++) Buf2[CountBars-i]=0.0;
}
//----
i=CountBars-101-1;
// if(counted_bars>=101) i=Bars-counted_bars-1;
while(i>=0)
{
//++++++++++++++++++++++++++++++++++++++++++++++
//Äëÿ âàðèàíòîâ ñ êîëè÷åñòâîì äâèæåíèÿ
/*
for (i1=1;i1<=100;i1++)
{
con1+=MathAbs(Close[i+i1]-Open[i+i1]);
if (con1>=Po1*Point) {Pe1=i1;break;}
}
for (i2=1;i2<=100;i2++)
{
con2+=MathAbs(Close[i+i2]-Open[i+i2]);
if (con2>=Po2*Point) {Pe2=i2;break;}
}
con1=0;
con2=0;
*/
//+++++++++++++++++++++++++++++++++++++++++
//Äëÿ âàðèàíòîâ ñ ýêñòðåìóìàìè
BufCus[i]=iCustom(NULL,0,"FATL",CountBars,0,i);
for (i1=1;i1<=100;i1++)
{
if ((BufCus[i+i1]>BufCus[i+i1+1] && BufCus[i+i1+1]<BufCus[i+i1+2]) ||
(BufCus[i+i1]<BufCus[i+i1+1] && BufCus[i+i1+1]>BufCus[i+i1+2]))
{
n=n+1;iEx[n]=i1;pEx[n]=Close[i1];
if (n==nExtr1) {Pe1=iEx[n];}
if (n==nExtr2) {Pe2=iEx[n];}
}
/*
+++++++++++++++++++++++++++++++++++++++++++++++
if (BufCus[i+i1]>BufCus[i+i1+1] && BufCus[i+i1+1]<BufCus[i+i1+2])
{nl=nl+1;Flow[nl]=BufCus[i+i1+1];iFlow[nl]=i1;
pEXlow[nl]=Close[i1];}
if (BufCus[i+i1]<BufCus[i+i1+1] && BufCus[i+i1+1]>BufCus[i+i1+2])
{nh=nh+1;Fhigh[nh]=BufCus[i+i1+1];iFhigh[nh]=i1;
pEXhigh[nh]=Close[i1];}
+++++++++++++++++++++++++++++++++++++++++++++++
*/
}
n=0;
/*
+++++
nl=0;
nh=0;
+++++
*/
//++++++++++++++++++++++++++++++++++++++++
//Âàðèàíòû ñ êîëè÷åñòâîì ôðàêòàëîâ
/*
BufFUP[i]=iFractals(NULL,0,MODE_UPPER,i);
BufFLO[i]=iFractals(NULL,0,MODE_LOWER,i);
for (i1=3;i1<=103;i1++)
{
if (BufFUP[i+i1]!=0 || BufFLO[i+i1]!=0)
nf=nf+1;iExF[nf]=i1;pF[nf]=Close[i1]
if (nf==nFract1) {Pe1=iExF[nf];}
if (nf==nFract2) {Pe2=iExF[nf];}
}
nf=0;
*/
//++++++++++++++++++++++++++++++++++++++++
//Buf[i]=iCCI(NULL,0,Pe1,PRICE_CLOSE,i);
//Buf1[i]=iCCI(NULL,0,Pe2,PRICE_CLOSE,i);
Buf[i]=iRSI(NULL,0,Pe1,PRICE_CLOSE,i);
Buf1[i]=iRSI(NULL,0,Pe2,PRICE_CLOSE,i);
//Buf[i]=iStdDev(NULL,0,Pe1,MODE_SMA,0,PRICE_CLOSE,i);
//Buf1[i]=iStdDev(NULL,0,Pe2,MODE_SMA,0,PRICE_CLOSE,i);
//Buf[i]=iADX(NULL,0,Pe1,PRICE_CLOSE,MODE_MAIN,i);
//Buf1[i]=iADX(NULL,0,Pe2,PRICE_CLOSE,MODE_MAIN,i);
//Buf[i]=iStochastic(NULL,0,Pe1,stochD,stochslow,MODE_SMA,PRICE_CLOSE,MODE_MAIN,i);
//Buf1[i]=iStochastic(NULL,0,Pe2,stochD,stochslow,MODE_SMA,PRICE_CLOSE,MODE_MAIN,i);
//Buf[i]=iWPR(NULL,0,Pe1,i);
//Buf1[i]=iWPR(NULL,0,Pe2,i);
//Buf[i]=iForce(NULL,0,Pe1,MODE_SMA,PRICE_CLOSE,i);
//Buf1[i]=iForce(NULL,0,Pe2,MODE_SMA,PRICE_CLOSE,i);
//Buf[i]=iWPR(NULL,0,Pe1,i);
//Buf1[i]=iWPR(NULL,0,Pe2,i);
//Buf[i]=iRVI(NULL,0,Pe1,MODE_MAIN,i);
//Buf1[i]=iRVI(NULL,0,Pe2,MODE_MAIN,i);
//Buf[i]=iDeMarker(NULL,0,Pe1,i);
//Buf1[i]=iDeMarker(NULL,0,Pe2,i);
//Buf[i]=iMFI(NULL,0,Pe1,i);
//Buf1[i]=iMFI(NULL,0,Pe2,i);
//Buf[i]=iCustom(NULL,0,"J_TPO",Pe1,CountBars,0,i);
//Buf1[i]=iCustom(NULL,0,"J_TPO",Pe2,CountBars,0,i);
//Buf[i]=iCustom(NULL,0,"rsx",Pe1,0,i);
//Buf1[i]=iCustom(NULL,0,"rsx",Pe2,0,i);
Buf2[i]=(Buf[i]+Buf1[i])/2;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments