Sporadic Pending Orders

 

Hi there

So I have an EA which places a Pending Order at the opening price of the current candle, and expires at the end of the current candle.

My code is below, I have even printed an error function in order to diagnose any errors that may occur, however, according to the EA, a pending order is placed so no error appears.

Sometimes a pending order is actually successfully executed, and other times, it tells me a pending order has been placed successfully, but no pending order appears on the chart.

There are no error messages.

Clearly there are no errors, so it must be something to do with my coding. What am I missing here? Why does it sometimes placed a pending order on the chart, and others times it decided not to?

In addition to this, I'm getting random entry prices in my trade ledger, despite clearly specifying the price with which I want my EA to execute a position. It seems to correct itself when I reinit the EA, but I really should not need to do this. 

Many thanks.

if(<Conditions are met>){

   int      pendingExpiration          = Period() * 60;
   double   candleOpenPrice            = iOpen(Symbol(),0,0);
   double   pendingOrderExecPrice      = NormalizeDouble(candleOpenPrice,Digits); 
   
   if(!OrderSend(Symbol(),OP_BUYSTOP,3,pendingOrderExecPrice,100,<sl>,<tp>,0,1,Time[0] + pendingExpiration,0)){
               
         RefreshRates();
         
            Print("Error on pending order "+IntegerToString(GetLastError(),0)); 
         
   }
         
   else {
            
	<confirmaion email function>
         
   }

}
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
I believe that your conditions for opening are taking in consideration that for BuyStop, entry price should be above current price, so that candle 0 should be bearish. But… why is your EA opening pendings? Why not making it open market orders? Any reason for that? 
 
Daniel Cioca #:
I believe that your conditions for opening are taking in consideration that for BuyStop, entry price should be above current price, so that candle 0 should be bearish. But… why is your EA opening pendings? Why not making it open market orders? Any reason for that? 

Yes there is a reason for that.

Yes I am aware as to the BuyStop and SellStop orders are. 

Still getting the same unwanted result. 

 
TheHonestPrussian :

Hi there

So I have an EA which places a Pending Order at the opening price of the current candle, and expires at the end of the current candle.

My code is below, I have even printed an error function in order to diagnose any errors that may occur, however, according to the EA, a pending order is placed so no error appears.

Sometimes a pending order is actually successfully executed, and other times, it tells me a pending order has been placed successfully, but no pending order appears on the chart.

There are no error messages.

Clearly there are no errors, so it must be something to do with my coding. What am I missing here? Why does it sometimes placed a pending order on the chart, and others times it decided not to?

In addition to this, I'm getting random entry prices in my trade ledger, despite clearly specifying the price with which I want my EA to execute a position. It seems to correct itself when I reinit the EA, but I really should not need to do this. 

Many thanks.

I think your conditions are in accordance with the BUYLIMIT order instead of BUYSTOP. Try replacing it with BUYLIMIT.

 
Ahmet Metin Yilmaz #:

I think your conditions are in accordance with the BUYLIMIT order instead of BUYSTOP. Try replacing it with BUYLIMIT.

No I definitely want a BuyLimit

 
TheHonestPrussian # :

No I definitely want a BuyLimit

Then you will need to add the condition that the current buying price goes lower( + STOPLEVEL accordance in your broker level ) than the opening price of the candle into your conditions.

if( <Conditions are met > ){

I don't know if it already exists because you show the conditions as closed.

 
Ahmet Metin Yilmaz #:

Then you will need to add the condition that the current buying price goes lower( + STOPLEVEL accordance in your broker level ) than the opening price of the candle into your conditions.

I don't know if it already exists because you show the conditions as closed.

Will give it a go, but why does it not return the error message like I have asked it to?

 
TheHonestPrussian # :

Will give it a go, but why does it not return the error message like I have asked it to?

if( <Conditions are met > ){

Shouldn't we know your conditions before asking this? How can we know?

 
Ahmet Metin Yilmaz #:

Shouldn't we know your conditions before asking this? How can we know?

Because the condition is the push of a button.