Author: Copyright � 2009-2012, Ivan Kornilov. All rights reserved.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MBMCD
//+------------------------------------------------------------------+
//|                              Copyright © 2009-2012, Ivan Kornilov|
//|                                                         MBMCD.mq4|
//|                                   excelf@gmail.com, skype: excelf|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009-2012, Ivan Kornilov. All rights reserved."
#property link "excelf@gmail.com"

#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1 LawnGreen
//#property  indicator_color1 Green
#property  indicator_color2 DarkViolet
#property  indicator_level1 0

extern int ma        = 1;
extern int mbm      = 13;
extern int filter    = 0;
extern int lineCount = 1;//<=5
extern int maType    = 0;
extern int maPrice   = 0;

double HistogramRed[];
double HistogramGreen[];
double MaBuffer[];
double MacdBuffer1[];
double MacdBuffer2[];
double MacdBuffer3[];
double MacdBuffer4[];
double MacdBuffer5[];


/*
#include <constants.mqh>
#include <switch.mqh>
#include <logger.mqh>
#include <indicators\objects.mqh>
#include <indicators\indiUtils.mqh>
#include <indicators\MA.mqh>
#include <indicators\Regression.mqh>
#include <JJMASeries.mqh> 
*/


int init(){
   IndicatorBuffers(8);
   SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, 2);
   SetIndexStyle(1, DRAW_HISTOGRAM, EMPTY, 2);
   SetIndexDrawBegin(0, mbm);
   SetIndexDrawBegin(1, mbm);
   IndicatorDigits(Digits + 1);

   SetIndexBuffer(0, HistogramRed);
   SetIndexBuffer(1, HistogramGreen);
   SetIndexBuffer(2, MacdBuffer1);
   SetIndexBuffer(3, MacdBuffer2);
   SetIndexBuffer(4, MacdBuffer3);
   SetIndexBuffer(5, MacdBuffer4);
   SetIndexBuffer(6, MacdBuffer5);
   SetIndexBuffer(7, MaBuffer);
   
  
   IndicatorShortName("MBMCD(" + ma + "," + mbm + ", line: " + lineCount + ")" );
   //IndicatorShortName("MBMCD(" + ma + "," + macd + ", line: " + lineCount + ")" + " maType: " + ma.getMaName(maType));
   SetIndexLabel(0, "HistogramRed");
   SetIndexLabel(1, "HistogramGreen");
   //ma.init(maType);
}

int start(){
   int countedBars = IndicatorCounted();
   if (countedBars<0) { 
      return(-1);
   }
   if(countedBars > 0) {
       countedBars--;
   }
   int limit = Bars - countedBars - 1;
   
   for(int shift = limit; shift >= 0; shift--) {
      /*
      if(maType == 9 || maType == 10 || maType == 11 || maType == 12) {
         ma.MaxBar = Bars - 1;
         ma.limit  = limit;
      }
      */
      //MaBuffer[shift] = ma.ma(ma, maType, 0, shift);
      MaBuffer[shift] = iMA(NULL, 0, ma, 0, maType, maPrice, shift);
   }
   
   for(int i = limit; i >= 0; i--) {
       MacdBuffer1[i] = MaBuffer[i] - iMAOnArray(MaBuffer, 0, mbm, 0, 0, i);
   }
   
   if(lineCount >= 2)
      for(i = limit; i >= 0; i--) {
          MacdBuffer2[i] = MacdBuffer1[i] - iMAOnArray(MacdBuffer1, 0, mbm, 0, 0, i);
      }
   
   if(lineCount >= 3)
      for(i = limit; i >= 0; i--) {
          MacdBuffer3[i] = MacdBuffer2[i] - iMAOnArray(MacdBuffer2, 0, mbm, 0, 0, i);
      }
   
   if(lineCount >= 4)
      for(i = limit; i >= 0; i--) {
          MacdBuffer4[i] = MacdBuffer3[i] - iMAOnArray(MacdBuffer3, 0, mbm, 0, 0, i);
      }
   if(lineCount >= 5)
      for(i = limit; i >= 0; i--) {
          MacdBuffer5[i] = MacdBuffer4[i] - iMAOnArray(MacdBuffer4, 0, mbm, 0, 0, i);
      }
   
   
   double valueMa, macd;
   for(i = limit; i >= 0; i--) {
      switch(lineCount) {
         case 1: 
            macd = MacdBuffer1[i];
            valueMa = iMAOnArray(MacdBuffer1, 0, filter, 0, maType, i);
            break;
         case 2:             
            macd = MacdBuffer2[i];
            valueMa = iMAOnArray(MacdBuffer2, 0, filter, 0, maType, i);
            break;
         case 3:             
            macd = MacdBuffer3[i];
            valueMa = iMAOnArray(MacdBuffer3, 0, filter, 0, maType, i);
            break;
         case 4:             
            macd = MacdBuffer4[i];
            valueMa = iMAOnArray(MacdBuffer4, 0, filter, 0, maType, i);
            break;
         case 5:             
            macd = MacdBuffer5[i];
            valueMa = iMAOnArray(MacdBuffer5, 0, filter, 0, maType, i);
            break;   
         case 0: 
            macd = MacdBuffer1[i];
            valueMa = iMAOnArray(MacdBuffer1, 0, filter, 0, maType, i);
            break;
      }
      
      if(valueMa < macd) {
         HistogramRed[i] = macd;
         HistogramGreen[i] = EMPTY_VALUE;
      } else {
         HistogramRed[i] = EMPTY_VALUE;
         HistogramGreen[i] = macd;
      }
   }
}

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