Dear Mr. Rosh,Please give me an example

 

Hi ! Dear Mr. Rosh,

How to use the iCustom() ?

Would you give me an example how to use the great Fuction ?

For example , like the indicator ATR ('Average True Range, ATR')

My problem is how to put the parameters in right way ?

To make things simple,Could you put the parameters' Name in below ,to make it work !

iCustom(NULL,Timeframe,"ATR",parameter1,parameter2,...,shift)

Thank you in advance !

 
See indicator ATR Channels
 

Mr. Rosh

Thank you for reply quickly

My problem is how to use the parameters at EA side to cntrol (change) those parameters at indicator side

For example, at ATR inner having an iMAOnArray(TempBuffer,Bars,AtrPeriod,ma_shift,ma_method,i)

I should have put the parameters at EA side like this :

extern int ATR_Timeframe =60;
extern int total=0;
extern int AtrPeriod=14;
extern int ma_shift=0;
extern int ma_method=0;// 0=MODE_SMA, 1=MODE_EMA, 2=MODE_SMMA, 3=MODE_LWMA

..............

aaa=iCustom(NULL,ATR_Timeframe,"ATR",total,AtrPeriod, ma_shift,ma_method, bar-1);

I follow th rules Reference of MT4 like above

But it doesn't work !

The iMAOnArray() couldn't get these parameters at ED side

What's wrong with me ?

Please help me !

 
You must call function iCustom() with parameters in same order as indicator was written.

aaa=iCustom(NULL,ATR_Timeframe,"ATR",AtrPeriod,0, 1); // value of ATR on first bar

See ATR source
//+------------------------------------------------------------------+
//|                                                          ATR.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net//"
 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int AtrPeriod=14;
//---- buffers
double AtrBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 1 additional buffer used for counting.
   IndicatorBuffers(2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,AtrBuffer);
   SetIndexBuffer(1,TempBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="ATR("+AtrPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,AtrPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Average True Range                                               |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   if(Bars<=AtrPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=AtrPeriod;i++) AtrBuffer[Bars-i]=0.0;
//----
   i=Bars-counted_bars-1;
   while(i>=0)
     {
      double high=High[i];
      double low =Low[i];
      if(i==Bars-1) TempBuffer[i]=high-low;
      else
        {
         double prevclose=Close[i+1];
         TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose);
        }
      i--;
     }
//----
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   for(i=0; i<limit; i++)
      AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i);
//----
   return(0);
  }
//+------------------------------------------------------------------+
It has only one input "AtrPeriod" and two indicator buffers: AtrBuffer[] which bounded with 0 index and TempBuffer which bounded with 1 index.
原因: