Navigation:Home > Content >

GannLevels_(1).mq4

Time: 2011-11-17 | Download file:GannLevels_(1).mq4

//+------------------------------------------------------------------+
//|                                   Copyright © 2010, Ivan Kornilov|
//|                                                    GannLevels.mq4|
//+------------------------------------------------------------------+

#property copyright "Copyright © 2010, Ivan Kornilov. All rights reserved."
#property link "[email protected]"
#property indicator_buffers 0
#property indicator_chart_window

extern int drowDays = 100;
extern bool showText = false;
extern double order = 0.0001;

double level1 = 1.25;
double level2 = 2.50;
double level3 = 3.33;
double level4 = 5;
double level5 = 6.66;
double level6 = 7.5;
double level7 = 22;

int init() {
    level1 = level1 * order;
    level2 = level2 * order;
    level3 = level3 * order;
    level4 = level4 * order;
    level5 = level5 * order;
    level6 = level6 * order;
    level7 = level7 * order;
}

int deinit() {
    ObjectsDeleteAll(0,OBJ_TREND);
    ObjectsDeleteAll(0,OBJ_TEXT);
}

int start() {
    int indicatorCounted = IndicatorCounted();
    if (indicatorCounted < 0) { 
        return (-1);
    }
    if(indicatorCounted > 0) {
       indicatorCounted--;
    }
   
    int limit = Bars - indicatorCounted;
    int days = 0;
    for(int i = 0; i < limit; i++) {   
        if(TimeDay(Time[i]) != TimeDay(Time[i+1])) {
     //if(TimeDayOfWeek(Time[i])  ==  1 && TimeDayOfWeek(Time[i+1]) != 1){
            double openDay = Open[i];
            datetime openTime = Time[i];
            datetime closeTime = Time[i] + 60 * 60 * 24;
            
            
            double level = openDay;
            string levelName = "level0" + TimeDay(Time[i]);
            ObjectCreate(levelName, OBJ_TREND, 0, openTime, level, closeTime, level);
            ObjectSet(levelName, OBJPROP_COLOR, BlueViolet);
            ObjectSet(levelName, OBJPROP_WIDTH, 0);
            ObjectSet(levelName, OBJPROP_BACK, true);
            ObjectSet(levelName, OBJPROP_RAY, false);
            ObjectSet(levelName, OBJPROP_STYLE, STYLE_DASH);
            

            /*
            
            //1й уровень - (корень от открытия дня + 0.125)в квадрате зеленый цвет полужирный уровень аналогично и с поддержкой только отнять 0.125
            double level1Up = MathPow((MathSqrt(openDay) + level1), 2);
            string level1UpName = "level1Up" + TimeDay(Time[i]);
            ObjectCreate(level1UpName, OBJ_TREND, 0, openTime, level1Up, closeTime, level1Up);
            ObjectSet(level1UpName, OBJPROP_COLOR, Green);
            ObjectSet(level1UpName, OBJPROP_WIDTH, 2);
            ObjectSet(level1UpName, OBJPROP_BACK, true);
            ObjectSet(level1UpName, OBJPROP_RAY, false);
            
                        
       
            
            double level1Down = MathPow((MathSqrt(openDay) - level1), 2);
            string level1DownName = "level1Down" + TimeDay(Time[i]);
            ObjectCreate(level1DownName, OBJ_TREND, 0, openTime, level1Down, closeTime, level1Down);
            ObjectSet(level1DownName, OBJPROP_COLOR, Green);
            ObjectSet(level1DownName, OBJPROP_WIDTH, 2);
            ObjectSet(level1DownName, OBJPROP_BACK, true);
            ObjectSet(level1DownName, OBJPROP_RAY, false);
            
     
            
            //2й) корень от открытия дня + 0.25)в квадрате синий полужирный и аналогично для поддержки только минус 0.25
            double level2Up = MathPow((MathSqrt(openDay) + level2), 2);
            string level2UpName = "level2Up" + TimeDay(Time[i]);
            ObjectCreate(level2UpName, OBJ_TREND, 0, openTime, level2Up, closeTime, level2Up);
            ObjectSet(level2UpName, OBJPROP_COLOR, SkyBlue);
            ObjectSet(level2UpName, OBJPROP_WIDTH, 0);
            ObjectSet(level2UpName, OBJPROP_BACK, true);
            ObjectSet(level2UpName, OBJPROP_RAY, false);

            
            double level2Down = MathPow((MathSqrt(openDay) - level2), 2);
            string level2DownName = "level2Down" + TimeDay(Time[i]);
            ObjectCreate(level2DownName, OBJ_TREND, 0, openTime, level2Down, closeTime, level2Down);
            ObjectSet(level2DownName, OBJPROP_COLOR, Orange);
            ObjectSet(level2DownName, OBJPROP_WIDTH, 0);
            ObjectSet(level2DownName, OBJPROP_BACK, true);
            ObjectSet(level2DownName, OBJPROP_RAY, false);
                        

            
            //3йкорень от открытия дня + 0.333)в квадрате тонкий синий аналогично для поддержки только -0.333
            double level3Up = MathPow((MathSqrt(openDay) + level3), 2);
            string level3UpName = "level3Up" + TimeDay(Time[i]);
            ObjectCreate(level3UpName, OBJ_TREND, 0, openTime, level3Up, closeTime, level3Up);
            ObjectSet(level3UpName, OBJPROP_COLOR, SkyBlue);
            ObjectSet(level3UpName, OBJPROP_WIDTH, 0);
            ObjectSet(level3UpName, OBJPROP_BACK, true);
            ObjectSet(level3UpName, OBJPROP_RAY, false);
            

            
            double level3Down = MathPow((MathSqrt(openDay) - level3), 2);
            string level3DownName = "level3Down" + TimeDay(Time[i]);
            ObjectCreate(level3DownName, OBJ_TREND, 0, openTime, level3Down, closeTime, level3Down);
            ObjectSet(level3DownName, OBJPROP_COLOR, Orange);
            ObjectSet(level3DownName, OBJPROP_WIDTH, 0);
            ObjectSet(level3DownName, OBJPROP_BACK, true);
            ObjectSet(level3DownName, OBJPROP_RAY, false);
            
            
  
            
            //4й уровень корень от открытия дня + 0.5)в квадрате полужирный синий цвет.... аналогично для поддержки только минус 0.5
            double level4Up = MathPow((MathSqrt(openDay) + level4), 2);
            string level4UpName = "level4Up" + TimeDay(Time[i]);
            ObjectCreate(level4UpName, OBJ_TREND, 0, openTime, level4Up, closeTime, level4Up);
            ObjectSet(level4UpName, OBJPROP_COLOR, GreenYellow);
            ObjectSet(level4UpName, OBJPROP_WIDTH, 2);
            ObjectSet(level4UpName, OBJPROP_BACK, true);
            ObjectSet(level4UpName, OBJPROP_RAY, false);

            
            double level4Down = MathPow((MathSqrt(openDay) - level4), 2);
            string level4DownName = "level4Down" + TimeDay(Time[i]);
            ObjectCreate(level4DownName, OBJ_TREND, 0, openTime, level4Down, closeTime, level4Down);
            ObjectSet(level4DownName, OBJPROP_COLOR, Red);
            ObjectSet(level4DownName, OBJPROP_WIDTH, 2);
            ObjectSet(level4DownName, OBJPROP_BACK, true);
            ObjectSet(level4DownName, OBJPROP_RAY, false);
   *//*
            //5й уровень корень от открытия дня + 0.0.666)в квадрате тонкий 
            double level5Up = MathPow((MathSqrt(openDay) + level5), 2);
            string level5UpName = "level5Up" + TimeDay(Time[i]);
            ObjectCreate(level5UpName, OBJ_TREND, 0, openTime, level5Up, closeTime, level5Up);
            ObjectSet(level5UpName, OBJPROP_COLOR, SkyBlue);
            ObjectSet(level5UpName, OBJPROP_WIDTH, 0);
            ObjectSet(level5UpName, OBJPROP_BACK, true);
            ObjectSet(level5UpName, OBJPROP_RAY, false);
            
            double level5Down = MathPow((MathSqrt(openDay) - level5), 2);
            string level5DownName = "level5Down" + TimeDay(Time[i]);
            ObjectCreate(level5DownName, OBJ_TREND, 0, openTime, level5Down, closeTime, level5Down);
            ObjectSet(level5DownName, OBJPROP_COLOR, Orange);
            ObjectSet(level5DownName, OBJPROP_WIDTH, 0);
            ObjectSet(level5DownName, OBJPROP_BACK, true);
            ObjectSet(level5DownName, OBJPROP_RAY, false);
            */
            //6й корень от открытия дня + 0.75)в квадрате тонкий все аналогично и для поддержки
            double level6Up = MathPow((MathSqrt(openDay) + level6), 2);
            string level6UpName = "level6Up" + TimeDay(Time[i]);
            ObjectCreate(level6UpName, OBJ_TREND, 0, openTime, level6Up, closeTime, level6Up);
            ObjectSet(level6UpName, OBJPROP_COLOR, GreenYellow);
            ObjectSet(level6UpName, OBJPROP_WIDTH, 3);
            ObjectSet(level6UpName, OBJPROP_BACK, true);
            ObjectSet(level6UpName, OBJPROP_RAY, false);
                  
            double level6Down = MathPow((MathSqrt(openDay) - level6), 2);
            string level6DownName = "level6Down" + TimeDay(Time[i]);
            ObjectCreate(level6DownName, OBJ_TREND, 0, openTime, level6Down, closeTime, level6Down);
            ObjectSet(level6DownName, OBJPROP_COLOR, Red);
            ObjectSet(level6DownName, OBJPROP_WIDTH, 3);
            ObjectSet(level6DownName, OBJPROP_BACK, true);
            ObjectSet(level6DownName, OBJPROP_RAY, false);
            
            //7й корень от открытия дня + 1)в квадрате полужирный
            double level7Up = MathPow((MathSqrt(openDay) + level7), 2);
            string level7UpName = "level7Up" + TimeDay(Time[i]);
            ObjectCreate(level7UpName, OBJ_TREND, 0, openTime, level7Up, closeTime, level7Up);
            ObjectSet(level7UpName, OBJPROP_COLOR, GreenYellow);
            ObjectSet(level7UpName, OBJPROP_WIDTH, 3);
            ObjectSet(level7UpName, OBJPROP_BACK, true);
            ObjectSet(level7UpName, OBJPROP_RAY, false);
            
            double level7Down = MathPow((MathSqrt(openDay) - level7), 2);
            string level7DownName = "level7Down" + TimeDay(Time[i]);
            ObjectCreate(level7DownName, OBJ_TREND, 0, openTime, level7Down, closeTime, level7Down);
            ObjectSet(level7DownName, OBJPROP_COLOR, Red);
            ObjectSet(level7DownName, OBJPROP_WIDTH, 3);
            ObjectSet(level7DownName, OBJPROP_BACK, true);
            ObjectSet(level7DownName, OBJPROP_RAY, false);
            
            
            if(showText) {
                string label = "level0label" + TimeDay(Time[i]);
                string text = "Открытие дня";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level1UpLabel" + TimeDay(Time[i]);
                text = "Уровень 1";
                /*
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level1Up);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level1DownLabel" + TimeDay(Time[i]);
                text = "Уровень -1";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level1Down);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level2UpLabel" + TimeDay(Time[i]);
                text = "Уровень 2";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level2Up);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level2DownLabel" + TimeDay(Time[i]);
                text = "Уровень -2";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level2Down);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level3UpLabel" + TimeDay(Time[i]);
                text = "Уровень 3";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level3Up);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level3DownLabel" + TimeDay(Time[i]);
                text = "Уровень -3";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level3Down);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                
               
                label = "level4UpLabel" + TimeDay(Time[i]);
                text = "Уровень 4";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level4Up);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level4DownLabel" + TimeDay(Time[i]);
                text = "Уровень -4";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level4Down);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level5UpLabel" + TimeDay(Time[i]);
                text = "Уровень 5";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level5Up);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level5DownLabel" + TimeDay(Time[i]);
                text = "Уровень -5";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level5Down);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level6UpLabel" + TimeDay(Time[i]);
                text = "Уровень 6";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level6Up);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level6DownLabel" + TimeDay(Time[i]);
                text = "Уровень -6";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level6Down);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                 */
                
                label = "level7UpLabel" + TimeDay(Time[i]);
                text = "Уровень 7";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level7Up);
                ObjectSetText(label, text, 8, "Tahoma", Black);
                label = "level7DownLabel" + TimeDay(Time[i]);
                text = "Уровень -7";
                ObjectCreate(label, OBJ_TEXT, 0, openTime + StringLen(text), level7Down);
                ObjectSetText(label, text, 8, "Tahoma", Black);
            }
            days++;
        } 
        if(days >= drowDays) {
            break;
        }
    }
    return(0);
}

Recommend