InverseReaction

Author: Copyright 2013, Erdem Sen
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
InverseReaction
//+---------------------------------------------------------------------+
//|                                                 InverseReaction.mq5 |
//|Converted to MQL4 by Mikhail <Sepulca> Kozhemyako, ua3xcm@obninsk.ru |
//|                                           Copyright 2013, Erdem Sen |
//|                            http://login.mql5.com/en/users/erdogenes |
//+---------------------------------------------------------------------+
#property copyright "Copyright 2013, Erdem Sen"
#property link      "http://login.mql5.com/en/users/erdogenes"
//---
// This indicator is based on the idea of that an unusual impact in price changes will be
// adjusted by an inverse reaction. It consists of two main buffers: One shows gap-free
// price changes and the other(s) shows the possible volatility limits.
// The signal comes out when the price change buffer exceeds the possible volatility limits.
// Then you can expect an inverse reaction.
//--- Dynamic Confidence Levels (DCL)--------------------------------------------------------------------------------
      //
      // To determine DCLs, first, moving standard deviation (MStD) must be calculated. With the assumption of 
      // "PERFECT NORMALITY CONDITIONS" in price changes, and using absolute values with "HALF NORMAL" 
      // distribution method, MStD can be calculated by MA:
      // Ex:---------------------------------------------------| 
      // |    MStD = Sqrt[Pi]/Sqrt[2] * MA[Abs[Price Changes]] |
      // |    GoldenRatio ~= z[%80] * Sqrt[Pi]/Sqrt[2]         |
      // |    DCL[%80]~= GoldenRatio * MA[Abs[Price Changes]]  |
      // |-----------------------------------------------------|
      // With large numbers of MaPeriod, DCL aproximates to static ConfidenceLevel for normal distribution, 
      // However the system is dynamic and memory is very short for such economic behavours, 
      // so it set with a small number: 3 as default. (!!! plus, considering a possible HEAVY-TAIL problem, 
      // small values of MaPeriod will relatively response better.) 
      // ---------------------------------------------------------------------------------------------------------- 

//--- Indicator
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  BlueViolet
#property indicator_color2  Red
#property indicator_color3  Green
extern int      MaPeriod    = 3;     // Moving average period
extern double   Coefficient = 1.618; // Confidence coefficient
double   PriceChangesBuffer[];
double   u_CLevelBuffer[];
double   l_CLevelBuffer[];
int init()
  {
   SetIndexBuffer(0,PriceChangesBuffer);
   SetIndexBuffer(1,u_CLevelBuffer);
   SetIndexBuffer(2,l_CLevelBuffer);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   string name=  "InverseReaction("+MaPeriod+" , "+DoubleToStr(Coefficient,3)+")"; 
   IndicatorShortName(name);
   IndicatorDigits(Digits);
   return(0);
  }  
int start(){
   if(Bars<MaPeriod) 
     {   Print("Sorry!!, there is not enough bars. Download more historical data and retry");
         return(0);
     }
   int ExtCountedBars=IndicatorCounted();
   if (ExtCountedBars<0) return(-1);
   for(int i=Bars-ExtCountedBars-1;i>=0;i--)
     {   PriceChangesBuffer[i]=(Close[i]-Open[i]);
         if(i>Bars-MaPeriod)continue;
         u_CLevelBuffer[i]=sma(i);
         l_CLevelBuffer[i]=-1*u_CLevelBuffer[i];
     } 
   return(0);
  }
double sma(int j)
  {
   double sum=0;
   for(int i=j;i<MaPeriod+j;i++) sum+=MathAbs(PriceChangesBuffer[i]);
   sum=Coefficient*sum/MaPeriod;
   return(sum);
  }

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---