MaChannel_v1

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

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red


extern int ma = 12;
extern int shift  = 600;
extern int maType = 0;
extern bool oneWay = true; 


double lineGreen[];
double lineRed[];

double up[];
double down[];
double trand[];


//#include <constants.mqh>
//#include <switch.mqh>
//#include <indicators\indiUtils.mqh>
//#include <indicators\objects.mqh>

int init() {
   IndicatorBuffers(5);
   
   SetIndexBuffer(0, lineGreen);
   SetIndexBuffer(1, lineRed);
   SetIndexBuffer(2, up);
   SetIndexBuffer(3, down);
   SetIndexBuffer(4, trand);
   
   SetIndexStyle(0, DRAW_LINE, EMPTY, 1);
   SetIndexStyle(1, DRAW_LINE, EMPTY, 1);
   
   //objects.initArrawObjects();
   if(Digits == 4) {
      shift = shift / 10;
   }
}

int deinit() {
   //objects.deinitArrawObjects();
}

int start() {
    int indicatorCounted = IndicatorCounted();
    if (indicatorCounted < 0) {
         return (-1);
    }
    if (indicatorCounted > 0) {
         indicatorCounted--;
    }
    int limit = Bars - indicatorCounted -1;
    for (int i = limit - 1; i >= 0; i--) {
        trand[i] = trand[i + 1];
        up[i]   = iMA(NULL, 0, ma, 0, maType, PRICE_HIGH, i + 1) + shift * Point;
        down[i] = iMA(NULL, 0, ma, 0, maType, PRICE_LOW,  i + 1) - shift * Point;
        
        if(oneWay) {
            if(trand[i+1] == 1) {
                if(down[i] < down[i+1] && down[i+1] != EMPTY_VALUE) {
                   down[i] = down[i+1];
                }
            } else if(trand[i+1] == -1){
                if(up[i] > up[i+1] && up[i+1] != EMPTY_VALUE) {
                   up[i] = up[i+1];
                }
            }
        }
        
        if (High[i] > up[i]) {
            trand[i] = 1;
        } else if (Low[i] < down[i]) {
            trand[i] = -1;
        }
        
        if (trand[i] == -1.0) {
            lineRed[i] = up[i];
            lineGreen[i] = EMPTY_VALUE;
        } else if(trand[i] == 1.0) {
            lineGreen[i] = down[i];
            lineRed[i] = EMPTY_VALUE;
        }
    }
}


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