MT5 EA using iCustom indicator

 

Hi.  I am no coder, but I try hard, so don't flame me, refer me to documentation or treat me with disrespect.  I'm stuck, I've spent weeks on this and I am asking for anyone who CAN program, to tell me where I'm wrong, please.  Thank you in advance.

Problem: I have a custom indicator called Trading the Trend.  It works fine and I can call the indicator in a script and use the data successfully.  Buffer 5 is the indicator value.

I am trying to write an EA which triggers at the new candle (this much works fine, and I thank Raimund Bauer for the coding) BUT I have applied both the inbuilt iMA function and the iCustom function in exactly the same way.  The comment line just shows me the output and I'll use the data later on.  The iMA output MA20 is fine and the indicator is drawn on the chart during testing.  It is correct and updates at each new candle.  The iCustom output TTT5 is garbage and doesn't update at all, and is not drawn on the chart.

If someone can explain to me how to get this iCustom indicator working correctly I would be eternally grateful.


// SIMPLE: https://www.youtube.com/watch?v=BGCQkf8GjIo

#include <GetIndicatorBuffers.mqh> 
#property tester_indicator "Trading the Trend.ex5" 
void OnTick()        
  {
MqlRates priceData[];                         //create a price array called priceData
ArraySetAsSeries(priceData,true);
CopyRates(_Symbol,_Period,0,3,priceData);    //copy candle price for three candles into the array
static datetime timeStampLastCheck;          //create Datetime variable for the last time stamp
datetime timeStampCurrentCandle;             //create Datetime variable for the current candle
timeStampCurrentCandle=priceData[0].time;    //read time stamp for the current candle in the array
double priceLastClose;                       //Create an array for the closing prices

priceLastClose=iClose(Symbol(),0,1);        //read the last close price.  0 means current period, 1 means previous candle

double TTT5[];
int TTT_handle=iCustom(_Symbol,_Period,0,"Trading the Trend.ex5",21,3,1,PRICE_CLOSE);  	//create the indicator...this line works in a script which tells me the values of buffer 5
CopyBuffer(TTT_handle,5,0,4,TTT5);							//extract buffer 5, the most recent four values
ArraySetAsSeries(TTT5,true);

double MA20[];
int MA_handle=iMA(_Symbol,_Period,20,0,MODE_EMA,PRICE_CLOSE);
CopyBuffer(MA_handle,0,0,4,MA20);
ArraySetAsSeries(MA20,true);            
            

if (timeStampCurrentCandle!=timeStampLastCheck) 	//if the current timestamp is different to the last time we checked, then update the comment.
   {
   timeStampLastCheck=timeStampCurrentCandle; 		//update the current timestamp for use next time
    

   
Comment (priceLastClose,"  ",TTT5[1],"   ",MA20[1]);			
   }
   

  }
 
int TTT_handle=iCustom(_Symbol,_Period,0,"Trading the Trend.ex5",21,3,1,PRICE_CLOSE);

You shouldn't create the indicator handle anew on every tick. This belongs into OnInit(). And what is this 0 supposed to do? You need to match the iCustom parameters precisely.

 

Hi Lippmaje 

Thank you for that advice.  That makes a lot of sense.  I appreciate your help.


Best regards

Mark


Addendum:  After Lippmaje's advice, my EA works.  Correct syntax was int TTT_handle=iCustom(_Symbol,_Period,"Trading the Trend.ex5",21,3,1,PRICE_CLOSE); 


Interestingly enough, in various scripts I use 

int TTT_handle=iCustom(_Symbol,_Period,0,"Trading the Trend.ex5",21,3,1,PRICE_CLOSE); 

int TTT_handle=iCustom(_Symbol,_Period,,"Trading the Trend.ex5",21,3,1,PRICE_CLOSE); 

int TTT_handle=iCustom(_Symbol,_Period,"Trading the Trend.ex5",21,3,1,PRICE_CLOSE);


Some work in the script but not the EA.  Odd, but beyond the understanding of this poor excuse for a coder.

Again I thank you for your help.  It made its first trade today and I made my first profit from it.