Download MetaTrader 5

Using Technical indicator in an EA

To add comments, please log in or register
Riyo Putra
399
Riyo Putra 2010.06.14 07:38 

Gents,

Could you help me how to solve  "handle" stuff in new MQL5.
I just want to compare MA period 20 days with MA period 12 days, do I need to create two handles for this indicator?  

Samuel Olowoyo
2244
Samuel Olowoyo 2010.06.15 11:51  
riyo:

Gents,

Could you help me how to solve  "handle" stuff in new MQL5.
I just want to compare MA period 20 days with MA period 12 days, do I need to create two handles for this indicator?  

Hi riyo,

I think you need to create two handles in other to do this. Follow this procedure:

1. Declare two integer data type variables for the handles

int mahandle1;

int mahandle2;

2. Use the MA indicator function (iMA) to get the handles and store them in variables  declared above

 mahandle1 = iMA(_Symbol,_Period,20,0,MODE_EMA,PRICE_CLOSE);

 mahandle2 = iMA(_Symbol,_Period,12,0,MODE_EMA,PRICE_CLOSE);

//--- What if handles return Invalid Handles
  if(mahandle1<0 || mahandle2<0)
{
  Alert("Error Creating Handles for ma indicators- ",GetLastError());
}
 

3. You can now use the handles to obtain the various values of the indicators for each bar on your chart using the CopyBuffer function

But first declare two dynamic arrays to hold the array values for the indicators and set the arrays as series using the Arraysetasseries function

double firstma[];  // for MA of period 20 

double secondma[]; // For MA of period 12

// set as series

ArraySetAsSeries(firstma,true); 

ArraySetAsSeries(secondma,true);  

// copy indicator buffers using the handles

if(CopyBuffer(mahandle1,0,0,3,firstma)<0  || CopyBuffer(mahandle2,0,0,3,secondma))  // we copied for bars 0,1,and 2
{
  Alert("Error copying Moving Average indicators buffer-",GetLastError());
   return;

}

// Now you can compare your indicator values depending on what you have in mind

if(firstma[1] > secondma[1])

{

// ma with period 20 is higher that ma with period 12 on bar 1

}

For more details, you may want to read this article if you have not already done so.  Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners 

Hope this helps 

Riyo Putra
399
Riyo Putra 2010.06.17 01:02  

Thank olowsam, your explanation is very clear.



Eric
153
Eric 2010.06.17 20:23  

Would it be the same for a custom indicator ?

I have a custom indicator and an EA. On demo mode i ask the EA to read the value in a label created and feed by the custom indicator  and i convert with StringtoDouble to use the info after in the EA.

But with this method, I can not backtest the EA unless there is a way to force the custom indic. to be present during the EA is running ... is it possible ?

 how can i read and objet propriety (value) during backtesting if the object has to be created by a custom indicator ?

 

Thank you for your help 

  

Samuel Olowoyo
2244
Samuel Olowoyo 2010.06.18 16:37  
Gachette:

Would it be the same for a custom indicator ?

I have a custom indicator and an EA. On demo mode i ask the EA to read the value in a label created and feed by the custom indicator  and i convert with StringtoDouble to use the info after in the EA.

But with this method, I can not backtest the EA unless there is a way to force the custom indic. to be present during the EA is running ... is it possible ?

 how can i read and objet propriety (value) during backtesting if the object has to be created by a custom indicator ?

 

Thank you for your help 

  

Hi Gachette,

If I understand your question,  "Would it be the same for a custom indicator ?"

I will say YES. The only difference is that you will have to use the icustom function instead of iMA function used above.

Let's say that the name of your custom indicator is sam indicator. Make sure it is in the indicator is located in the indicators standard folder. 

int sam_handle = iCustom(_Symbol,_Period,"sam indicator",indicator_input_parameters); 

Other steps are the same as earlier explained above.

Eric
153
Eric 2010.06.22 05:20  

hi,sorry i tried alot of things but cant have any succes !

maybe somebody can help me, i want to get the D and S value from the Rabbit indicator https://www.mql5.com/en/code/112

i want to be able to have access directly to the value. right now i do it live get the value of the 2 labels in the topcorner , but i would like to backtest my EA and i can not because i dont know how to get the value of D and S from the icustom direct in my EA

the EA itself does alot of thing, but without the Rabbit indicator present on the chart it could not start any trade...

thanks alot to the one that could help me but telling what i have to the to the indic and to my ea to be able to backtest my strategie  

ps; i dont want/dont need any array or buffer or timeseries or copyrate and whatever else..the only thing i want is the CURRENT value of s and d variable in rabbit indic. Thats it...  with the visual tester i could do it because before the ea start i will have time to put the custom indic on the ea before the backtesting strats so the objects i need to read values from will be present on chart. but there is surely a way to do it without any array or time series things???

objet are create during backtest? 

Rabbit
  • votes: 11
  • 2010.05.20
  • Jon Katana, VDV Soft | English Russian Spanish Portuguese
  • www.mql5.com
The Rabbit indicator plots the true support/resistance levels for any currency pair.
Simon Gniadkowski
Moderator
18002
Simon Gniadkowski 2014.01.07 14:19  
Comments that do not relate to this topic, have been moved to "Help with Indicator . . .".
To add comments, please log in or register