//+------------------------------------------------------------------+ //| alb + speed - RSI.mq5 | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 5 #property indicator_plots 1 #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_level1 70 #property indicator_level2 30 #property indicator_levelcolor DarkSlateGray // // // // // #property indicator_label1 "alb RSI" #property indicator_type1 DRAW_LINE #property indicator_color1 Lime #property indicator_width1 1 #property indicator_style1 STYLE_SOLID // // // // // input int inpSwingCount = 5; // Swing count for periods input double inpSpeed = 1.0; // Speed of adaption input ENUM_APPLIED_PRICE inpPrice = PRICE_CLOSE; // Apply to // // // // // double RsiBuffer[]; double TotBuffer[]; double ChgBuffer[]; double PrcBuffer[]; double SwpBuffer[]; // // // // // int priceHandle; int iSwingCount; double iSpeed; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int OnInit() { SetIndexBuffer(0,RsiBuffer,INDICATOR_DATA); ArraySetAsSeries(RsiBuffer,true); SetIndexBuffer(1,TotBuffer,INDICATOR_CALCULATIONS); ArraySetAsSeries(TotBuffer,true); SetIndexBuffer(2,ChgBuffer,INDICATOR_CALCULATIONS); ArraySetAsSeries(ChgBuffer,true); SetIndexBuffer(3,SwpBuffer,INDICATOR_CALCULATIONS); ArraySetAsSeries(SwpBuffer,true); SetIndexBuffer(4,PrcBuffer,INDICATOR_CALCULATIONS); ArraySetAsSeries(PrcBuffer,true); iSwingCount = (inpSwingCount>1) ? inpSwingCount : 1; iSpeed = (inpSpeed>0) ? inpSpeed : 0.000001; priceHandle = iMA(NULL,0,1,0,MODE_SMA,inpPrice); // // // // // IndicatorSetString(INDICATOR_SHORTNAME,"Alb RSI ("+(string)iSwingCount+") 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; for (int i=0; i<=last; i++) { ChgBuffer[rates_total-i-1] = 0; TotBuffer[rates_total-i-1] = 0; } limit -= last; } if (!checkCalculated(priceHandle,rates_total,"prices")) return(prev_calculated); if (!doCopy(priceHandle,PrcBuffer,0,limit ,"prices")) return(prev_calculated); if (!ArrayGetAsSeries(high)) ArraySetAsSeries(high ,true); if (!ArrayGetAsSeries(low)) ArraySetAsSeries(low ,true); // // // // // 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; // // // // // double alpha = 1 / albPeriod; if (i>=(rates_total-albPeriod)) { double sum = 0; int k = 0; for (;kPrcBuffer[i+k+1]) ? PrcBuffer[i+k]-PrcBuffer[i+k+1] : PrcBuffer[i+k+1]-PrcBuffer[i+k]; // // // // // ChgBuffer[i] = (PrcBuffer[i]-PrcBuffer[rates_total-1])/k; TotBuffer[i] = sum/k; } else { double change = PrcBuffer[i]-PrcBuffer[i+1]; ChgBuffer[i] = ChgBuffer[i+1] + alpha*( change - ChgBuffer[i+1]); TotBuffer[i] = TotBuffer[i+1] + alpha*(MathAbs(change) - TotBuffer[i+1]); } if (TotBuffer[i] != 0) RsiBuffer[i] = 50.0*((ChgBuffer[i]/TotBuffer[i])+1); else RsiBuffer[i] = 0; } // // // // // return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // bool checkCalculated(int bufferHandle, int total, string checkDescription) { int calculated=BarsCalculated(bufferHandle); if (calculated