Download MetaTrader 5

Load indicator - iCustom

To add comments, please log in or register
Kima
373
Kima  

Ive tried to load this indicator to my EA: https://www.mql5.com/en/forum/9660/page9#comment_411206

But i need some help.. 

Ive tried:

//---- indicator parameters - in the indicator it self
input int                  Length         =  9;    // Price Channel Period
input ENUM_APPLIED_PRICE   Price          =  PRICE_CLOSE;    // Applied Price
input double               Risk           =  3;    // Risk Factor in units (0...10) 
input int                  UseReEntry     =  1;    // Re-Entry Mode: 0-off,1-on
input int                  AlertMode      =  0;    // Alert Mode: 0-off,1-on
input int                  WarningMode    =  0;    // Warning Mode: 0-off,1-on
input string               WarningSound   =  "tick.wav"; 


// input the indicator in EA   
int OnInit()
  {
 handles2[0]=iCustom(symbol[0],Time_Frame,"PriceChannel_Signal_v1"); 
         if(handles2[0]<0)
           {
            Alert("Can not get icustom.");
            return(-1);
           }
}
// and tried
int OnInit()
  {
handles2[0]=iCustom(symbol[0],Time_Frame,"PriceChannel_Signal_v1",9,PRICE_CLOSE,3,1,0,0,"tick.wav"); 
         if(handles2[0]<0)
           {
            Alert("Can not get icustom.");
            return(-1);
           }
}

 

 My idea was that with:

handles2[0]=iCustom(symbol[0],Time_Frame,"PriceChannel_Signal_v1");

it would just load the standaard inputs from the indicator self .. But it still says "array out of range"

PriceChannel Parabolic system
PriceChannel Parabolic system
  • www.mql5.com
So I decided to create some simple trading system with re-enter based on indicator's arrow on the chart.
Pasi Hakamaki
6345
Pasi Hakamaki  

Hi Kima,

I believe that if you specify no input parameters the default values will be used automatically, see below:

int  iCustom(
   string           symbol,     // symbol name
   ENUM_TIMEFRAMES  period,     // period
   string           name        // folder/custom indicator_name
   ...                          // list of indicator input parameters
   );

Parameters

symbol

[in] The symbol name of the security, the data of which should be used to calculate the indicator. The NULL value means the current symbol.

period

[in] The value of the period can be one of the ENUM_TIMEFRAMES values, 0 means the current timeframe.

name

[in] The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/Examples, its name must be specified like: "Examples\\indicator_name" (it is necessary to use a double slash instead of the single slash as a separator).

...

[in] input-parameters of a custom indicator, separated by commas. Type and order of parameters must match. If there is no parameters specified, then default values will be used.

Kima
373
Kima  

I see i messed up the post, after a review it works now. At least i dont get the error anymore.

But now how to get the data from the indicator..

void OnTick() 
  { 
   for(int i=0;i<symbols;i++)
     {
      Print(get_Custom(handles[i],0));
     }
  }
  
double get_Custom(int handle,int bar)
  {
   double lw[1]={0};
   CopyBuffer(handle,0,bar,1,lw);
   return(lw[0]);
  }

 Ive red the copybuffer part an reviewed a view other example EA's but i dont get it yet.. 

 

 With the code above i thought i can get the information from the indicater:

"SetIndexBuffer(0,UpSignal,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_ARROW,108);"

 is set to true or false.

 

So i thought in the copybuffer the 0  before the 'UpSignal' was:

 int       start_pos,            // start position

  Or am i thinking the wrong way?

 

 

Miguelito Yap
640
Miguelito Yap  

iCustom returns the handle of the indicator.  You have to create an array and then copy the inidicator's buffer to it.  Then you access the data as you would an array.

Example:

handle = iCustom( etc....

double indicatorName[]; //rezise this to the amount of data you want to get, countToRetrieve below

ArraySetAsSeries(indicatorName,true); //ensures, the latest value is at the beginning of the buffer.

CopyBuffer(handle,bufferNumer,start,countToRetrieve,indicatorName);

To get the current value, you invoke indicatorName[0].

Mike 

phi nuts
2181
phi nuts  
Kima:

I see i messed up the post, after a review it works now. At least i dont get the error anymore.

But now how to get the data from the indicator..

 Ive red the copybuffer part an reviewed a view other example EA's but i dont get it yet.. 

 

 With the code above i thought i can get the information from the indicater:

"SetIndexBuffer(0,UpSignal,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_ARROW,108);"

 is set to true or false.

 

So i thought in the copybuffer the 0  before the 'UpSignal' was:

 int       start_pos,            // start position

  Or am i thinking the wrong way?


I don't understand what you mean by "So i thought in the copybuffer the 0  before the 'UpSignal' was: in start_pos ...". Where's the 0 before 'UpSignal' ?.


With your code, you will get the data of the current bar. The current bar may not yet fully develop, and so the indicator may not draw anything yet. Also this indicator only draw some dot, so it possible that it won't draw dot at all.

To solve this, get the indicator data of bar 1 instead of bar 0.

void OnTick() 
  { 
   for(int i=0;i<symbols;i++)
     {
      Print(get_Custom(handles[i],1)); //--- data of bar 1
     }
  }
  
double get_Custom(int handle,int bar)
  {
   double lw[1]={0};
   CopyBuffer(handle,0,bar,1,lw);
   return(lw[0]);
  }
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Drawing Styles - Documentation on MQL5
Kima
373
Kima  

Hmm ok.

@Mike  It looks interesting to fill a array when it makes a point in the indicator.. 

@phi.nuts  okj that looks more useful to take the last bar and not the current. thks

To add comments, please log in or register