inversereaction_new
Download scriptThe InverseReaction 1.3 indicator is designed to identify moments in the financial markets where price movements become statistically "unusual." It operates on the fundamental principle of mean reversion: the idea that when a market experiences a sudden, violent price swing that exceeds normal volatility limits, there is a high probability that an opposite (inverse) reaction will follow as the market seeks to correct itself.
Core Logic and Methodology
The script monitors the intensity of price changes by comparing current market action against a dynamic baseline. Here is how it processes data to generate signals:
1. Measuring Price Volatility Instead of looking at raw price points, the tool focuses on the "change" (the difference between the opening and closing prices). It calculates the magnitude of these movements over a short, rolling window of time. This allows the indicator to stay reactive to current market conditions rather than being weighed down by historical data that may no longer be relevant.
2. The Dynamic Confidence Level (DCL) The engine uses a specific calculation called the "Dynamic Confidence Level." It takes the average of recent price changes and multiplies them by a specific coefficient (the default being the Golden Ratio, 1.618). This establishes a "boundary" for what is considered normal market behavior. Because it uses a short rolling period, the indicator can quickly adapt to shifts in market speed—expanding its boundaries during high-volatility periods and tightening them during calm ones.
3. Identifying the "Inverse Reaction" The signal is triggered based on a comparison between the actual price change and the Dynamic Confidence Level:
- The Threshold: When the actual price movement significantly exceeds the calculated confidence limit, the market is flagged as having undergone an "unusual impact."
- The Signal: Once this threshold is breached, the indicator highlights a potential point of exhaustion. It suggests that the current momentum may be overextended and that a reversal—an inverse reaction—is likely to occur as the price corrects back toward its equilibrium.
Visual Representation
To make this data actionable for the user, the script provides two primary visual components:
- Change Analysis: It uses color-coded candles to represent the direction and magnitude of price movements.
- Confidence Signals: It plots specific markers (arrows) to indicate when the "Inverse Reaction" logic has been met. These signals serve as a warning that price action has reached an extreme state, potentially signaling a turning point in the trend.
//+------------------------------------------------------------------+
//| InverseReaction 1.3 |
//| 2013-2014 Erdem SEN |
//| http://login.mql5.com/en/users/erdogenes |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013-2015, Erdem Sen"
#property version "1.3"
#property link "http://login.mql5.com/en/users/erdogenes"
//---
#property description "This indicator is based on the idea of that an unusual impact"
#property description "in price changes will be adjusted by an inverse reaction."
#property description "The signal comes out when the price-change exceeds the possible"
#property description "volatility limits, then you can expect an inverse reaction."
//---
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots 2
//---
#property indicator_label1 "Changes"
#property indicator_label2 "Confidence"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_type2 DRAW_COLOR_ARROW
#property indicator_color1 clrGreen,clrRed,clrMagenta// candles color array
#property indicator_color2 clrGold,clrBlueViolet // signal color array
//--- input parameters
input double Coef = 1.618; // DCL Coefficient
input int MaPeriod = 3; // DCL Period
//--- Indicator buffers
double o[]; // zero price (it's here only to draw candles)
double h[]; // highest change (high price minus open price)
double l[]; // lowest change (low price minus open price)
double c[]; // main change (close price minus open price)
double clr1[]; // color buffer for bear and bull
double m[]; // confidence level
double clr2[]; // color buffer for levels
//---
int calcstart;
string name;
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int OnInit()
{
//--- verify the confidence coefficient
bool validation=(Coef>1 && Coef<=3);
if(!validation)
{
printf("Invalid value is determined for DCL Coefficient,\nit sould be in (1,3] interval. Error Code: %d",GetLastError());
return(INIT_PARAMETERS_INCORRECT);
}
//--- mapping
SetIndexBuffer(0,o,INDICATOR_DATA);
SetIndexBuffer(1,h,INDICATOR_DATA);
SetIndexBuffer(2,l,INDICATOR_DATA);
SetIndexBuffer(3,c,INDICATOR_DATA);
SetIndexBuffer(4,clr1,INDICATOR_COLOR_INDEX);
SetIndexBuffer(5,m,INDICATOR_DATA);
SetIndexBuffer(6,clr2,INDICATOR_COLOR_INDEX);
//--- shortname
name=StringFormat("IR(%d, %.2f)",MaPeriod,Coef);
IndicatorSetString(INDICATOR_SHORTNAME,name);
//--- arrow symbol
PlotIndexSetInteger(5,PLOT_ARROW,159);
//--- digits for vertical axis
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Calculation |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],
const double &open[],const double &high[],const double &low[],const double &close[],
const long &tick_volume[],const long &volume[],const int &spread[])
{
//--- prevent the recalculation
if(prev_calculated>rates_total || prev_calculated<=0) calcstart=0;
else calcstart=prev_calculated-1;
//--- calculate the buffers
for(int i=calcstart;i<rates_total;i++)
{
o[i] = 0.0;
h[i] = high[i] - open[i];
l[i] = low[i] - open[i];
c[i] = close[i] - open[i];
//---
if(open[i]>close[i])
{
clr1[i]=1;
m[i]=-DCL(i,MaPeriod,Coef,c);
}
else if(open[i]<close[i])
{
clr1[i]=0;
m[i]=DCL(i,MaPeriod,Coef,c);
}
else clr1[i]=2;
clr2[i]=(fabs(m[i])>fabs(c[i]));
}
return(rates_total);
}
/*---Dynamic Confidence Level (DCL)----------------------------------+
For stationary series with zero mean (like price changes) DCL can be calculated as
DCL = Multiplier * MovingAverage(AbsoluteChanges)
Just for example, when we use Golden Ratio as multiplier, with the perfect
conditions of normality, it gives us nearly 80% confidence levels:
StandardDeviation = Sqrt(Pi/2) * Mean(Abs(Changes))
GoldenRatio ~= z_%80 * Sqrt(Pi/2)
DCL(z_%80) ~= GoldenRatio * MovingAverage(Abs(Price Changes))
With large numbers of MovingAverage period, DCL aproximates to a static confidence
level. However, the system is dynamic and memory is very short for such economic
behaviors, so it is set with a small number (3 as default). Plus, considering the
HEAVY-TAIL problem, small period values will relatively response better!!!!
*/
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double DCL(const int position,const int period,const double coef,const double &price[])
{
double result=0.0;
if(position>=period-1 && period>0)
{
for(int i=0;i<period;i++) result+=fabs(price[position-i]);
result /= period;
result *= coef;
}
return(result);
}
//+------------------------------------------------------------------+
Comments