Download MetaTrader 5

Need Help Debugging Code - Problem with Passing Values into Function.

To add comments, please log in or register
Jason
26
Jason  

Hello people,

I'm 16 and fairly new to programming. Have had a go at writing my first EA and I'm getting an error to do with passing values to functions. What I am trying to do is pass the boolean variables returned by my two long and short trade-scan functions into my trade execution function, but something along the way isn't working. Any help would be much appreciated.

Files:
Simon Gniadkowski
Moderator
18035
Simon Gniadkowski  
Doomanx:

Hello people,

I'm 16 and fairly new to programming. Have had a go at writing my first EA and I'm getting an error to do with passing values to functions. What I am trying to do is pass the boolean variables returned by my two long and short trade-scan functions into my trade execution function, but something along the way isn't working. Any help would be much appreciated.

You need to declared these variables stating what type of variable they are, are they int, double, string, datetime ?

int tradeExec(  longArbBool,   shortArbBool  )

You haven't defined this function that you are calling . . .

bool longArbBool =  longArbBool()  ;

nor this one . . .

bool shortArbBool =    shortArbBool()   ;


You might want to keep your function names and variable names unique, it makes reading code easier and less prone to mistakes.

Jason
26
Jason  

Aha I see that basic error with the function names now. I have changed it to:

int start()
{
bool longArbBool = longArbScan();
bool shortArbBool = shortArbScan();

   dataChecks();
   tradeExec(longArbBool, shortArbBool);
   orderCycle();
}

I am still getting "parameter definition expected" error, however.

Simon Gniadkowski
Moderator
18035
Simon Gniadkowski  
Doomanx:

Aha I see that basic error with the function names now. I have changed it to:

I am still getting "parameter definition expected" error, however.

As I already said . . . .
RaptorUK:

You need to declared these variables stating what type of variable they are, are they int, double, string, datetime ?

int tradeExec(  longArbBool,   shortArbBool  )

Jason
26
Jason  

Are they not being declared here?

bool longArbBool = longArbScan();
bool shortArbBool = shortArbScan();

Apologies if I'm missing something very obvious and thank you for the help.

Simon Gniadkowski
Moderator
18035
Simon Gniadkowski  
Doomanx:

Are they not being declared here?

Apologies if I'm missing something very obvious and thank you for the help.

You declared them in start() they are local to start(), you declared then for your function as part of the function declaration, they are local to your function . . . but you didn't say what type they were.

You need to read up on local scope and global scope . . . and understand the scope of a locally declared variable.


Also, this is wrong, please read the documentation for OrderSelect() and OrderProfit()

if( OrderProfit( OrderSelect(last_trade-1,SELECT_BY_POS,MODE_HISTORY) ) > 0 )

OrderProfit(bool) ? ?

To add comments, please log in or register