Author: Copyright � 2009, LeMan
BinaryWave

This code snippet defines a custom indicator in MQL4. Let's break down what it does and how it's structured.

Overall Purpose:

The indicator appears to be designed to combine several technical analysis indicators (Moving Average, MACD, Oscillator, CCI, Momentum, RSI, ADX) into a single "Wave" indicator. It calculates a combined value for each bar and then smooths this combined value using a moving average to create the final "Wave" signal.

Key Components and Explanation:

  1. #property indicator_separate_windows true: This line indicates that the indicator will be displayed in a separate window.

  2. #property indicator_buffers 2: This declares that the indicator will use two buffers: WaveBuffer and TempBuffer.

  3. #property indicator_plots 2: This declares that the indicator will have two plots.

  4. #property indicator_label1 "Wave": This sets the label for the first plot (WaveBuffer).

  5. #property indicator_color1 clrBlue: This sets the color of the first plot to blue.

  6. #property indicator_label2 "Combined Values": This sets the label for the second plot (TempBuffer).

  7. #property indicator_color2 clrRed: This sets the color of the second plot to red.

  8. #property indicator_buffers 2: Declares two buffers.

  9. #property indicator_plots 2: Declares two plots.

  10. #property indicator_label1 "Wave": Label for the WaveBuffer plot.

  11. #property indicator_color1 clrBlue: Color of the WaveBuffer plot.

  12. #property indicator_label2 "Combined Values": Label for the TempBuffer plot.

  13. #property indicator_color2 clrRed: Color of the TempBuffer plot.

  14. start() Function: This is the main function that calculates the indicator values.

  • IndicatorCounted() and Bars: These variables are used to determine the number of bars that have already been processed and the total number of bars in the chart.
  • limit = Bars - counted_bars;: Calculates the number of bars to process.
  • TempBuffer[i] = MAClose(i) + MACD(i) + OsMA(i) + CCI(i) + MOM(i) + RSI(i) + ADX(i);: This is the core calculation. It sums the results of seven different indicator functions for each bar. The MAClose, MACD, OsMA, CCI, MOM, RSI, and ADX functions are defined later in the code.
  • iMAOnArray(TempBuffer, 0, MovWavePer, 0, MovWaveType, i);: This applies a moving average to the TempBuffer values to smooth the combined indicator. MovWavePer is the period of the moving average, and MovWaveType specifies the type of moving average (e.g., Simple, Exponential, Smoothed).
  • WaveBuffer[i] = TempBuffer[i];: If MovWavePer is 1, the WaveBuffer is simply equal to the TempBuffer.
  1. Indicator Functions (MAClose, MACD, OsMA, CCI, MOM, RSI, ADX):
  • These functions calculate the values of the individual indicators. They are defined later in the code. Each function takes a bar index i as input and returns a value.
  • MAClose(i): Calculates a moving average of the closing prices.
  • MACD(i): Calculates the MACD (Moving Average Convergence Divergence).
  • OsMA(i): Calculates the Oscillator.
  • CCI(i): Calculates the Commodity Channel Index.
  • MOM(i): Calculates the Momentum.
  • RSI(i): Calculates the Relative Strength Index.
  • ADX(i): Calculates the Average Directional Index.

Key Observations and Potential Improvements:

  • Indicator Function Definitions: The code snippet only shows the start() function. The definitions of the individual indicator functions (MAClose, MACD, OsMA, CCI, MOM, RSI, ADX) are missing. These are crucial for the indicator to work correctly.
  • Parameterization: The indicator has several parameters (e.g., periods for moving averages, RSI, ADX). These parameters are likely defined as external input parameters, allowing the user to customize the indicator's behavior.
  • Weighting: The code simply sums the values of the individual indicators. It might be beneficial to assign different weights to each indicator based on their relative importance or expected contribution to the overall signal.
  • Normalization: The individual indicators might have different scales. Normalizing the values before summing them could improve the accuracy and stability of the combined indicator.
  • Error Handling: The code doesn't include any error handling. It's important to add checks to ensure that the input parameters are valid and that the indicator functions don't produce errors.

In summary, this code defines a custom indicator that combines several technical analysis indicators into a single "Wave" signal. The indicator calculates a combined value for each bar and then smooths this combined value using a moving average. The code is incomplete, as the definitions of the individual indicator functions are missing. However, the overall structure and logic of the indicator are clear.

Indicators Used
Moving average indicatorMACD HistogramMoving Average of OscillatorCommodity channel indexMomentum indicatorRelative strength indexMovement directional indexMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
BinaryWave
//+------------------------------------------------------------------+
//|                                                   BinaryWave.mq4 |
//|                                          Copyright © 2009, LeMan |
//|                                                 b-market@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, LeMan"
#property link      "b-market@mail.ru"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//--- Âåñ èíäèêàòîðîâ. Åñëè íîëü, èíäèêàòîð íå ó÷àñòâóåò â ðàñ÷åòå âîëíû
extern double WeightMA    = 1.0;
extern double WeightMACD  = 1.0;
extern double WeightOsMA  = 1.0;
extern double WeightCCI   = 1.0;
extern double WeightMOM   = 1.0;
extern double WeightRSI   = 1.0;
extern double WeightADX   = 1.0;
//---- Ïàðàìåòðû ñêîëüçÿùåãî ñðåäíåãî
extern int   MAPeriod     = 13;
extern int   MAType       = 1;
extern int   MAPrice      = 0;
//---- Ïàðàìåòðû OsMA
extern int   FastMACD     = 12;
extern int   SlowMACD     = 26;
extern int   SignalMACD   = 9;
extern int   PriceMACD    = 0;
//---- Ïàðàìåòðû OsMA
extern int   FastPeriod   = 12;
extern int   SlowPeriod   = 26;
extern int   SignalPeriod = 9;
extern int   OsMAPrice    = 0;
//---- Ïàðàìåòðû CCI
extern int   CCIPeriod    = 14;
extern int   CCIPrice     = 5;
//---- Ïàðàìåòðû Ìîìåíòà
extern int   MOMPeriod    = 14;
extern int   MOMPrice     = 0;
//---- Ïàðàìåòðû RSI
extern int   RSIPeriod    = 14;
extern int   RSIPrice     = 0;
//---- Ïàðàìåòðû ADX
extern int   ADXPeriod    = 14;
extern int   ADXPrice     = 0;
//---- Âêëþ÷åíèå ñãëàæèâàíèÿ âîëíû
extern int MovWavePer     = 1;
extern int MovWaveType    = 0;
//---- buffers
double WaveBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(Digits);
   IndicatorBuffers(2);  
   double ws = WeightMA+WeightMACD+WeightOsMA+WeightCCI+WeightMOM+WeightRSI+WeightADX;  
   string short_name = "Binary Wave ("+DoubleToStr(ws,Digits)+")";
//---- indicators
   IndicatorShortName(short_name);
   SetIndexBuffer(0,WaveBuffer);
   SetIndexBuffer(1,TempBuffer);
   SetIndexStyle(0,DRAW_LINE);
//----
   return(0);
  }
//---- Îïðåäåëÿåì ïîëîæåíèå öåíû çàêðûòèÿ îòíîñèòåëüíî ñêîëüçÿùåãî ñðåäíåãî
double MAClose(int i = 0) {
   if (WeightMA > 0) {
      if ((Close[i]-iMA(NULL,0,MAPeriod,0,MAType,MAPrice,i)) > 0)
         return(WeightMA);
      if ((Close[i]-iMA(NULL,0,MAPeriod,0,MAType,MAPrice,i)) < 0)
         return(-WeightMA);
      if ((Close[i]-iMA(NULL,0,MAPeriod,0,MAType,MAPrice,i)) == 0)
         return(0);         
   } else {
      return(0);
   }
}
//---- Îïðåäåëÿåì íàêëîí MACD
double MACD(int i = 0) {
   if (WeightMACD > 0) {
      if (iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i)-iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i+1) > 0)
         return(WeightMACD);
      if (iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i)-iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i+1) < 0)
         return(-WeightMACD);
      if (iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i)-iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD,MODE_MAIN,i+1) == 0)
         return(0);         
   } else {
      return(0);
   }
}
//---- Îïðåäåëÿåì ïîëîæåíèå OsMa îòíîñèòåëüíî íóëÿ
double OsMA(int i = 0) {
   if (WeightOsMA > 0) {
      if (iOsMA(NULL,0,FastPeriod,SlowPeriod,SignalPeriod,OsMAPrice,i) > 0)
         return(WeightOsMA);
      if (iOsMA(NULL,0,FastPeriod,SlowPeriod,SignalPeriod,OsMAPrice,i) < 0)
         return(-WeightOsMA);
      if (iOsMA(NULL,0,FastPeriod,SlowPeriod,SignalPeriod,OsMAPrice,i) == 0)
         return(0);         
   } else {
      return(0);
   }
}
//---- Îïðåäåëÿåì ïîëîæåíèå CCI îòíîñèòåëüíî íóëÿ
double CCI(int i = 0) {
   if (WeightCCI > 0) {
      if (iCCI(NULL,0,CCIPeriod,CCIPrice,i) > 0)
         return(WeightCCI);
      if (iCCI(NULL,0,CCIPeriod,CCIPrice,i) < 0)
         return(-WeightCCI);
      if (iCCI(NULL,0,CCIPeriod,CCIPrice,i) == 0)
         return(0);         
   } else {
      return(0);
   }
}
//---- Îïðåäåëÿåì ïîëîæåíèå Momentum îòíîñèòåëüíî 100
double MOM(int i = 0) {
   if (WeightMOM > 0) {
      if (iMomentum(NULL,0,MOMPeriod,MOMPrice,i) > 100)
         return(WeightMOM);
      if (iMomentum(NULL,0,MOMPeriod,MOMPrice,i) < 100)
         return(-WeightMOM);
      if (iMomentum(NULL,0,MOMPeriod,MOMPrice,i) == 100)
         return(0);         
   } else {
      return(0);
   }
}
//---- Îïðåäåëÿåì ïîëîæåíèå RSI îòíîñèòåëüíî 50
double RSI(int i = 0) {
   if (WeightRSI > 0) {
      if (iRSI(NULL,0,RSIPeriod,RSIPrice,i) > 50)
         return(WeightRSI);
      if (iRSI(NULL,0,RSIPeriod,RSIPrice,i) < 50)
         return(-WeightRSI);
      if (iRSI(NULL,0,RSIPeriod,RSIPrice,i) == 50)
         return(0);         
   } else {
      return(0);
   }
}
//---- Îïðåäåëÿåì ïîëîæåíèå DMI
double ADX(int i = 0) {
   if (WeightADX > 0) {
      if (iADX(NULL,0,ADXPeriod,ADXPrice,MODE_PLUSDI,i) > iADX(NULL,0,ADXPeriod,RSIPrice,MODE_MINUSDI,i))
         return(WeightADX);
      if (iADX(NULL,0,ADXPeriod,ADXPrice,MODE_PLUSDI,i) < iADX(NULL,0,ADXPeriod,RSIPrice,MODE_MINUSDI,i))
         return(-WeightADX);
      if (iADX(NULL,0,ADXPeriod,ADXPrice,MODE_PLUSDI,i) == iADX(NULL,0,ADXPeriod,RSIPrice,MODE_MINUSDI,i))
         return(0);         
   } else {
      return(0);
   }
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, limit, counted_bars=IndicatorCounted();
//----
   if (counted_bars > 0) counted_bars--;
   limit = Bars-counted_bars;
//---- macd
   for (i = 0; i < limit; i++)
      TempBuffer[i] = MAClose(i)+MACD(i)+OsMA(i)+CCI(i)+MOM(i)+RSI(i)+ADX(i);   
//----
   int max = MathMax(MAPeriod,MathMax(SlowPeriod,MathMax(CCIPeriod,MathMax(SlowMACD,MOMPeriod))));
//----
   if (Bars <= max) return(0);
//---- initial zero
   if (counted_bars < 1) 
      for (i = 1; i <= max; i++) WaveBuffer[Bars-i] = 0.0;
//----
   i = Bars-max-1;
   if (counted_bars >= max) i = Bars-counted_bars-1;
   while(i >= 0) {
      if (MovWavePer > 1) {
         WaveBuffer[i] = iMAOnArray(TempBuffer,0,MovWavePer,0,MovWaveType,i);
      } else {
         WaveBuffer[i] = TempBuffer[i];
      }
      i--;
   }

   return(0);
  }
//+------------------------------------------------------------------+

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 ---