Download MetaTrader 5
To add comments, please log in or register
Post web links to paid signals. Receive the partner's share!
paddythehotmail
20
paddythehotmail 2015.07.14 19:20 

Hi Guys, 

 

I'm stumped on some code...can you help? 

 

I've got two functions in an include file (GetA and GetB). I want to use these two functions to populate two arrays that will later be used in two custom indicator buffers.

But for some reason, I can only get one array to populate. Please see my MWE below: 

 

Am I missing something about only being able to populate one custom indicator at a time within the special function start?  

int start()   {                       
   
   for(int i = 0; i <= 9;i++) {
      
      Var_a[i] = GetA(Lookback, T, R);  //Where GetA is a function in an include file
      Var_b[i] = GetB(Lookback, T, S);  //Where GetB is an identical function in the same include file
   
     
  
  Print("Var_a=",Var_a[i]);           //Interrogate the value of Var_a (successful)
  Print("Var_b=" , Var_b[i]);         //Interrogate the value of Var_b  (not successful) Why???
  
  Print("Var_a=",GetA(Lookback, T, R));  //Directly Interrogate the value of Var_a (successful)
  Print("Var_b=",GetB(Lookback, T, S)); //Directly Interrogate the value of Var_b (successful)
      
    
}    
   return;
}
honest_knave
947
honest_knave 2015.07.14 20:19  
Please can you show the code where you declared/sized the arrays Var_a[] and Var_b[]
Keith Watford
Moderator
7869
Keith Watford 2015.07.14 20:23  

We don't know whether Var_b[] is an indicator buffer or an array

If it is an array, have you sized it? 

paddythehotmail
20
paddythehotmail 2015.07.15 17:02  

Hi guys, 

 

Thanks for chipping in. I have defined Var_a and Var_b globally at the beginning of my code. Apologies, I should have included it. 

So I define the the variables globally as an array (without sizing them), then look to use those arrays as a buffer for my custom indicator.  

 

#property indicator_separate_window
#property indicator_buffers 5

#define NEGATIVE_VALUE -1
#define THRESHOLD 0

#include <Functions.mqh>

extern   int      Lookback       =  5;


int file_handle;
int file_result;

double Var_a[];
double Var_b[];
 

 

SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Var_a);
SetIndexLabel(0,"Variable A");

SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Var_b);
SetIndexLabel(1,"Variable B");
paddythehotmail
20
paddythehotmail 2015.07.15 17:07  
GumRai:

We don't know whether Var_b[] is an indicator buffer or an array

If it is an array, have you sized it? 

Forgive my stupid question GumRai, can it be both? My understanding is that I have defined Var_b[] as an array. I then call on this array to populate my indicator buffer

Thank you kindly for your help, I am truly stumped on this one.  

paddythehotmail
20
paddythehotmail 2015.07.15 18:25  

Ah, gents I've solved it. 

 

My problem was that I was actually using 5 buffers, and I had Var_b[] being called using the 5th buffer. So there was a few blank buffers before Vab_b[]. Changing the buffer to the next available free one has worked.

Can I thank you both for taking the time to help, I thought that I had tried this solution before but obviously I'd done something incorrectly. 

 

Thanks again for your time.

Paddy.  

/
To add comments, please log in or register