Can someone help me iCustom

alexlearnmql  

Hello can someone help me with my code for the icustom function. The the original indicator is just a 50,200 ema but I want to learn how to import my own custom indicator and for this the iMA function can not be used. I  am using the built in moving average EA for testing the code, I just want the ea to buy when ma1 goes above ma2 or sell when ma1 goes below ma2 to see if it works. Do I need to rebuild the whole array using buffers etc or is it as simple as ma1=icustom?

 //+------------------------------------------------------------------+
//|Global variables  |                                                |
//+------------------------------------------------------------------+
           
int ma1;
int ma2;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  ma1=iCustom(NULL,0,"myindicator",1,0);
  ma2=iCustom(NULL,0,"myindicator",2,0);
  return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
      //--- for debugging
      Print("ma1: ",ma1);
      Print("ma2: ",ma2);
            
      //--- check for history and trading
      if(Bars<100 || IsTradeAllowed()==false)
      return;
      //--- calculate open orders by current symbol
      if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();  
else                                          CheckForClose(); 
 }

 

When I print the values I get this in the journal which is wrong.

2016.09.12 19:44:39.186 2011.03.17 09:03  MyEA8 USDCAD,M30: ma1: -2147483648

2016.09.12 19:44:39.186 2011.03.17 09:03  MyEA8 USDCAD,M30: ma2: 0

Fernando Carreiro  

Trying to explain all that here will be very time consuming and require too much text!

Since, there are many, many examples of EAs in the Code Base that you can study in order to learn how to use iCustom() and in particular with moving averages, it will be easier and better for your learning, if you just search the Code Base for EAs that work similarly to what you want. You can then analyse them and experiment with them in order to learn and understand the functionality, which you can then apply to your own EA.

alexlearnmql  

Hello I got it working but I am having some problems simulating on strategy tester.

On simulation there is three settings // on every tick, control points and open bar.

My results are considerably different depending on which setting I select. Say if I wanted to test this EA on a 30 minute time frame when I select every tick it says using 1 minute data..on the window(I thought everytick would be most realistic but it does not seem to be) Then  when I select open bar then again I get wrong results, Control points I am not sure what data this is using.

I would just like to know what setting should I be using to simulate results of a 30 minute bar time frame as if it was in real time. 

Also when I open a different window with the indicator only while running the EA on a separate chart the two indicators look completely different??? Please help thank you. 

alexlearnmql  
Never mind I think I sussed it but advice regarding the the three settings still welcome.