//---- indicator settings #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 White #property indicator_color2 Red #property indicator_color3 Blue #property indicator_color4 Violet //---- indicator parameters extern int ma_period=12; extern int ma_method=MODE_SMA ; extern int ma_varpip=2 ; extern int ma_periodpip=4 ; //---- indicator buffers double VariatorFlat[] ; double VariatorUp[] ; double VariatorDown[] ; double Trans[] ; //Differentiate a buffer void differentiate(double buff[], double& res[]) { ArrayResize(res, ArraySize(buff)) ; ArrayInitialize(res, 0) ; for(int var=0 ; var<ArraySize(buff)-1 ; var++) { res[var] = buff[var]-buff[var+1] ; } } //Compute variation on a buffer at index for period double getVar(double buff[], int index, int period) { double res=0 ; for(int i=index ; i<index+period && i<ArraySize(buff)-1 ; i++) { res += buff[i]-buff[i+1] ; } return(res) ; } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexBuffer(0, VariatorFlat) ; SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1) ; SetIndexEmptyValue(0, 0.0) ; SetIndexBuffer(1, VariatorUp) ; SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1) ; SetIndexEmptyValue(1, 0.0) ; SetIndexBuffer(2, VariatorDown) ; SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 1) ; SetIndexEmptyValue(2, 0.0) ; SetIndexBuffer(3, Trans) ; SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 3) ; //---- indicator buffers mapping //---- name for DataWindow and indicator subwindow label IndicatorShortName("MA variator") ; SetIndexLabel(0, "MA variator") ; //---- initialization done return(0) ; } //+------------------------------------------------------------------+ //| Moving Averages variation | //+------------------------------------------------------------------+ int start() { double maclose[] ; double madiff[] ; double vopen[] ; double vclose[] ; double pipval ; static int value=0 ; int limit ; int counted_bars ; if(Bars<=ma_period+ma_periodpip) return(0) ; counted_bars = IndicatorCounted() ; if(counted_bars>0) counted_bars-- ; limit = Bars-counted_bars ; //---------------------------------------------------------- //Création des buffers ArrayResize(maclose, ArraySize(VariatorUp)) ; ArrayInitialize(maclose, 0) ; ArrayResize(madiff, ArraySize(VariatorUp)) ; ArrayInitialize(madiff, 0) ; for(int i=0 ; i<limit ; i++) maclose[i] = iMA(NULL, 0, ma_period, 0, ma_method, PRICE_CLOSE, i) ; differentiate(maclose, madiff) ; ArrayCopySeries(vopen, MODE_OPEN) ; ArrayCopySeries(vclose, MODE_CLOSE) ; //---------------------------------------------------------- //Compute indicator i = Bars-counted_bars-1 ; while(i>=0) { double var ; int v=0 ; //MA variator var = getVar(maclose, i, ma_periodpip) ; if(var>=Point*ma_varpip) { v = 1 ; VariatorUp[i] = maclose[i] ; VariatorFlat[i] = 0 ; VariatorDown[i] = 0 ; } else if(var<=-Point*ma_varpip) { v = 2 ; VariatorUp[i] = 0 ; VariatorFlat[i] = 0 ; VariatorDown[i] = maclose[i] ; } else { v = 0 ; VariatorUp[i] = 0 ; VariatorFlat[i] = maclose[i] ; VariatorDown[i] = 0 ; } //Inversion indicator if(VariatorUp[i]!=0) { if(vopen[i]>vclose[i] && vopen[i+1]<vclose[i+1]) { Trans[i] = vclose[i] ; } else { Trans[i] = 0 ; } } else if(VariatorDown[i]!=0) { if(vopen[i]<vclose[i] && vopen[i+1]>vclose[i+1]) { Trans[i] = vclose[i] ; } else { Trans[i] = 0 ; } } else { Trans[i] = 0 ; } i-- ; } // value++ ; // Print(value, " ", Symbol(), " ", Period()) ; Print(VariatorUp[0], " ", VariatorFlat[0], " ", VariatorDown[0]) ; return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Implements a curve of type DRAW_ARROW
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: