Orders don't get listed

To add comments, please log in or register
Ali
18
Ali  

Hi,

I'm new to MQL4 and do have a problem with the execution of an Expert Advisor.

While the Expert is running I'm getting the alerts I assigned to the OrderSends, but the orders don't show up in the Trading window in FxPro, which means the Expert doesn't do anything at all.

Thanks in advance.

Here is the code:


//--------------------------------------------------------------------
int Count=0;                                   // Global variable
double BS=0; Alert ("Erster BUY: ", BS);                                    // Set First Buy/Sell
//--------------------------------------------------------------------
int init()                                      // Spec. funct. init()
   {
   Alert ("Function init() triggered at start");// Alert
   return;                                      // Exit init()
   }   
//--------------------------------------------------------------------
int start()                                                                      
   {
   double Price = Bid;                                                           
   Count++;                                                                      
   Alert("New tick ",Count,"   Price = ",Price);                                 
   double Unterschied = Price - BS;
   
   Alert ("Unterschied vor vergleich: ",Unterschied);
   
   if (Unterschied < 0)                                                           
      {Unterschied = Unterschied * (-1);}
      
   Alert("Unterschied nach vergleich: ",Unterschied);   
      
   if (Unterschied > 30*Point)
      {OrderSend(Symbol(),OP_BUY,0.1,Bid,3,Bid-15*Point,Bid+15*Point);         
       
       double Kauf = Bid;
       double Stopkauf = Bid-15*Point;
       double Takekauf = Bid+15*Point; 
       Alert("Buy at: ",Kauf," ::: Stop Loss: ",Stopkauf," ::: Take Profit: ",Takekauf);
         
       BS = Bid;
       Alert("Neuer BS: ",BS);
                                                                       
       OrderSend(Symbol(),OP_SELL,0.1,Ask,3,Ask+15*Point,Ask-15*Point);

       double Verkauf = Ask;
       double Stopverkauf = Bid+15*Point;
       double Takeverkauf = Bid-15*Point; 
       Alert("Sell at: ",Kauf," ::: Stop Loss: ",Stopkauf," ::: Take Profit: ",Takekauf);
       
       }         
   return;                                      // Exit start()
   }
//--------------------------------------------------------------------
int deinit()                                    // Spec. funct. deinit()
   {
   Alert ("Function deinit() triggered at deinitialization");   // Alert
   return;                                      // Exit deinit()
   }
//-------------------------------------------------------------------+
Ickyrus
886
Ickyrus  

Count++

I am assuming (which is always a bad idea) that Count is initilised to 0 before the program is called which is on every tick (new piece of chart data) so the variable Count will always be 1.

Use varable declaration just after function declaration otherwises you are likely to get "already defined varable errors.

Ali
18
Ali  

the counter is just fine. its defined as global before start() (so not defined as 0 every tick). and the alert message also is counting properly.

my problem is just that orders dont get listet in trades.

William Roeder
20808
William Roeder  
OrderSend(Symbol(),OP_BUY,0.1,Bid,3,Bid-15*Point,Bid+15*Point);      
  1. You open buys at the Ask and sells at the Bid.
  2. Test return codes and print errors so you know why
    if(!OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point)) 
       Alert("orderSend failed ",GetLastError());  

  3. On a 5 digit broker you must adjust tp, sl, and slippage. a sl of 1.5 pips won't work on most brokers. MarketInfo(Symbol(), MODE_STOPLEVEL)*Point is 30 (3.0 pips on IBFX)
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  4. On ECN brokers you must open the order without a tp/sl and then modify it.
Ickyrus
886
Ickyrus  
AlyxO:

the counter is just fine. its defined as global before start() (so not defined as 0 every tick). and the alert message also is counting properly.

my problem is just that orders dont get listet in trades.


Thanks - saves me testing it!

Ali
18
Ali  

@ WHRoeder


thanks, I changed the asks and bids. Added the print errors. but still nothing.

no errors are displayed and no trades either.

I did some manual trades so its not FxPro.

I even tried the most simple Adviser but still no trades although alerts are shown.


int start()
  {
//----
int Ticket = OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-20*Point,Bid+20*Point);
         if (Ticket < 0)                        // Success :)
           {
            Alert ("Opened order Buy ",Ticket);
            return;                             // Exit start()
           }
            
                  
//----
   return(0);
  }
zzuegg
1499
zzuegg  

Hi,

if ticket < 0 means there was an error. I assume you are on a 5 digits broker where Bid-20*Point is to close to the current market. It would be only 2Pips away from the current price. you should reread WHRoeder's post, and implement the 3/5 Digits adjustment.

Ali
18
Ali  

Okay, yes I'm using a 5 digits broker. now I added the adjustment to my code.

after running it I get the common error 4109 "Trade not allowed" which I tried to solve by allowing "live trades" in the EA options, but this error still shows up.

I read about the 4109 problem here and some say that it might be because of the too close tp's and sl's, but shouldn't this return the error 130?

William Roeder
20808
William Roeder  

AlyxO:

which I tried to solve by allowing "live trades" in the EA options, but this error still shows up.

And you have the Expert Advisors button depressed. And you have a smiley face on the chart (UR corner.)
Ali
18
Ali  

Thanks a bunch guys.

I dont know what caused the problem but after restarting my computer it was solved.

So now my orders are showing up in trades.

thanks again

To add comments, please log in or register