Smoothing indicator

 

Hi,

I have an indicator on a 1min GBPUSD chart and it is created by looping through the bars getting the EURUSD closing price, The indicator works fine but I want to smooth this indicator how do I do it? (example please as I have tried and failed several times using iMA and iMAOnArray)

P.S. Sorry I know this is probably a stupid easy question but I hve spent ages trying to sort it so please help :)

Steve

 
scarr:
I have tried and failed several times using iMA and iMAOnArray
Post your code. We're not going to code it FOR you. We are willing to HELP you.
 
scarr:

Hi,

I have an indicator on a 1min GBPUSD chart and it is created by looping through the bars getting the EURUSD closing price, The indicator works fine but I want to smooth this indicator how do I do it? (example please as I have tried and failed several times using iMA and iMAOnArray)

P.S. Sorry I know this is probably a stupid easy question but I hve spent ages trying to sort it so please help :)

Steve


Have a look at this code used to create a MACD as an example how to use iMAOnArray(), notice it uses two loops, one to prepare the data in an array and the second to use it in iMAOnArray() to smooth the signal line

Also notice SetIndexDrawBegin() used for the signal line

int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,SignalSMA);
//---- indicator buffers mapping
   SetIndexBuffer(0,MacdBuffer);
   SetIndexBuffer(1,SignalBuffer);
//---- initialization done
   return(0);
  }

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(int i=0; i<limit; i++)
      MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
   return(0);
 

Simple

 before leaving the function init() apply a small operation that reduces noise.

 

for(i=0; i<limit; i++)
      buffer0[i]=(buffer0[i]+buffer0[i+1]+buffer0[i+2])/3;

return(0);
 
You could download a copy of the famous book "Trading for a leaving", it includes the formulas for the main smoothing methods. If you are after a single value, then smoothing using a MA already offers quite a number of options (algorithm, periods, shift, price type etc).
Reason: