Adaptosctry_v2
Download scriptThis script is a technical analysis tool designed to identify and visualize specific price action trends by analyzing "extremes" in market data. Instead of relying on standard fixed periods (like a simple 14-day average), this logic dynamically calculates its own lookback periods based on how the market actually behaves, aiming to provide a more responsive view of momentum.
Core Logic Overview
1. Dynamic Extremum Detection The script scans historical price data to identify "peaks" and "valleys." It does this by looking for specific points where the value of a secondary indicator (specifically one named "FATL") changes direction—meaning it moves from an upward trend to a downward trend, or vice versa.
2. Smart Period Selection Unlike most indicators that use a static number for their calculations, this script:
- Scans back through the price history until it finds the first and second most recent "extreme" points.
- Automatically uses the distance (the number of bars) between the current price and these identified extremes to set its calculation window.
- This allows the indicator to automatically expand or contract its sensitivity based on whether the market is currently in a high-volatility state or a period of consolidation.
3. Multi-Layered Calculation The script processes these dynamic periods through two different lenses:
- It calculates an RSI (Relative Strength Index) for both identified extreme points independently.
- It then takes the average of these two RSI values to create a final, smoothed output.
Visual Output
The tool produces three distinct lines in a separate window on the trading platform:
- Line 1: The first dynamic RSI calculation (representing one extreme).
- Line 2: The second dynamic RSI calculation (representing the other extreme).
- Line 3: A combined average of both calculations, which serves as the primary smoothed signal for the user.
Summary for the User
In short, this script tries to "understand" the market's current rhythm. By identifying significant turning points in the price action rather than using a fixed timeline, it attempts to provide a more accurate representation of momentum that adapts automatically to changing market conditions.
//+------------------------------------------------------------------+
//| 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