//+------------------------------------------------------------------+ //| ravi.mq4 | //| from Mladen mt5 version | //+------------------------------------------------------------------+ #property link "www.forex-station.com" #property copyright "www.forex-station.com" #property indicator_separate_window #property indicator_buffers 8 #property indicator_color1 clrForestGreen #property indicator_color2 clrGray #property indicator_color3 clrCrimson #property indicator_color4 clrGray #property indicator_color5 clrForestGreen #property indicator_color6 clrForestGreen #property indicator_color7 clrCrimson #property indicator_color8 clrCrimson #property indicator_style1 STYLE_DOT #property indicator_style2 STYLE_DOT #property indicator_style3 STYLE_DOT #property indicator_width4 3 #property indicator_width5 3 #property indicator_width6 3 #property indicator_width7 3 #property indicator_width8 3 #property indicator_level1 0 #property indicator_levelcolor clrMediumOrchid #property strict // // // // // enum enPrices { pr_close, // Close pr_open, // Open pr_high, // High pr_low, // Low pr_median, // Median pr_typical, // Typical pr_weighted, // Weighted pr_average, // Average (high+low+open+close)/4 pr_medianb, // Average median body (open+close)/2 pr_tbiased, // Trend biased price pr_tbiased2, // Trend biased (extreme) price pr_haclose, // Heiken ashi close pr_haopen , // Heiken ashi open pr_hahigh, // Heiken ashi high pr_halow, // Heiken ashi low pr_hamedian, // Heiken ashi median pr_hatypical, // Heiken ashi typical pr_haweighted, // Heiken ashi weighted pr_haaverage, // Heiken ashi average pr_hamedianb, // Heiken ashi median body pr_hatbiased, // Heiken ashi trend biased price pr_hatbiased2, // Heiken ashi trend biased (extreme) price pr_habclose, // Heiken ashi (better formula) close pr_habopen , // Heiken ashi (better formula) open pr_habhigh, // Heiken ashi (better formula) high pr_hablow, // Heiken ashi (better formula) low pr_habmedian, // Heiken ashi (better formula) median pr_habtypical, // Heiken ashi (better formula) typical pr_habweighted,// Heiken ashi (better formula) weighted pr_habaverage, // Heiken ashi (better formula) average pr_habmedianb, // Heiken ashi (better formula) median body pr_habtbiased, // Heiken ashi (better formula) trend biased price pr_habtbiased2 // Heiken ashi (better formula) trend biased (extreme) price }; enum enMaTypes { ma_sma, // Simple moving average ma_ema, // Exponential moving average ma_smma, // Smoothed MA ma_lwma, // Linear weighted MA }; enum enColorMode { col_onZero, // Change color on middle line cross col_onOuter // Change color on outer levels cross }; input int inpFastPeriod = 7; // Fast period input int inpSlowPeriod = 65; // Slow period input enMaTypes inpMaMethod = ma_sma; // Moving average method input enPrices inpPrice = pr_close; // Ravi price to use input int inpFlPeriod = 32; // Floating levels period input double inpFlLevelUp = 80.0; // Up level % input double inpFlLevelDn = 20.0; // Down level % input enColorMode inpColorMode = col_onOuter; // Change color mode input bool alertsOn = true; // Alerts on true/false? input bool alertsOnCurrent = false; // Alerts on current bar true/false? input bool alertsMessage = true; // Alerts message true/false? input bool alertsSound = false; // Alerts sound true/false? input bool alertsEmail = false; // Alerts email true/false? input bool alertsNotify = false; // Alerts notification true/false? input string soundFile = "alert2.wav";// Alerts Sound file //--- indicator buffers double val[],valUpa[],valUpb[],valDna[],valDnb[],valc[],flup[],flmi[],fldn[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(9); SetIndexBuffer(0,flup, INDICATOR_DATA); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1,flmi, INDICATOR_DATA); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(2,fldn, INDICATOR_DATA); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(3,val, INDICATOR_DATA); SetIndexStyle(3,DRAW_LINE); SetIndexBuffer(4,valUpa,INDICATOR_DATA); SetIndexStyle(4,DRAW_LINE); SetIndexBuffer(5,valUpb,INDICATOR_DATA); SetIndexStyle(5,DRAW_LINE); SetIndexBuffer(6,valDna,INDICATOR_DATA); SetIndexStyle(6,DRAW_LINE); SetIndexBuffer(7,valDnb,INDICATOR_DATA); SetIndexStyle(7,DRAW_LINE); SetIndexBuffer(8,valc, INDICATOR_CALCULATIONS); //--- indicator short name assignment IndicatorShortName("Range action verification index ("+(string)inpFastPeriod+","+(string)inpSlowPeriod+")"); //--- return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator de-initialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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 i,counted_bars=prev_calculated; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = fmin(rates_total-counted_bars,rates_total-1); // // // // // if (valc[limit]== 1) CleanPoint(limit,valUpa,valUpb); if (valc[limit]==-1) CleanPoint(limit,valDna,valDnb); for(i=limit; i>=0; i--) { double _price=getPrice(inpPrice,open,close,high,low,i,rates_total); double _maFast = iCustomMa(inpMaMethod,_price,inpFastPeriod,i,rates_total,0); double _maSlow = iCustomMa(inpMaMethod,_price,inpSlowPeriod,i,rates_total,1); // // // // // val[i] = (_maSlow!=0) ? 100.0*(_maFast-_maSlow)/_maSlow : 0; valUpa[i] = EMPTY_VALUE; valUpb[i] = EMPTY_VALUE; valDna[i] = EMPTY_VALUE; valDnb[i] = EMPTY_VALUE; double min = val[ArrayMinimum(val,inpFlPeriod,i)]; double max = val[ArrayMaximum(val,inpFlPeriod,i)]; double range = max-min; flup[i] = min+inpFlLevelUp*range/100.0; fldn[i] = min+inpFlLevelDn*range/100.0; flmi[i] = min+50 *range/100.0; switch (inpColorMode) { case col_onOuter : valc[i] = (val[i]>flup[i]) ? 1 :(val[i]flmi[i]) ? 1 :(val[i]=0; k++) avg += workSma[r-k][instanceNo+0]; return(avg/(double)k); } // // // // // double workEma[][_maWorkBufferx1]; double iEma(double price, double period, int r, int _bars, int instanceNo=0) { if (ArrayRange(workEma,0)!= _bars) ArrayResize(workEma,_bars); workEma[r][instanceNo] = price; if (r>0 && period>1) workEma[r][instanceNo] = workEma[r-1][instanceNo]+(2.0/(1.0+period))*(price-workEma[r-1][instanceNo]); return(workEma[r][instanceNo]); } // // // // // double workSmma[][_maWorkBufferx1]; double iSmma(double price, double period, int r, int _bars, int instanceNo=0) { if (ArrayRange(workSmma,0)!= _bars) ArrayResize(workSmma,_bars); workSmma[r][instanceNo] = price; if (r>1 && period>1) workSmma[r][instanceNo] = workSmma[r-1][instanceNo]+(price-workSmma[r-1][instanceNo])/period; return(workSmma[r][instanceNo]); } // // // // // double workLwma[][_maWorkBufferx1]; double iLwma(double price, double period, int r, int _bars, int instanceNo=0) { if (ArrayRange(workLwma,0)!= _bars) ArrayResize(workLwma,_bars); workLwma[r][instanceNo] = price; if (period<=1) return(price); double sumw = period; double sum = period*price; for(int k=1; k=0; k++) { double weight = period-k; sumw += weight; sum += weight*workLwma[r-k][instanceNo]; } return(sum/sumw); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // #define _prHABF(_prtype) (_prtype>=pr_habclose && _prtype<=pr_habtbiased2) #define _priceInstances 1 #define _priceInstancesSize 4 double workHa[][_priceInstances*_priceInstancesSize]; double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars, int instanceNo=0) { if (tprice>=pr_haclose) { if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); instanceNo*=_priceInstancesSize; int r = bars-i-1; // // // // // double haOpen = (r>0) ? (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0 : (open[i]+close[i])/2;; double haClose = (open[i]+high[i]+low[i]+close[i]) / 4.0; if (_prHABF(tprice)) if (high[i]!=low[i]) haClose = (open[i]+close[i])/2.0+(((close[i]-open[i])/(high[i]-low[i]))*fabs((close[i]-open[i])/2.0)); else haClose = (open[i]+close[i])/2.0; double haHigh = fmax(high[i], fmax(haOpen,haClose)); double haLow = fmin(low[i] , fmin(haOpen,haClose)); // // // // // if(haOpenhaOpen) return((haHigh+haClose)/2.0); else return((haLow+haClose)/2.0); case pr_hatbiased2: case pr_habtbiased2: if (haClose>haOpen) return(haHigh); if (haCloseopen[i]) return((high[i]+close[i])/2.0); else return((low[i]+close[i])/2.0); case pr_tbiased2: if (close[i]>open[i]) return(high[i]); if (close[i]=Bars-3) return; if ((second[i] != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE)) second[i+1] = EMPTY_VALUE; else if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE)) first[i+1] = EMPTY_VALUE; } void PlotPoint(int i,double& first[],double& second[],double& from[]) { if (i>=Bars-2) return; if (first[i+1] == EMPTY_VALUE) if (first[i+2] == EMPTY_VALUE) { first[i] = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; } else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; } else { first[i] = from[i]; second[i] = EMPTY_VALUE; } } // // // // // string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"}; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable[i]) return(sTfTable[i]); return(""); } //+------------------------------------------------------------------+ // // // // void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; // // // // // message = StringConcatenate(Symbol()," ",timeFrameToString(_Period)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Ravi ",doWhat); if (alertsMessage) Alert(message); if (alertsNotify) SendNotification(message); if (alertsEmail) SendMail(_Symbol+" Ravi ",message); if (alertsSound) PlaySound(soundFile); } }