Download MetaTrader 5

Searching for answers!!

To add comments, please log in or register
Improve your rating. Execute orders in Freelance service!
liquidd
172
liquidd 2014.01.06 20:54 

Hello there!

First off thank you for taking the time to look at this post.

I have an EA I worked weeks on here and I'm trying to figure out why it is not working

First off it is working just good and exactly as I would expect it to on a thinkforex demo account.

now since I'm not a millionaire yet I can not afford to have this kind of big account in live so I started an alpari nz nano to run my ea from.

surprise surprise!! the ea takes the first trade never trade again. ...

anyone already encountered such problem?

Ubzen
5394
Ubzen 2014.01.06 21:02  
liquidd:

Hello there!

First off thank you for taking the time to look at this post.

I have an EA I worked weeks on here and I'm trying to figure out why it is not working

First off it is working just good and exactly as I would expect it to on a thinkforex demo account.

now since I'm not a millionaire yet I can not afford to have this kind of big account in live so I started an alpari nz nano to run my ea from.

surprise surprise!! the ea takes the first trade never trade again. ...

anyone already encountered such problem?

Without seeing the codes, we'll have to play the guessing game. I'm not asking you to post your hard-earned codes on the forum. But we're blind.

Your best solution is doing some de-bugging and trying to figure out where the program stops within your codes. This is achieved through the use of Print().

Example here: https://www.mql5.com/en/forum/148456 .

liquidd
172
liquidd 2014.01.06 21:27  
ubzen:

Without seeing the codes, we'll have to play the guessing game. I'm not asking you to post your hard-earned codes on the forum. But we're blind.

Your best solution is doing some de-bugging and trying to figure out where the program stops within your codes. This is achieved through the use of Print().

Example here: https://www.mql5.com/en/forum/148456 .


I was gona say there's something about the order close section but I found something that could go possibly wrong... (actually was about to post it look)

could the ++ be wrong since I usually use -- for order close loops... maybe that is my error in there and I have only one ea running on the test account...

            for (int w =0;w<OrdersTotal();w++)
               {      
                  OrderSelect(w, SELECT_BY_POS, MODE_TRADES);
                     {
                        while (close == 0)
                           {
                              com = StringConcatenate(ea, " Version: ",version," ",hours,":",minutes);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_SELL) close = OrderClose(OrderTicket(), OrderLots(), Ask, 30, Red);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_BUY) close = OrderClose(OrderTicket(), OrderLots(), Bid, 30, Red);
                           }
                     }
               }
Ubzen
5394
Ubzen 2014.01.06 21:36  
liquidd: I was gona say there's something about the order close section but I found something that could go possibly wrong... (actually was about to post it look) could the ++ be wrong since I usually use -- for order close loops... maybe that is my error in there and I have only one ea running on the test account...

I taught you had problems placing orders... Did it already close the first order it placed? If not... perhaps you have something like if( OrdersTotal() > 0 ){ OrderSend(); } and because the old order is still open its not letting you place additional orders. However... if you're having problems closing the order opened. Then check the following.


            for (int w =0;w<OrdersTotal();w++) //Always count down when closing orders.... for( int w=OrdersTotal()-1; i>=0; i-- )
               {      
                  OrderSelect(w, SELECT_BY_POS, MODE_TRADES); //Always check if the OrderSelect() Worked. Example Below:
                                                              // if( OrderSelect(...........)   ){
                     {
                        while (close == 0)
                           {
                              com = StringConcatenate(ea, " Version: ",version," ",hours,":",minutes);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_SELL) close = OrderClose(OrderTicket(), OrderLots(), Ask, 30, Red);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_BUY) close = OrderClose(OrderTicket(), OrderLots(), Bid, 30, Red);
                           }
                     }
               }
Ubzen
5394
Ubzen 2014.01.06 21:46  

Also De-Bugging is a good skill to have ... at some point you'll out grow the forum and have to find your own errors.

            for (int w =0;w<OrdersTotal();w++)
               {Print("For Passed..........");
                  if(OrderSelect(w, SELECT_BY_POS, MODE_TRADES))
                     {Print("OrderSelect Passed..........");
                        while (close == 0) //Note: using while like this can cause an endless loop ... should OrderClose keep failing.
                           {Print("While Passed..........");
                              com = StringConcatenate(ea, " Version: ",version," ",hours,":",minutes);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_SELL) close = OrderClose(OrderTicket(), OrderLots(), Ask, 30, Red);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_BUY) close = OrderClose(OrderTicket(), OrderLots(), Bid, 30, Red);
                           }
                     }
               }

So for example if you get as far as the While Passed but the order failed to Close. Then perhaps the OrderMagicNumber does-not equal Magic. Maybe you forgot to set the Magic# within the OrderSend() for example.

You can always use something like Print( "OrderMagicNumber=", OrderMagicNumber() ) to peak at the value of the magic number ... or what ever else.

liquidd
172
liquidd 2014.01.06 22:02  
ubzen:

Also De-Bugging is a good skill to have ... at some point you'll out grow the forum and have to find your own errors.

So for example if you get as far as the While Passed but the order failed to Close. Then perhaps the OrderMagicNumber does-not equal Magic. Maybe you forgot to set the Magic# within the OrderSend() for example.

You can always use something like Print( "OrderMagicNumber=", OrderMagicNumber() ) to peak at the value of the magic number ... or what ever else.


in that case, the ea wouyld never have worked tough. now it works only on one broker out of two...
Ubzen
5394
Ubzen 2014.01.06 22:19  
liquidd: in that case, the ea wouyld never have worked tough. now it works only on one broker out of two...
Return to Demo. Perform the Print() for all your conditions because I cannot tell which one is likely not-processing. It tedious but must be done unless you want to post your entire code. Then we can go from there.
Keith Watford
Moderator
9624
Keith Watford 2014.01.07 00:37  
for (int w =0;w<OrdersTotal();w++)
               {      
                  OrderSelect(w, SELECT_BY_POS, MODE_TRADES);
                     {
                        while (close == 0)
                           {
                              com = StringConcatenate(ea, " Version: ",version," ",hours,":",minutes);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_SELL) close = OrderClose(OrderTicket(), OrderLots(), Ask, 30, Red);
                              if (OrderMagicNumber() == Magic && OrderType() == OP_BUY) close = OrderClose(OrderTicket(), OrderLots(), Bid, 30, Red);
                           }
                     }
               }

I assume that close is declared locally, somewhere before this piece of code.

I don't think that you need the while loop. Once the first order is selected, if the conditions in the while loop are not satisfied by that trade's status, the the program will be stuck in an endless loop, because close will not be assigned a new value.

Keith Watford
Moderator
9624
Keith Watford 2014.01.07 00:49  
  for (int w =OrdersTotal()-1;w>=0;w--)
    {      
    OrderSelect(w, SELECT_BY_POS, MODE_TRADES);
    com = StringConcatenate(ea, " Version: ",version," ",hours,":",minutes);
    if (OrderMagicNumber() == Magic && OrderType() == OP_SELL) 
      close = OrderClose(OrderTicket(), OrderLots(), Ask, 30, Red);
    if (OrderMagicNumber() == Magic && OrderType() == OP_BUY) 
      close = OrderClose(OrderTicket(), OrderLots(), Bid, 30, Red);
    if (close > 0 )
      break;
    }

Maybe make some amendments similar to this?

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.07 09:42  
liquidd:


I was gona say there's something about the order close section but I found something that could go possibly wrong... (actually was about to post it look)

could the ++ be wrong since I usually use -- for order close loops... maybe that is my error in there and I have only one ea running on the test account...

Read this: Loops and Closing or Deleting Orders
To add comments, please log in or register