Try move it to start .. not oninit ...
deysmacro:
Try move it to start .. not oninit ...
I put it on OnInit() is that i want to initialize the value to 1 which it will not allow the Slave EA to trade and after the Master EA begin trading, the value will be changed to 0 to be translated to the Slave EA to start trading.
Try move it to start .. not oninit ...
void CPanelDialog::OnClickBtn1(void) { int type; if(rd1.State()==false && rd2.State()==false){} else { if(rd1.State()==true){ type=OP_BUY; }else if(rd2.State()==true){ type=OP_SELL; } if(OpenOrder(type,StringToDouble(edit2.Text()))) { if(GlobalVariableGet("TradeAllowed")==1) { GlobalVariableSet("TradeAllowed",0); } } } }
GlobalVariableCheck = check if TradeAllowed existed or not without checking its value.
GlobalVariableGet = check if the TradeAllowed value matched or not or whatever value we want is there.
deysmacro:
Thanks i got that one but my main problem is that i want to initialize the value of "TradeAllowed" to 1 thats why i used this code.GlobalVariableCheck = check if TradeAllowed existed or not without checking its value.
GlobalVariableGet = check if the TradeAllowed value matched or not or whatever value we want is there.
int OnInit() { //check if GlobalVariable is present if(!GlobalVariableCheck("TradeAllowed"))//check if the GlobalVariable "TradeAllowed" is present. { GlobalVariableSet("TradeAllowed",1);//if not present, create the GlobalVariable "TradeAllowed" with a value of 1. } else { GlobalVariableSet("TradeAllowed",1);//if present, set the GlobalVariable "TradeAllowed" value with 1. } }but the thing is, after the EA has been initialized, the value of the GlobalVariable "TradeAllowed" is always 0, sometimes it will have a value of 1 but after i put the Slave EA it will change its value to 0 to which the Slave EA has no code to change the value of the GlobalVariable "TradeAllowed".
Last try ...
int OnInit() { //check if GlobalVariable is present if(GlobalVariableGet("TradeAllowed")!=1)GlobalVariableSet("TradeAllowed",1); GlobalVariablesFlush(); }
By the way, what you put on deinit() ?
deysmacro:
Thanks but it is still not working.
Last try ...
Use Print() after each function to see which one is the culprit.
deysmacro:
Use Print() after each function to see which one is the culprit.
I use that one for debugging but i dont see any errors. It always return the value 0.
Use Print() after each function to see which one is the culprit.
if(OpenOrder(type,StringToDouble(edit2.Text()))) { if(GlobalVariableCheck("TradeAllowed")) { GlobalVariableSet("TradeAllowed",0); } }
That code snippet must be always true which leads to
GlobalVariableSet("TradeAllowed",0);
It may not be relevant in your case, but if you use strategy tester to test any EA that uses GV's, you MUST make sure that it doesn't change any GV's value that might be accessed by an EA on a live chart.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi guys,
I would like to ask if i had a proper coding when dealing with GlobalVariables.
I have this code so that the other EA's(slave) will not trade not until one EA(master) have made the first move(or the first trade) which has this code.
The problem is that, everytime i load the EA or start the EA, the GlobalVariable "TradeAllowed" always have a value of 0 instead of 1 which i declared above.
Can anyone help me with this problem.
Thanks.