Indicator Bars in EA OnTick()

To add comments, please log in or register
Charles Stangor
216
Charles Stangor  

Am I doing this right at all?

I have an indicator (it's BrainTrend2Sig from the codebase).

It outputs a buyarray[] and a sellarray[]

In my EA I first link to that indicator

  indicator_handle=iCustom(NULL, PERIOD_CURRENT,"BrainTrend2Sig");

Then in OnTick() I call for  the arrays.

   double  buys[], sells[];

   int buy_ = CopyBuffer(indicator_handle,0,0,num_bars,buys);

   int sell_ = CopyBuffer(indicator_handle,1,0,num_bars,sells);

How do I get the right value for num_bars to assure that the called indicators always line up with the correct bars in the series?  

The problem is that the indicators don't come with dates.

Or perhaps there is an entirely different way?

Thanks.


Alain Verleyen
39036
Alain Verleyen  
Charles Stangor:

Am I doing this right at all?


How do I get the right value for num_bars to assure that the called indicators always line up with the correct bars in the series?  

The problem is that the indicators don't come with dates.

Or perhaps there is an entirely different way?

Thanks.


Your code is correct. You have to check the buy_ and _sell variable to be sure the copy was done without error. Then you can use your buys[] and sells[] array.

If you want access these arrays as series, you need to use ArraySetAsSeries(). Then they will line up, no need for dates.
Charles Stangor
216
Charles Stangor  
Alain Verleyen:
Your code is correct. You have to check the buy_ and _sell variable to be sure the copy was done without error. Then you can use your buys[] and sells[] array.

If you want access these arrays as series, you need to use ArraySetAsSeries(). Then they will line up, no need for dates.
Thank you Alain.  ArraySetAsSeries() seems perfect.  So many useful functions in mql5 :)
To add comments, please log in or register