hello,
i bought Andrew Young book and start learning how to code in mql.
I'm try to figure out why i don't get any more trades.
for example : in buy orders the logic is simple
if(FastMA > SlowMA && Ask > LongMA && BuyTicket == 0)
FastMA =10
SlowMA=20
LongMA=240
the EA open trades only once when the Ask > LongMA and don't open more buy orders until i got a sell signal.
please see the code an the image.
any help will be appreciate, thanks.
Yes, you have BuyTicket==0 as a condition so it buys only if the buy ticket is equal to zero. How do you exactly get the value of BuyTicket and what happens if you cut that part out?
thanks pennyhunter i really appricate you trying to help.
when i cut the "BuyTicket " from here: if(FastMA > SlowMA && Ask > LongMA && BuyTicket == 0 ) the EA don't stop opening orders in every new tick.
i get the BuyTicket when the EA open a buy order, so if i have a buy order running, the EA will not open a new buy order.
but the problem is when the EA close the orderthen it should open a new order when condition are right , but for a reason that i don't understand yet it doesn't open new buy orders, the next trade will be a sell order.
thanks pennyhunter i really appricate you trying to help.
when i cut the "BuyTicket " from here: if(FastMA > SlowMA && Ask > LongMA && BuyTicket == 0 ) the EA don't stop opening orders in every new tick.
i get the BuyTicket when the EA open a buy order, so if i have a buy order running, the EA will not open a new buy order.
but the problem is when the EA close the orderthen it should open a new order when condition are right , but for a reason that i don't understand yet it doesn't open new buy orders, the next trade will be a sell order.
Probably because the BuyTicket with the number zero has been taken already. Take this instead:
if(PositionsTotal()==0)
Then the EA does one position at max.
If you want it to do one position buy and one sell you would need to write a custom boolean function that you can call which checks if there is a buy or sell position open.
https://www.mql5.com/de/docs/basis/function
https://www.mql5.com/de/docs/basis/function/call
https://www.mql5.com/de/docs/basis/function/parameterpass
https://www.mql5.com/de/docs/trading/positiongetinteger
https://www.mql5.com/de/docs/function_indices
Now try for yourself and come back if you have questions.

- www.mql5.com
thanks pennyhunter i really appricate you trying to help.
when i cut the "BuyTicket " from here: if(FastMA > SlowMA && Ask > LongMA && BuyTicket == 0 ) the EA don't stop opening orders in every new tick.
i get the BuyTicket when the EA open a buy order, so if i have a buy order running, the EA will not open a new buy order.
but the problem is when the EA close the orderthen it should open a new order when condition are right , but for a reason that i don't understand yet it doesn't open new buy orders, the next trade will be a sell order.
please post the code in the thread with the code button. I had quick look and looks simple enuf, but it is easier to read and help you if it formatted as compiler format.
your issue is that you need to add ability for the ea to recognise that the ma's crossed over, and then make the ea wait until the next crossover to open the next trade. I can do that, once you have posted the code properly, either by the code button, or as a mq4 file attachment.
EDIT: if you want the ea to open have more than 1 trade open, then your code to close trades will only work to close 1 trade. That is another thing that will not work in your code.
EDIT2: your question on the image... "why it only open < or > 240 ma? answer because you coded it that way. i have to assume that sell trades are only allowed to open when price is below the 240 ma.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello,
i bought Andrew Young book and start learning how to code in mql.
I'm try to figure out why i don't get any more trades.
for example : in buy orders the logic is simple
if(FastMA > SlowMA && Ask > LongMA && BuyTicket == 0)
FastMA =10
SlowMA=20
LongMA=240
the EA open trades only once when the Ask > LongMA and don't open more buy orders until i got a sell signal.
please see the code an the image.
any help will be appreciate, thanks.