Navigation:Home > Content >

StochasticStack.mq4

Time: 2017-11-04 | Download file:StochasticStack.mq4

//+------------------------------------------------------------------+
//|                                   Copyright ? 2019, Ivan Kornilov|
//|                                               StochasticStack.mq4|
//+------------------------------------------------------------------+
#property copyright "Copyright ? 2009, Ivan Kornilov. All rights reserved."
#property link "excelf@gmail.com"
 
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 8
#property indicator_level1 20
#property indicator_level2 80
#property indicator_levelcolor LightSlateGray
#property indicator_color8 Silver
#property indicator_color7 MediumPurple
#property indicator_color6 DodgerBlue
#property indicator_color5 Aqua
#property indicator_color4 Lime
#property indicator_color3 Gold
#property indicator_color2 Orange
#property indicator_color1 Red
 
extern double nextPriod = 1.3;
extern int kPeriod1 = 7;
int dPeriod1 = 0;
int slowing1 = 0;
 
extern int kPeriod2 = 21;
int dPeriod2 = 0;
int slowing2 = 0;
 
extern int kPeriod3 = 34;
int dPeriod3 = 0;
int slowing3 = 0;
 
extern int kPeriod4 = 55;
int dPeriod4 = 0;
int slowing4 = 0;
 
extern int kPeriod5 = 72;
int dPeriod5 = 0;
int slowing5 = 0;
 
extern int kPeriod6 = 89;
int dPeriod6 = 0;
int slowing6 = 0;
 
extern int kPeriod7 = 116;
int dPeriod7 = 0;
int slowing7 = 0;
 
extern int kPeriod8 = 144;
int dPeriod8 = 0;
int slowing8 = 0;
 
 
extern bool modeSignal = true;
 
extern int countLine = 8;
 
double lineBuffer0[];
double lineBuffer1[];
double lineBuffer2[];
double lineBuffer3[];
double lineBuffer4[];
double lineBuffer5[];
double lineBuffer6[];
double lineBuffer7[];
#define maxBuffer 8
int init() {
    if(countLine > maxBuffer) {
        countLine = maxBuffer;
    } else if(countLine < 1) {
        countLine = 1;
    }
    if(nextPriod != 0) {
        kPeriod2 = kPeriod1 * nextPriod;
        kPeriod3 = kPeriod2 * nextPriod;
        kPeriod4 = kPeriod3 * nextPriod;
        kPeriod5 = kPeriod4 * nextPriod;
        kPeriod6 = kPeriod5 * nextPriod;
        kPeriod7 = kPeriod6 * nextPriod;
        kPeriod8 = kPeriod7 * nextPriod;
    } 
    if(dPeriod1 == 0 && slowing1 == 0) {
        dPeriod1 = kPeriod1 / 2;
        slowing1 = dPeriod1 / 2;
    }
    if(dPeriod2 == 0 && slowing2 == 0) {
        dPeriod2 = kPeriod2 / 2;
        slowing2 = dPeriod2 / 2;
    }
    if(dPeriod3 == 0 && slowing3 == 0) {
        dPeriod3 = kPeriod3 / 2;
        slowing3 = dPeriod3 / 2;
    }
    if(dPeriod4 == 0 && slowing4 == 0) {
        dPeriod4 = kPeriod4 / 2;
        slowing4 = dPeriod4 / 2;
    }
    if(dPeriod5 == 0 && slowing5 == 0) {
        dPeriod5 = kPeriod5 / 2;
        slowing5 = dPeriod5 / 2;
    }
    if(dPeriod6 == 0 && slowing6 == 0) {
        dPeriod6 = kPeriod6 / 2;
        slowing6 = dPeriod6 / 2;
    }
    if(dPeriod7 == 0 && slowing7 == 0) {
        dPeriod7 = kPeriod7 / 2;
        slowing7 = dPeriod7 / 2;
    }
    if(dPeriod8 == 0 && slowing8 == 0) {
        dPeriod8 = kPeriod8 / 2;
        slowing8 = dPeriod8 / 2;
    }
 
    string indicatorName = "Stochastic Stack(";
    SetIndexBuffer(0, lineBuffer0);
    SetIndexStyle(0, DRAW_LINE);
    indicatorName = indicatorName + kPeriod1;
    if(countLine > 1)  {
        SetIndexBuffer(1, lineBuffer1);
        SetIndexStyle(1, DRAW_LINE);
        indicatorName = indicatorName + "," + kPeriod2;
    }
    if(countLine > 2) {
        SetIndexBuffer(2, lineBuffer2);
        SetIndexStyle(2, DRAW_LINE);
        indicatorName = indicatorName + "," + kPeriod3;
    }
    if(countLine > 3) {
        SetIndexBuffer(3, lineBuffer3);
        SetIndexStyle(3, DRAW_LINE);
        indicatorName = indicatorName + "," + kPeriod4;
    }
    if(countLine > 4) {
        SetIndexBuffer(4, lineBuffer4);
        SetIndexStyle(4, DRAW_LINE);
        indicatorName = indicatorName + "," + kPeriod5;
    }
    if(countLine > 5) {
        SetIndexBuffer(5, lineBuffer5);
        SetIndexStyle(5, DRAW_LINE);
        indicatorName = indicatorName + "," + kPeriod6;
    }
    if(countLine > 6) {
        SetIndexBuffer(6, lineBuffer6);
        SetIndexStyle(6, DRAW_LINE);
        indicatorName = indicatorName + "," + kPeriod7;
    }
    if(countLine > 7) {
        SetIndexBuffer(7, lineBuffer7);
        SetIndexStyle(7, DRAW_LINE);
        indicatorName = indicatorName + "," + kPeriod8;
    }
 
    indicatorName = indicatorName + ")";
    IndicatorShortName(indicatorName);
}
 
int start(){
    int indicatorCounted = IndicatorCounted();
    if (indicatorCounted < 0) { 
        return (-1);
    }
    if(indicatorCounted > 0) {
       indicatorCounted--;
    }
    int stochasticBuffer;
    if(modeSignal) {
        stochasticBuffer = MODE_SIGNAL;
    } else {
        stochasticBuffer = MODE_MAIN;
    }
   
    int limit = Bars - indicatorCounted;
    for(int i = limit - 1; i >= 0; i--) {
        lineBuffer0[i] = iStochastic(NULL, 0, kPeriod1, dPeriod1, slowing1, MODE_EMA, 1, stochasticBuffer, i);
        if(countLine > 1)  {
            lineBuffer1[i] = iStochastic(NULL, 0, kPeriod2, dPeriod2, slowing2, MODE_EMA, 1, stochasticBuffer, i);
        }
        if(countLine > 2) {
            lineBuffer2[i] = iStochastic(NULL, 0, kPeriod3, dPeriod3, slowing3, MODE_EMA, 1, stochasticBuffer, i);
        }
        if(countLine > 3) {
            lineBuffer3[i] = iStochastic(NULL, 0, kPeriod4, dPeriod4, slowing4, MODE_EMA, 1, stochasticBuffer, i);
        }
        if(countLine > 4) {
            lineBuffer4[i] = iStochastic(NULL, 0, kPeriod5, dPeriod5, slowing5, MODE_EMA, 1, stochasticBuffer, i);
        }
        if(countLine > 5) {
            lineBuffer5[i] = iStochastic(NULL, 0, kPeriod6, dPeriod6, slowing6, MODE_EMA, 1, stochasticBuffer, i);
        }
        if(countLine > 6) {
            lineBuffer6[i] = iStochastic(NULL, 0, kPeriod7, dPeriod7, slowing7, MODE_EMA, 1, stochasticBuffer, i);
        }
        if(countLine > 7) {
            lineBuffer7[i] = iStochastic(NULL, 0, kPeriod8, dPeriod8, slowing8, MODE_EMA, 1, stochasticBuffer, i);
        }
    }
}

Recommend