//+------------------------------------------------------------------+ //| alb - stochastic.mq5 | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 2 #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_level1 80 #property indicator_level2 20 #property indicator_levelcolor DarkSlateGray // // // // // #property indicator_label1 "Stochastic" #property indicator_type1 DRAW_LINE #property indicator_color1 Lime #property indicator_style1 STYLE_SOLID #property indicator_label2 "Stochastic signal" #property indicator_type2 DRAW_LINE #property indicator_color2 OrangeRed #property indicator_style2 STYLE_DOT // // // // // enum ENUM_STOCH_TYPE { sttHL, // Low - high sttCl // Close - close }; input int inpSwingCount = 5; // Swing count for periods input double inpSpeed = 1.0; // Speed of the indicator input int inpSlowing = 3; // Slowing length input int inpSignal = 3; // Signal length input ENUM_MA_METHOD inpSignalMode = MODE_EMA; // Signal line calculation mode input ENUM_STOCH_TYPE inpStochType = sttHL; // Stochatic calculation type // // // // // double StcBuffer[]; double StrBuffer[]; double SigBuffer[]; double SwpBuffer[]; // // // // // int iSwingCount; int iSlowing; int iSignal; double iUpLevel; double iDnLevel; double iSpeed; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int OnInit() { SetIndexBuffer(0,StcBuffer,INDICATOR_DATA); ArraySetAsSeries(StcBuffer,true); SetIndexBuffer(1,SigBuffer,INDICATOR_DATA); ArraySetAsSeries(SigBuffer,true); SetIndexBuffer(2,StrBuffer,INDICATOR_CALCULATIONS); ArraySetAsSeries(StrBuffer,true); SetIndexBuffer(3,SwpBuffer,INDICATOR_CALCULATIONS); ArraySetAsSeries(SwpBuffer,true); iSwingCount = (inpSwingCount>1) ? inpSwingCount : 1; iSlowing = (inpSlowing>1) ? inpSlowing : 1; iSignal = (inpSignal>1) ? inpSignal : 1; iSpeed = (inpSpeed>0) ? inpSpeed : 0.000001; // // // // // IndicatorSetString(INDICATOR_SHORTNAME,"Alb stochastic ("+(string)iSwingCount+","+(string)iSlowing+","+(string)iSignal+") speed ("+DoubleToString(iSpeed,Digits())+")"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int OnCalculate(const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[]) { // // // // // int limit = rates_total-prev_calculated; if (prev_calculated > 0) limit++; if (prev_calculated ==0) { int last = (iSwingCount>5) ? iSwingCount : 5; last = (iSlowing>last) ? iSlowing : last; last = (iSignal >last) ? iSignal : last; limit -= last; } if (!ArrayGetAsSeries(close)) ArraySetAsSeries(close,true); if (!ArrayGetAsSeries(high)) ArraySetAsSeries(high ,true); if (!ArrayGetAsSeries(low)) ArraySetAsSeries(low ,true); // // // // // double min,max; for (int i=limit; i>=0; i--) { SwpBuffer[i] = 0; if (low[i+3] high[i+2] && high[i]>high[i+1]) SwpBuffer[i] = -1; if (high[i+3]>high[i+4] && high[i+2]>high[i+3] && low[i+1] 1) ? albPeriod : 1; // // // // // switch (inpStochType) { case sttHL : max = high[i]; for(int k=1; k=0; i--) { if (i>(total-period)) buffer[i] = price[i]; else { double sum = 0; for (int l=0; l=0; i--) { if (i>(total-period)) buffer[i] = price[i]; else buffer[i] = buffer[i+1]+alpha*(price[i]-buffer[i+1]); } ArraySetAsSeries(buffer, as_series_buffer); ArraySetAsSeries(price, as_series_price); } // // // // // void iSMMAOnBuffer(const int total, const int limit, const int period, const double& price[], double& buffer[]) { bool as_series_price = ArrayGetAsSeries(price); bool as_series_buffer = ArrayGetAsSeries(buffer); if(!as_series_price) ArraySetAsSeries(price, true); if(!as_series_buffer) ArraySetAsSeries(buffer,true); // // // // // for (int i=limit; i>=0; i--) { if (i>(total-period)) { int l=0; double sum = 0; for(;(i+l)0) buffer[i] = sum/l; else buffer[i] = price[i]; } else buffer[i] = (buffer[i+1]*(period-1)+price[i])/period; } ArraySetAsSeries(buffer, as_series_buffer); ArraySetAsSeries(price, as_series_price); } // // // // // void iLWMAOnBuffer(const int total, const int limit, const int period, const double& price[], double& buffer[]) { bool as_series_price = ArrayGetAsSeries(price); bool as_series_buffer = ArrayGetAsSeries(buffer); if(!as_series_price) ArraySetAsSeries(price, true); if(!as_series_buffer) ArraySetAsSeries(buffer,true); // // // // // for (int i=limit; i>=0; i--) { if (i>(total-period)) buffer[i] = price[i]; else { double sum = 0; double weight = 0; for (int l=0,k=period; l