Angat » Sat Jan 17, 2015 1:10 pm wrote:
Yes thanks, this is basically what I'm asking but for some unknown reason, I have global variables that cant be access within functions.
For example I have
Code: Select all
bool LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));
as a global variable.
Then in LookForTradingOpportunities() function I want to say
Code: Select all
If(LineDetectABZERO)
SendShort = true;
But apparently this doesn't work. But does work if I move "bool LineDetectABZERO..." to within LookForTradingOpportunities() .
It is not being detected properly because your asking it to find objects only at the start of the EA, when it is place on the chart, this happens only once. start() is run with each tick. Here is what you need to do....
this is the global
bool LineDetectABZERO;//this initialises the variable, you can make it equal to something, usually a default value like 0, or null. Using bid wont even work here because you have not seen a tick yet.
then near the top of start() you write
Code: Select all
LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));//this will be evaluated at every tick
the value of "LineDetectABZERO" it will be seen in your function.
You need to understand how an ea executes to fully get this....
this is how an EA starts off
drag onto chart
goes through all the variables outside of all the functions, the global variables and initialises them
then it runs init()
then it runs start() at the next tick (on saturday you wont get start() to run unless you have a tick generator)
it runs start and when it finds a function it will go there and then come back
when the ea is removed it will run deinit()
Code: Select all
bool LineDetectABZERO = ((ObjectFind(0,"AlphaLine_0")==0) || (ObjectFind(0,"BetaLine_0")==0));
do you understand the functions "void" "bool", "double" etc?
what's the difference between the functions below (took me a while to get this concept when I started)
Code: Select all
bool myfunction(){
some code
}
void myfunction(){
some code
}