Problems calling variables from functions

 

I'm builing an ea I can use over and over to make new ea from a standard format.

When I was recently inputting a holiday safety feature for interbankfx i created long ago, I decided to experiment a little with using functions.

Now, no matter what i do when i try to call two variables, (DayOff, and DayOffClose), from two functions i made, my opening logics compiles out, "variable not defined".

This leads me to believe it isn't returning the order integer in the closing logics either.

What am i doing wrong?

 

//+------------------------------------------------------------------+

//| Entry logics |

//+------------------------------------------------------------------+

{

HolidayAbandonTest();

HolidayTest();

}

if ((UseDayOff) && DayOff == False && DayOffClose == False)

//put in your entry logics between theese brackets

{

}

The variables DayOff and DayOffClose are not defined in the start function.

int goodfriday(gmonth, gday)

{

double cycledays = 29.5306;//approxamation of how long it takes the moon to return to a full moon

int month = 11;//last full moon was november 2006

You are going to need types for gmonth and gday (e.g. int).

 
Craig:
//+------------------------------------------------------------------+

//| Entry logics |

//+------------------------------------------------------------------+

{

HolidayAbandonTest();

HolidayTest();

}

if ((UseDayOff) && DayOff == False && DayOffClose == False)

//put in your entry logics between theese brackets

{

}

The variables DayOff and DayOffClose are not defined in the start function.

int goodfriday(gmonth, gday)

{

double cycledays = 29.5306;//approxamation of how long it takes the moon to return to a full moon

int month = 11;//last full moon was november 2006

You are going to need types for gmonth and gday (e.g. int).

that just gives me more errors

Compiling 'Starter EA.mq4'...

'DayOff' - variable not defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (159, 26)

'DayOffClose' - variable not defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (159, 45)

'gmonth' - variable already defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (327, 11)

'gday' - variable already defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (328, 11)

'gmonth' - variable not defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (400, 16)

'gday' - variable not defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (400, 24)

'gmonth' - variable not defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (419, 22)

'gday' - variable not defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (419, 42)

'gday' - variable not defined C:\Documents and Settings\Tricia\Desktop\Currency Study\John's Metatrader 4\experts\Starter EA.mq4 (419, 63)

9 error(s), 0 warning(s)

Files:
starter_ea.mq4  18 kb
 

Variable not defined means the variable is not defined at global or function level (as per my first reply) Variable already defined means you have defined the variable twice.

e.g.

int goodfriday(int gmonth, int gday)

{

double cycledays = 29.5306;//approxamation of how long it takes the moon to return to a full moon

int month = 11;//last full moon was november 2006

double day = 5;//last full moon was november 5, 2006

bool FullMoon = False;//self-explanatory

int gmonth = 0;//month good friday occurs in

int gday = 0;//da

With all due repect, you really need to go and get a better idea of how variables and functions work (e.g. http://docs.mql4.com/basis/variables & http://docs.mql4.com/basis/functions) because if you can't work out what is going on with these basic errors you don't stand a chance of working out more complex logical errors. Reading a book on the C programming languge won't hurt either (http://www.imada.sdu.dk/~svalle/courses/dm14-2005/mirror/c/)

 

Fixed compile errors

Fixed the compile errors, didn't have time to check the logic.

Files:
 
tururo:
Fixed the compile errors, didn't have time to check the logic.

thank you tururo, i can deal with the logics now that i know what was wrong with the errors.

 
Craig:
Variable not defined means the variable is not defined at global or function level (as per my first reply) Variable already defined means you have defined the variable twice.

e.g.

int goodfriday(int gmonth, int gday)

{

double cycledays = 29.5306;//approxamation of how long it takes the moon to return to a full moon

int month = 11;//last full moon was november 2006

double day = 5;//last full moon was november 5, 2006

bool FullMoon = False;//self-explanatory

int gmonth = 0;//month good friday occurs in

int gday = 0;//da

With all due repect, you really need to go and get a better idea of how variables and functions work (e.g. http://docs.mql4.com/basis/variables & http://docs.mql4.com/basis/functions) because if you can't work out what is going on with these basic errors you don't stand a chance of working out more complex logical errors. Reading a book on the C programming languge won't hurt either (http://www.imada.sdu.dk/~svalle/courses/dm14-2005/mirror/c/)

With all do respect, that is exactly what i have done, i can tell you haven't payed attention to the small change in the code you suggested. i had already tried to do that several times before. I have a larger understanding of what i'm doing than you give me credit. and i research what i do, i've looked at both of those before, and i have skimmed through several c+ books. refrence alone can not gain skill in a single area of coding, or in coding as a whole, no refrence i have observed has givin an example of EVERY possible use for a tool mentioned, to do so would take extra time, and make their books and refrences much longer. if i am troubled by some errors with a compiler, i generally experiment obvious answers to solve them, i'm not someone who posts questions on this forem simply for every problem i am confronted with.

 

Thought you might say somthing like that, your code changes suggested you do not know what you are doing, all I am suggesting is you might benefit from learning some more programming fundimentals, I forward this as a helpful suggestion from somebody who has been down the same road, not as a put-down.

You are correct in that good programming skills come from practical experence, but you really need to understand (for example) how to declare a function properly before you start coding and you also need to understand the concept of variable scoping, this is gone over in the MQL documentation I have referenced, which you have so obvously NOT read.

I could have also fixed your errors for you, but what good does that do? you still have no idea why it was broken!! If you can't take some gentle proding in the direction of the facts, your not going to get very far...in fact why am I bothering even writing this because your only going to ignore it anyway...or tell me I'm full of shit...losing interest zzzzzzzzzz

 
Craig:
Thought you might say somthing like that, your code changes suggested you do not know what you are doing, all I am suggesting is you might benefit from learning some more programming fundimentals, I forward this as a helpful suggestion from somebody who has been down the same road, not as a put-down.

You are correct in that good programming skills come from practical experence, but you really need to understand (for example) how to declare a function properly before you start coding and you also need to understand the concept of variable scoping, this is gone over in the MQL documentation I have referenced, which you have so obvously NOT read.

I could have also fixed your errors for you, but what good does that do? you still have no idea why it was broken!! If you can't take some gentle proding in the direction of the facts, your not going to get very far...in fact why am I bothering even writing this because your only going to ignore it anyway...or tell me I'm full of shit...losing interest zzzzzzzzzz

Wow... 5 post's and you are already being a jerk to someone like Eaglehawk? He's got 150+ posts here, and if you read more than 3 of them you would know how far out of line you are. Grow up.

 

Does the fact that he has posted here more than me mean that I have to avoid the truth? I have looked back though this posts, I'm not too sure what part of his posting is supposed to engender respect. He is trying to write EA's, fair enough, I just think he should have a better grasp of what he is doing from a coding point of view, this suggestion was made to help him, it's going to help him get where he wants to be is it not?

I offered help, he is the one that did his nut when I suggested some research. I don't see what is immature on my part. Quite the opposite in fact.

 

Before this turns into whatever...let's face the facts.

A. This changes and inability to debug them show he does not understand some basics of programming.

B. Understanding these basics would help.

C. Programming skill is not related to posting density.

These facts are independant of any of our opinions, if I came across as rude, I apologize. Dat's all I got to say!

Reason: