MACD_Signal

Author: Copyright © 2022, cmillion@narod.ru
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MACD_Signal
ÿþ//+------------------------------------------------------------------+

//|                                                  MACD Signal.mq4 |

//|                              Copyright © 2011, Khlystov Vladimir |

//|                                         http://cmillion.narod.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2022, cmillion@narod.ru"

#property link      "http://cmillion.ru"

#property strict

#property  indicator_separate_window

#property  indicator_buffers 7

#property  indicator_color1  Black

#property  indicator_color2  Gray

#property  indicator_color3  Green

#property  indicator_color4  Red

#property  indicator_color5  Blue

#property  indicator_color6  Red

#property  indicator_width7  2



extern int FastEMA   = 12;

extern int SlowEMA   = 26;

extern int SignalSMA = 9;



double     MacdBuffer[];

double     MacdBufferRed[];

double     MacdBufferBlue[];

double     SignalBuffer[];

double     SignalBufferRed[];

double     SignalBufferBlue[];

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int OnInit()

  {

   IndicatorBuffers(6); 

   SetIndexStyle(0,DRAW_HISTOGRAM);

   SetIndexStyle(1,DRAW_LINE);

   SetIndexDrawBegin(1,SignalSMA);

   IndicatorDigits(Digits+1);

   SetIndexStyle(2,DRAW_HISTOGRAM);

   SetIndexStyle(3,DRAW_HISTOGRAM);

   SetIndexStyle(4,DRAW_ARROW,0,2);

   SetIndexArrow(4,233);

   SetIndexStyle(5,DRAW_ARROW,0,2);

   SetIndexArrow(5,234);



   SetIndexBuffer(0,MacdBuffer);

   SetIndexBuffer(1,SignalBuffer);

   SetIndexBuffer(2,MacdBufferRed);

   SetIndexBuffer(3,MacdBufferBlue);

   SetIndexBuffer(4,SignalBufferRed);

   SetIndexBuffer(5,SignalBufferBlue);



   IndicatorShortName("MACD("+IntegerToString(FastEMA)+","+IntegerToString(SlowEMA)+","+IntegerToString(SignalSMA)+")");

   SetIndexLabel(0,"MACD");

   SetIndexLabel(1,"Signal");



   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

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[])

  {

   int counted_bars = IndicatorCounted();

   if(counted_bars < 0)  return(-1);

   if(counted_bars > 0)   counted_bars--;

   int limit = Bars - counted_bars;

   if(counted_bars==0) limit-=1+1;

   int i;

   for(i=0; i<limit; i++)

      MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);



   for(i=0; i<limit; i++)

      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);



   for(i=0; i<limit; i++)

      if(MacdBuffer[i+1]<MacdBuffer[i]) MacdBufferRed[i]=MacdBuffer[i];

   else MacdBufferBlue[i]=MacdBuffer[i];



   for(i=0; i<limit; i++)

     {

      if(SignalBuffer[i+1]<MacdBuffer[i+1]&& SignalBuffer[i]>MacdBuffer[i]) SignalBufferBlue[i]=SignalBuffer[i];

      if(SignalBuffer[i+1]>MacdBuffer[i+1] && SignalBuffer[i]<MacdBuffer[i]) SignalBufferRed[i]=SignalBuffer[i];

     }



   return(rates_total);

  }

//+------------------------------------------------------------------+

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