Navigation:Home > Content >

Ozy_lite_histo_1.mq4

Time: 2016-03-06 | Download file:Ozy_lite_histo_1.mq4

//+------------------------------------------------------------------+
//|                                             Ozy_lite_histo_1.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
//+ Взято у "ExcStrategy" "http://www.ExcStrategy.ru"
//+ Переделано под гистограмму. Не рисует) 
//+------------------------------------------------------------------+

#property strict
//----
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1

#property indicator_buffers 3
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Tomato
#property indicator_width1  2
#property indicator_width2  2

//----
extern int Period_1 = 2;
extern int Period_2 = 2;
//----
bool nexttrend;
double minh, maxl, up[], down[], trend[];
//----
int init () 
{
    SetIndexBuffer (0, up);
    SetIndexStyle (0, DRAW_HISTOGRAM);
    SetIndexBuffer (1, down);
    SetIndexStyle (1, DRAW_HISTOGRAM);

    SetIndexBuffer (2, trend);
    SetIndexStyle (2, DRAW_NONE);
    //----
    IndicatorShortName("Ozy_lite_histo_1");
    SetIndexLabel(0, "Down");
    SetIndexLabel(1, "Up");
    //----
    nexttrend = 0;
    minh = High[Bars - 1];
    maxl = Low[Bars - 1];
    //----
    return (0);
}
//----
int start ()
{
    double atr, ll, hh, lma, hma;
    int workbar = 1;
    int c = IndicatorCounted ();
    //----
    if(c < 0) 
    {
        return (- 1);
    }
    //----
    for (int i = Bars - 1 - c; i >= workbar; i --) 
    {
        if(Bars - i > 5 + MathMax(Period_1, Period_2))
        {
            //--------------------------------------------------------------------------------------------
            // Алгоритм расчёта взят с сайта http://tradelikeapro.ru/indikator-ozymandias/
            //--------------------------------------------------------------------------------------------
            ll = iLow(Symbol (), Period (), iLowest (Symbol (), Period (), MODE_LOW, Period_1, i));
            hh = iHigh(Symbol (), Period (), iHighest (Symbol (), Period (), MODE_HIGH, Period_1, i));
            lma = iMA(NULL, 0, Period_2, 0, MODE_SMA, PRICE_LOW, i);
            hma = iMA(NULL, 0, Period_2, 0, MODE_SMA, PRICE_HIGH, i);
            trend[i] = trend[i + 1];
            atr = iATR(Symbol (), 0, 100, i) / 2;
            //----
            if(nexttrend == 1) 
            {
                maxl = MathMax (ll, maxl);
                if(hma < maxl && Close[i] < Low[i + 1]) 
                {
                    trend[i] = 1;
                    nexttrend = 0;
                    minh = hh;
                }
            }
            //----
            if(nexttrend == 0)
            {
                minh = MathMin (hh, minh);
                if(lma > minh && Close[i] > High[i + 1]) 
                {
                    trend[i] = 0;
                    nexttrend = 1;
                    maxl = ll;
                }
            }

            
            if(trend[i] == 0 && trend[i+1] == 0)
            {
               up[i] = 1;
               down[i] = EMPTY_VALUE;
            }
            if(trend[i] == 1 && trend[i+1] == 1)
            {
               up[i] = EMPTY_VALUE;
               down[i] = 1;
            }
            if(trend[i] == 0 && trend[i+1] == 1)
            {
               up[i] = 1;
               down[i] = EMPTY_VALUE;
            }
            if(trend[i] == 1 && trend[i+1] == 0)
            {
               up[i] = EMPTY_VALUE;
               down[i] = 1;
            }           
            //----
            up[0] = EMPTY_VALUE;
            down[0] = EMPTY_VALUE;
        }
    }
    return (0);
}

Recommend