#property indicator_chart_window #property indicator_buffers 5 #property indicator_color1 clrLimeGreen #property indicator_color2 clrOrange #property indicator_color3 clrLimeGreen #property indicator_color4 clrOrange #property indicator_color5 clrOrange #property indicator_width3 3 #property indicator_width4 3 #property indicator_width5 3 // // // // // extern int OmaLength = 25; extern double OmaSpeed = 3.0; extern bool OmaAdaptive = true; extern double Sensitivity = 0.5; // Sensivity Factor extern double StepSize = 50; // Step Size period extern int Shift = 0; // Shift extern bool HighLow = false; // High/Low Mode Switch (more sensitive) extern int BarsWidth = 1; // Bars width (when bars are included in display) extern bool alertsOn = false; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; extern bool alertsNotification = false; extern bool alertsSound = false; extern bool alertsEmail = false; double LineBuffer[]; double DnBuffera[]; double DnBufferb[]; double histou[]; double histod[]; double smin[]; double smax[]; double trend[]; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int init() { IndicatorBuffers(8); SetIndexBuffer(0,histou); SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,BarsWidth); SetIndexBuffer(1,histod); SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,BarsWidth); SetIndexBuffer(2,LineBuffer); SetIndexShift(2,Shift); SetIndexBuffer(3,DnBuffera); SetIndexShift(3,Shift); SetIndexBuffer(4,DnBufferb); SetIndexShift(4,Shift); SetIndexBuffer(5,smin); SetIndexBuffer(6,smax); SetIndexBuffer(7,trend); IndicatorShortName("StepMA("+OmaLength+","+Sensitivity+","+StepSize+")"); OmaLength = MathMax(OmaLength, 1); OmaSpeed = MathMax(OmaSpeed ,-1.5); return(0); } int deinit() { return(0); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int start() { int i,counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = MathMin(Bars-counted_bars,Bars-1); // // // // // if (trend[limit]==-1) CleanPoint(limit,DnBuffera,DnBufferb); for(i=limit; i>=0; i--) { double thigh; double tlow; if (HighLow) { thigh=iAverage(High[i], OmaLength,OmaSpeed,OmaAdaptive,i,0); tlow =iAverage(Low[i], OmaLength,OmaSpeed,OmaAdaptive,i,7); } else { thigh=iAverage(Close[i],OmaLength,OmaSpeed,OmaAdaptive,i,0); tlow =iAverage(Close[i],OmaLength,OmaSpeed,OmaAdaptive,i,7);} LineBuffer[i] = iStepMa(Sensitivity,iATR(NULL,0,StepSize,i),1.0,thigh,tlow,Close[i],i); DnBuffera[i] = EMPTY_VALUE; DnBufferb[i] = EMPTY_VALUE; histou[i] = EMPTY_VALUE; histod[i] = EMPTY_VALUE; if (trend[i]==-1) PlotPoint(i,DnBuffera,DnBufferb,LineBuffer); if (trend[i]==-1) { histou[i] = Low[i]; histod[i] = High[i]; } if (trend[i]== 1) { histod[i] = Low[i]; histou[i] = High[i]; } } // // // // // if (alertsOn) { if (alertsOnCurrent) int whichBar = 0; else whichBar = 1; if (trend[whichBar] != trend[whichBar+1]) if (trend[whichBar] == 1) doAlert("up"); else doAlert("down"); } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // double stored[][14]; #define E1 0 #define E2 1 #define E3 2 #define E4 3 #define E5 4 #define E6 5 #define res 6 // // // // // double iAverage(double price, double averagePeriod, double tconst, bool adaptive, int i, int ashift=0) { if (ArrayRange(stored,0) != Bars) ArrayResize(stored,Bars); if (averagePeriod <=1) return(price); int r = Bars-i-1; double e1=stored[r-1][E1+ashift]; double e2=stored[r-1][E2+ashift]; double e3=stored[r-1][E3+ashift]; double e4=stored[r-1][E4+ashift]; double e5=stored[r-1][E5+ashift]; double e6=stored[r-1][E6+ashift]; // // // // // if (adaptive && (averagePeriod > 1)) { double minPeriod = averagePeriod/2.0; double maxPeriod = minPeriod*5.0; int endPeriod = MathCeil(maxPeriod); double tsignal = MathAbs((price-stored[r-endPeriod][res+ashift])); double noise = 0.00000000001; for(int k=1; kworkStep[r-1][_smax]) workStep[r][_trend] = 1; if (pprice workStep[r-1][_smax]) workStep[r][_smax]=workStep[r-1][_smax]; result = workStep[r][_smax]-size*stepMulti; } trend[Bars-r-1] = workStep[r][_trend]; return(result); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // 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()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Step Oma ",doWhat); if (alertsMessage) Alert(message); if (alertsNotification) SendNotification(message); if (alertsEmail) SendMail(StringConcatenate(Symbol()," Step Oma "),message); if (alertsSound) PlaySound("alert2.wav"); } } //------------------------------------------------------------------- // //------------------------------------------------------------------- // // // // // void CleanPoint(int i,double& first[],double& second[]) { 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 (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; } }