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

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
extern int period = 21;
extern int shift = 5;
extern int ma = 10;

double XBuffer[];
double MABuffer[];


double minVolume; 
int init() {
    SetIndexStyle(0,DRAW_LINE);
    SetIndexBuffer(0, XBuffer);
    
    SetIndexStyle(1,DRAW_LINE);
    SetIndexBuffer(1, MABuffer);
    
    SetIndexDrawBegin(0, (period+ma));
    SetIndexDrawBegin(1, (period+ma));
    
    IndicatorShortName("XSUM(" + period + "," + ma + ")");
}

int start() {
    int i;
    int j;
    int counted_bars=IndicatorCounted();
     if(counted_bars > 0) {
        counted_bars--;
    }
    int limit = Bars - counted_bars;

    for(i = limit - 1 ; i >= 0; i--) {
        double sum = 0;
        for(j=i;j<i+period;j++) {
          if(Close[j+shift] != 0) {
            if(MABuffer[i+1] < XBuffer[i+1]) {
                sum+= Close[j] / Close[j+shift];
             } else {
                 sum+= Close[j] / Close[j+shift];
             }
            
          }
        }
        XBuffer[i] = sum;
    }
    
     for(i = 0; i < limit; i++) {
        MABuffer[i] = iMAOnArray(XBuffer, Bars, ma, 0, 2, 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 ---