Navigation:Home > Content >

FiboBars.mq4

Time: 2018-06-11 | Download file:FiboBars.mq4

//+------------------------------------------------------------------+
//|                                   Copyright © 2010, Ivan Kornilov|
//|                                                      FiboBars.mq4|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Ivan Kornilov. All rights reserved."
#property link "excelf@gmail.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Green

//extern int period = 4;//1H
extern int period = 10;//5Min
extern int fiboLevel = 1;
extern bool showAlert = false;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

bool isTrandDown;
bool oldIsTrandDown ;
double level;
#define level1 0.236
#define level2 0.382
#define level3 0.5
#define level4 0.618
#define level5 0.762
int init() {
    SetIndexStyle(0, DRAW_HISTOGRAM, 0, 1);
    SetIndexBuffer(0, ExtMapBuffer1);
    SetIndexStyle(1, DRAW_HISTOGRAM, 0, 1);
    SetIndexBuffer(1, ExtMapBuffer2);
    SetIndexStyle(2, DRAW_HISTOGRAM, 0, 3);
    SetIndexBuffer(2, ExtMapBuffer3);
    SetIndexStyle(3, DRAW_HISTOGRAM, 0, 3);
    SetIndexBuffer(3, ExtMapBuffer4);

    SetIndexDrawBegin(0, 10);
    SetIndexDrawBegin(1, 10);
    SetIndexDrawBegin(2, 10);
    SetIndexDrawBegin(3, 10);
    SetIndexBuffer(0, ExtMapBuffer1);
    SetIndexBuffer(1, ExtMapBuffer2);
    SetIndexBuffer(2, ExtMapBuffer3);
    SetIndexBuffer(3, ExtMapBuffer4);
    
    isTrandDown  = Close[0] > Close[1];
    oldIsTrandDown  = isTrandDown ;
    switch(fiboLevel){
    case 1:
        level = level1;
        break;
    case 2:
        level = level2;   
        break;
    case 3:
        level = level3;
        break;
    case 4:
        level = level4;
        break;
    case 5:
        level = level5;
        break;
    default: 
        level = level1;
        break;
    }
    return(0);
}

int deinit(){
    return(0);
}

int start() {
    int indicatorCounted = IndicatorCounted();
    if (indicatorCounted < 0) { 
        return (-1);
    }
    if(indicatorCounted > 0) {
       indicatorCounted--;
    }
   
    int limit = Bars - indicatorCounted;
    for(int i = limit; i >= 0; i--) {
        double maxHigh = High[iHighest(NULL,0,MODE_HIGH, period, i)];
        double minLow = Low[iLowest(NULL,0,MODE_LOW, period, i)]; 
        if(Open[i] > Close[i]) {
           if(!(!isTrandDown  && (maxHigh - minLow) * level < (Close[i] - minLow))) {
                isTrandDown = true;
           }
        } else {
            if(!(isTrandDown  && (maxHigh - minLow) * level < (maxHigh - Close[i]))) {
                isTrandDown  = false;
            }
        }
        
        if(isTrandDown  != oldIsTrandDown && showAlert && i == 0) {
            if(isTrandDown) {
                Alert("Fibo Bars: Sell " + Symbol() + " M" + Period());
            } else {
                Alert("Fibo Bars: Buy " + Symbol() + " M" + Period());
            }
        }
        oldIsTrandDown  = isTrandDown ;
        if(isTrandDown) {//RED BAR 
            ExtMapBuffer1[i] = High[i];
            ExtMapBuffer2[i] = Low[i]; 
            ExtMapBuffer3[i] = MathMax(Open[i], Close[i]); 
            ExtMapBuffer4[i] = MathMin(Open[i], Close[i]);   
        } else {//GREEN BAR
            ExtMapBuffer1[i] = Low[i];
            ExtMapBuffer2[i] = High[i]; 
            ExtMapBuffer3[i] = MathMin(Open[i], Close[i]);  
            ExtMapBuffer4[i] = MathMax(Open[i], Close[i]);    
        } 
        
       
    }
    return(0);
}

Recommend