Download MetaTrader 5
To add comments, please log in or register
Share links from other resources. Now they have a description.
scarr
34
scarr 2012.04.24 14:06 

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

whroeder1
13600
whroeder1 2012.04.24 16:36  
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.
Ian Venner
2583
Ian Venner 2012.04.24 19:50  
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);
Hely Rojas
202
Hely Rojas 2014.12.02 17:01  

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);
gadget
100
gadget 2014.12.03 13:33  
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).
/
To add comments, please log in or register