Hi,
I am pretty new to mql4. I've been doing ok but recently I have been completely stumped by a problem I have run into. I have coded a simple ea which works fine when I declare a local variable for "buyorder"
int buyorder=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,MagicNumber,0, Green);
if (buyorder>0)
OrderModify(buyorder,OrderOpenPrice(),bsl,btp,0,CLR_NONE);
but if I declare buyorder as a global variable (and take away the int) it does not work. It just keeps modifying orders infinitum. For the life of me, I cannot understand why this should happen as a global variable should be able to be used anywhere in the program and it's value should be able to change. I could stick with the local variable but I want to expand the ea to make multiple orders and to use trailing stops etc and I will need to use global variables. I've included the ea below. The first version(local variable) works, the second(global) doesn't. If anyone could help me, that would be so appreciated as I've literally spent days trying to work it out. PS This also applies to the variable "sellorder".
Thanks
I am pretty new to mql4. I've been doing ok but recently I have been completely stumped by a problem I have run into. I have coded a simple ea which works fine when I declare a local variable for "buyorder"
int buyorder=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,MagicNumber,0, Green);
if (buyorder>0)
OrderModify(buyorder,OrderOpenPrice(),bsl,btp,0,CLR_NONE);
but if I declare buyorder as a global variable (and take away the int) it does not work. It just keeps modifying orders infinitum. For the life of me, I cannot understand why this should happen as a global variable should be able to be used anywhere in the program and it's value should be able to change. I could stick with the local variable but I want to expand the ea to make multiple orders and to use trailing stops etc and I will need to use global variables. I've included the ea below. The first version(local variable) works, the second(global) doesn't. If anyone could help me, that would be so appreciated as I've literally spent days trying to work it out. PS This also applies to the variable "sellorder".
Thanks
Attached File(s)
Lesson14x.mq4
3 KB
|
434 downloads
Lesson14xx.mq4
3 KB
|
400 downloads