Problem with indicator
Hi everyone,
it's my first post and i need your help for this indicator:
it always shows me the value 0
When you pass an array to a function you have to pass it by reference.
Read here: https://docs.mql4.com/basis/variables/formal
When you pass an array to a function you have to pass it by reference.
Read here: https://docs.mql4.com/basis/variables/formal
I should change
double Maarray(double arrayfixe[],int fast_period,int slow_period,int current)
by
double Maarray(double &arrayfixe[],int fast_period,int slow_period,int current)?
- Pass array by reference is necessary only if you want to modify the passed array.
double LWMA(double array[],int per,int bar) : Weight+= (per - i); // Sum += array[bar-i]*(per - i); Sum += array[bar+i]*(per - i); // array[bar] max weight // array[bar+per-1] weight=1
double HMA(double array[],int per,int bar) : // hma = LWMA(tmp,len,len-1); hma = LWMA(tmp,len,0); // tmp[0] max weight
- Get in the habit on counting down (must when closing/deleteing) it will simplify your code
for (int index=from; index<=from+period; index++) {
for (int index=from+period-1; index>=from; index--) {
for(int i = 0; i < len;i++) tmp[len-i-1] = 2*LWMA...
for(int i = len-1; i >= 0;i--) tmp[i] = 2*LWMA..
i change but it s not work
//+------------------------------------------------------------------+ //| Repulse_lisse.mq4 | //| | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Yellow #property indicator_color2 Lime #property indicator_color3 Coral //---- input parameters extern int RepulsePeriod3=15; extern int RepulsePeriod3fast=15; extern int RepulsePeriod3slow=15; extern int smooth = 10; //---- buffers double Smooth_3[]; extern double neutral_filter; double Up[]; double Down[]; double RepulseBuffer3[]; double PosBuffer[]; double NegBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; short_name="Repulse_lisse("+RepulsePeriod3+")"; IndicatorShortName(short_name); //---- indicators IndicatorBuffers(6); SetIndexBuffer(0, Smooth_3); SetIndexBuffer(1, Up); SetIndexBuffer(2, Down); SetIndexBuffer(3,RepulseBuffer3); SetIndexBuffer(4,PosBuffer); SetIndexBuffer(5,NegBuffer); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID,2); SetIndexStyle(1,DRAW_LINE, STYLE_SOLID,2); SetIndexStyle(2,DRAW_LINE, STYLE_SOLID,2); SetIndexStyle(3,DRAW_NONE); SetIndexStyle(4,DRAW_NONE); SetIndexStyle(5,DRAW_NONE); SetLevelValue(0,0); SetLevelStyle(STYLE_DOT,0,DimGray); //---- return(0); } //+------------------------------------------------------------------+ //| iteration function | //+------------------------------------------------------------------+ int start() { if (smooth <1) smooth=1; double forceHaussiere, forceBaissiere; int index = 0; int counted_bars=IndicatorCounted(); int limit = Bars - counted_bars; // Repulse3 for(index=0;index<Bars;index++) { PosBuffer[index] = ((((3*Close[index])-(2*getLow(index, RepulsePeriod3))-Open[index+RepulsePeriod3])/Close[index])*100); NegBuffer[index] = (((Open[index+RepulsePeriod3]+(2*getHigh(index, RepulsePeriod3))-(3*Close[index]))/Close[index])*100); } for(index=0;index<limit;index++) { forceHaussiere=Maarray(PosBuffer, RepulsePeriod3fast * 5, RepulsePeriod3slow * 5, index); forceBaissiere=Maarray(PosBuffer, RepulsePeriod3fast * 5, RepulsePeriod3slow * 5, index); RepulseBuffer3[index]=forceHaussiere-forceBaissiere; } //------------------------------------------------------ int i, lim; if(counted_bars>0) counted_bars--; lim = Bars-counted_bars; for(i=0; i< lim ; i++) Smooth_3[i]=Maarray(RepulseBuffer3,smooth,smooth,i); if(counted_bars>0) counted_bars--; lim = Bars-counted_bars; for(i=0; i< lim ; i++) { if ( Smooth_3[i]> Smooth_3[i+1]) Up[i] = Smooth_3[i]; else if ( Smooth_3[i] < Smooth_3[i+1]) Down[i]= Smooth_3[i]; else { Down[i]=EMPTY_VALUE; Up[i] =EMPTY_VALUE; } } return(0); } //+--------------------------------------------------------------- //+------------------------------------------------------------------+ double getLow(int from, int period) { double low = 9999999999; for (int index=from; index<=from+period; index++) { if (low > Low[index]) { low = Low[index]; } } return (low); } double getHigh(int from, int period) { double high = 0; for (int index=from; index<=from+period; index++) { if (high < High[index]) { high = High[index]; } } return (high); } //---------------------------------------------+ double Maarray(double &arrayfixe[],int fast_period,int slow_period,int current) { return (Histogram6(arrayfixe,fast_period,slow_period,current)); } double Histogram6(double &arrayfixe[],int fast_period,int slow_period,int current) { return (Ma(arrayfixe,fast_period,current) - Ma(arrayfixe,slow_period,current)); } double Ma(double &array[],int Periode, int bar) { return (HMA(array,Periode,bar)); } double LWMA(double &array[],int per,int bar) { double Sum = 0; double Weight = 0; for(int i = per-1;i>=0;i--) { Weight+= (per + i); Sum += array[bar+i]*(per + i); } if(Weight>0) double lwma = Sum/Weight; else lwma = 0; return(lwma); } double HMA(double &array[],int per,int bar) { double tmp[]; int len = MathSqrt(per); ArrayResize(tmp,len); if(bar == per) double hma = array[bar]; else if(bar > per) { for(int i = len-1; i>=0;i--) tmp[i] = 2*LWMA(array,per/2,bar-len+1-i) - LWMA(array,per,bar-len+1-i); hma = LWMA(tmp,len,0); } return(hma); }
Thank's for your answers
| What I posted in #2 above | Weight+= (per - i); // Sum += array[bar-i]*(per - i); Sum += array[bar+i]*(per - i); // array[bar] max weight |
| What you posted | Weight+= (per + i); Sum += array[bar+i]*(per + i); |
Thank you WHRoeder for you interest in my post
Hi everyone,
it's my first post and i need your help for this indicator:
it always shows me the value 0
I changed in the stable version
with
Thank you in advance for your answers