why don't go on for trade

 

hi,

i wrote an EA. when test, it just do few trade but don't go on. please anyone have a look at it and let me know the mistake?

thanks.

Files:
1-13-1.mq4  6 kb
 
heyigeng:

hi,

i wrote an EA. when test, it just do few trade but don't go on. please anyone have a look at it and let me know the mistake?

thanks.

I think I've read your code somewhere.

The OrderSelect() is badly coded, no GetLastError() for OrderSend() (see example here MetaEditor > Navigator Window (Ctrl + D) > Files tab > Script folder > trade.mq4).

You can write that OrderSend() as User-Defined-Function if you lazy enough writing GetLastError().

I think I'm gonna need that coffee better than WHRoeder https://www.mql5.com/en/forum/139579

 
thank you guy. i will try. have a nice day.
 

Here's example for OrderSelect()

for(i = OrdersTotal() - 1;i >= 0; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)== true &&
      OrderType()==OP_BUY && mafast0>buyopenma)
      {
   
      }
   }
 
the problem is not send order but don't send order again after the first time of buy and sell.
 
it is so strange thing that i never meet since i began to stand mql4. seems the EA go away from the market for sleep.
 
heyigeng:
the problem is not send order but don't send order again after the first time of buy and sell.

You don't set . . .

alreadybuy=false;


alreadysell=false;

in your StopLoss() function, only in your TakeProfit() function, so if your first 2 trades both are closed at SL they will be the only trades your EA takes . . . this is a really bad way of doing what you are trying to do.

Why don't you simply check if there is an open Buy Order before you try to place a new one ? and the same for a Sell ?

In your TakeProfit() function you don't check if your OrderClose has worked . . . if it fails you still go ahead and set alreadybuy=false; then you go and place another Buy Order . . .

Read this: What are Function return values ? How do I use them ?

 

Your OrderSelect need to be re-written see example here https://www.mql5.com/en/forum/139543

I have question though, did the first opened position get closed ?

and print everything like this one https://www.mql5.com/en/forum/139595

 
thank you all. i got the answer. it is really refers to "false". i have to learn mql4 more as new. all of you are so nice man.
 
heyigeng:
thank you all. i got the answer. it is really refers to "false". i have to learn mql4 more as new. all of you are so nice man.
Excellent ! :)
Reason: