Print Insuffient Funds

 

Good Morning Everyone,

Thank you for the help. An abundant amount of knowledge here.

Here is a script I have been scracthing my head on. A check for insufficient funds prior to opening

any position.

3 Errors, 0 Warnings

'total' variable not defined (14,7)

'total' variable not defined (15,12)

'lots' variable not defined (19,44)

This script is only a partial copy of the EA 'MACD SAMPLE '

#property link "https://www.metaquotes.net/"

//+------------------------------------------------------------------+
//| Check for Suffient Funds |
//+------------------------------------------------------------------+
double start()

{
total=OrdersTotal(); <-----------------------Line 14, Col 7
if(total<1) <-----------------------Line 15, Col 12

{
//no open orders identified
if(AccountFreeMargin()<(1000*lots)) <----------Line 19, Col 44
{
Print("Insuffient Funds. Free Margin =", AccountFreeMargin());
return(0);
}
}

}

//+------------------------------------------------------------------+
// Check for long position (BUY) possibility
//-------------------------------------------------------------------+

Thank you in Advance,

Huckleberry

 

declare the variable


bold

#property link "https://www.metaquotes.net/"

extern double lots = 0.1;

//+------------------------------------------------------------------+
//| Check for Suffient Funds |
//+------------------------------------------------------------------+
double start()

{

int total = 0;
total=OrdersTotal(); <-----------------------Line 14, Col 7
if(total<1) <-----------------------Line 15, Col 12
.......... ..................

 
Huckleberry:

Good Morning Everyone,

Thank you for the help. An abundant amount of knowledge here.

Here is a script I have been scracthing my head on. A check for suffient funds prior to opening

any position.

3 Errors, 0 Warnings

'total' variable not defined (14,7)

'total' variable not defined (15,12)

'lots' variable not defined (19,44)

This script is only a partial copy of the EA 'MACD SAMPLE '

#property link "https://www.metaquotes.net/"

//+------------------------------------------------------------------+
//| Check for Suffient Funds |
//+------------------------------------------------------------------+
double start()

{
total=OrdersTotal(); <-----------------------Line 14, Col 7
if(total<1) <-----------------------Line 15, Col 12

{
//no open orders identified
if(AccountFreeMargin()<(1000*lots)) <----------Line 19, Col 44
{
Print("Insuffient Funds. Free Margin =", AccountFreeMargin());
return(0);
}
}

}

//+------------------------------------------------------------------+
// Check for long position (BUY) possibility
//-------------------------------------------------------------------+

Thank you in Advance,

Huckleberry

You need to tell the platform what sort of variable you want to use, before you use it.

So you will need to include the following lines either before the start() function or within it, but before the variables are referenced. The former technique allows the same variables to be referenced in other functions too.

int total;

int lots;

You're putting the returned value from the OrdersTotal() function call into the total variable; the next thing you will need to do is to get a value into the lots variable. Only you will know what you wish to put in there.

Another minor problem is that you've spelt "insufficient" incorrectly.

Lastly, why are you declaring the start() function to return a double precision value, but then you're actually just returning a whole integer?


You mentioned it was just a portion of the sample code. Please tell me you're not trying to compile a section of the original code on its own! :-)


CB

 
cloudbreaker wrote >>

You need to tell the platform what sort of variable you want to use, before you use it.

So you will need to include the following lines either before the start() function or within it, but before the variables are referenced. The former technique allows the same variables to be referenced in other functions too.

int total;

int lots;

You're putting the returned value from the OrdersTotal() function call into the total variable; the next thing you will need to do is to get a value into the lots variable. Only you will know what you wish to put in there.

Another minor problem is that you've spelt "insufficient" incorrectly.

Lastly, why are you declaring the start() function to return a double precision value, but then you're actually just returning a whole integer?

You mentioned it was just a portion of the sample code. Please tell me you're not trying to compile a section of the original code on its own! :-)

CB

Hi CB and jmnendrix1983,

Thank you for the correction on the spelling.

The third error ('Lots') was corrected by spelling it with all lower case.

As far as taking a portion of an existing compiled (.ex4) file, yes. I copied the whole file and saved it, before I tampered with it. The file is MACD Sample. I hope that this is NOT a 'no no'. The samples are there for us to change around and then investigate what happens? What I have done was taken a small portion of an entire file, pasted it into a file that I created, put in different comments for how I deciphered the authors points of interest.

What I have learned or have been confused about with this exercise, is understanding declarations a bit better. These declarations should be placed prior to --- int start. The declarations are explainations what the variables will do within the program. Then, what variable that had been declared, is then used after the --- int start. Looking into the MACD Sample, I found the --- int total --- on Line 21, Col 27. I statred the coping of this file up to the first --- { ---, then cut off everything afterwards until, --- double start. Therefore, the additional advise you and jmhendrix1983 had provided, (int total) was missing.

Thank you. The jargon, placement of jargon, and syntax is clearing up in my head. Not completely. Better.

So much more to learn. Thanks again. It works now.

Regards

Huckleberry

 
Huckleberry:

Hi CB and jmnendrix1983,

Thank you for the correction on the spelling.

The third error ('Lots') was corrected by spelling it with all lower case.

As far as taking a portion of an existing compiled (.ex4) file, yes. I copied the whole file and saved it, before I tampered with it. The file is MACD Sample. I hope that this is NOT a 'no no'. The samples are there for us to change around and then investigate what happens? What I have done was taken a small portion of an entire file, pasted it into a file that I created, put in different comments for how I deciphered the authors points of interest.

What I have learned or have been confused about with this exercise, is understanding declarations a bit better. These declarations should be placed prior to --- int start. The declarations are explainations what the variables will do within the program. Then, what variable that had been declared, is then used after the --- int start. Looking into the MACD Sample, I found the --- int total --- on Line 21, Col 27. I statred the coping of this file up to the first --- { ---, then cut off everything afterwards until, --- double start. Therefore, the additional advise you and jmhendrix1983 had provided, (int total) was missing.

Thank you. The jargon, placement of jargon, and syntax is clearing up in my head. Not completely. Better.

So much more to learn. Thanks again. It works now.

Regards

Huckleberry

You can also declare variables inside a function block just before you use them. In that case they will only be relevant to that particular function.


CB