HELP, please try to help me.

 

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.

Files:
Untitled.png  28 kb
ea.txt  3 kb
 
avi:

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?
 
pennyhunter #:
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.

 
avi #:

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.

Dokumentation zu MQL5: Grundlagen der Sprache / Funktionen
Dokumentation zu MQL5: Grundlagen der Sprache / Funktionen
  • www.mql5.com
Funktionen - Grundlagen der Sprache - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5
 
Yardım edecek biri yok mu
 
kccknn #:
Yardım edecek biri yok mu
You mean is there nobody who does the hard work for me?
 
avi #:

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.

Is simple … example buycondition is true… first you close sell order…after that you open buy order… and your order will close when sell condition is true… you have same conditions for closing a trade and opening in opposite direction… you can cut some of the conditions. For closing the trades… for example… Buy open when FastMA > SlowMA && close > FastMA ( candle close above fast MA)… and close buy order only if close < FastMA… and do opposite for Sell condition … 
 
Oh... I entered this thread through the frint page and didn't realise this is MQL4, sorry.
 
avi:


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.