//------------------------------------------------------------------ #property copyright "mladen" #property link "mladenfx@gmail.com" #property version "1.00" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 7 #property indicator_plots 3 #property indicator_label1 "Ocean nmr upper band" #property indicator_type1 DRAW_LINE #property indicator_color1 clrAqua #property indicator_style1 STYLE_SOLID #property indicator_label2 "Ocean nmr lower band" #property indicator_type2 DRAW_LINE #property indicator_color2 clrYellow #property indicator_style2 STYLE_SOLID #property indicator_label3 "Ocean nmr" #property indicator_type3 DRAW_LINE #property indicator_color3 clrWhite #property indicator_style3 STYLE_SOLID // // // // // input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame input int inpNmrPeriod = 20; // Natural market river calculation period input bool inpWrongWay = false; // Wrong calculation way ? input bool alertsOn = false; // Alerts on input bool alertsOnCurrent = true; // Alert on current bar input bool alertsOnZeroCross = true; // Alerts on zero line cross input bool alertsOnBandCross = true; // Alerts on bands crosses input bool alertsMessage = true; // Display messageas on alerts input bool alertsSound = false; // Play sound on alerts input bool alertsNotification = false; // Send notification input bool alertsEmail = false; // Send email on alerts input bool Interpolate = true; // Interpolate mtf data ? // // // // // double nmr[]; double nmrbu[]; double nmrbd[]; double countBuffer[]; double trendz[]; double trendu[]; double trendd[]; ENUM_TIMEFRAMES timeFrame; int mtfHandle; bool calculating; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int OnInit() { SetIndexBuffer(0,nmrbu,INDICATOR_DATA); SetIndexBuffer(1,nmrbd,INDICATOR_DATA); SetIndexBuffer(2,nmr ,INDICATOR_DATA); SetIndexBuffer(3,countBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(4,trendz,INDICATOR_CALCULATIONS); SetIndexBuffer(5,trendu,INDICATOR_CALCULATIONS); SetIndexBuffer(6,trendd,INDICATOR_CALCULATIONS); timeFrame = MathMax(_Period,TimeFrame); calculating = (timeFrame==_Period); if (!calculating) mtfHandle = iCustom(NULL,timeFrame,getIndicatorName(),PERIOD_CURRENT,inpNmrPeriod,inpWrongWay,alertsOn,alertsOnCurrent,alertsOnZeroCross,alertsOnBandCross,alertsMessage,alertsSound,alertsNotification,alertsEmail); IndicatorSetString(INDICATOR_SHORTNAME,getPeriodToString(timeFrame)+" Ocean nmr ("+(string)inpNmrPeriod+")"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // #define iPrc 3 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[]) { // // // // // if (calculating) { for (int i=(int)MathMax(prev_calculated-1,1); i=0; k++) { if (k>0) { sum += MathAbs(MathLog(close[i-k])*100000 - MathLog(close[i-k-1])*100000); sum2 += MathAbs(MathLog(close[i-k])*100000 - MathLog(close[i-k-1])*100000)*(MathSqrt(k+1)-MathSqrt(k)); } else r += MathAbs(MathLog(close[i-k])*100000 - MathLog(close[i-k-1])*100000); x += (MathLog(close[i] )*100000 - MathLog(close[i-k-1])*100000)/MathSqrt(k+1); } // // // // // r += sum2; x /= (inpNmrPeriod*1.0); double ratio = 1; if (sum!=0) ratio = MathRound(sum2)/MathRound(sum); if (inpWrongWay) { nmr[i] = ratio*x; nmrbu[i] = ratio*ratio*r; } else { nmr[i] = nmr[i-1]+ratio*(x-nmr[i-1]); nmrbu[i] = nmrbu[i-1]+ratio*(r*ratio - nmrbu[i-1]); } nmrbd[i] = -nmrbu[i]; trendz[i] = trendz[i-1]; trendu[i] = trendu[i-1]; trendd[i] = trendd[i-1]; if (nmr[i]>0) trendz[i] = 1; if (nmr[i]<0) trendz[i] = -1; if (nmr[i]>nmrbu[i]) trendu[i] = 1; if (nmr[i]nmrbd[i]) trendd[i] = 1; if (nmr[i]time[0] || bars<1) return(rates_total); double tnmu[]; CopyBuffer(mtfHandle,0,0,bars,tnmu); double tnmd[]; CopyBuffer(mtfHandle,1,0,bars,tnmd); double tnmr[]; CopyBuffer(mtfHandle,2,0,bars,tnmr); double count[]; CopyBuffer(mtfHandle,3,0,bars,count); int maxb = (int)MathMax(MathMin(count[bars-1]*PeriodSeconds(timeFrame)/PeriodSeconds(_Period),rates_total-1),1); // // // // // for(int i=(int)MathMax(prev_calculated-maxb,0); i -1 && d < bars) { nmr[i] = tnmr[d]; nmrbu[i] = tnmu[d]; nmrbd[i] = tnmd[d]; } if (!Interpolate) continue; // // // // // int l=MathMin(i+1,rates_total-1); if (d!=dateArrayBsearch(times,time[l],bars) || i==l) { int n,k; for(n = 1; (i-n)> 0 && time[i-n] >= times[d]; n++) continue; for(k = 1; (i-k)>=0 && k= first) { mid = (first + last) >> 1; if (toFind == times[mid] || (mid < (total-1) && (toFind > times[mid]) && (toFind < times[mid+1]))) break; if (toFind < times[mid]) last = mid - 1; else first = mid + 1; } return (mid); }