Select an order once it is opened

 

Hey guys,

I seem to be having a problem. I have written the code needed to select the last pending order that has opened, upon opening I use PlaySound(). Now, it seems to keep selecting that order every new candle and playing the sound. Is there any filter that I can use to make the EA select it once only upon the order being opened, then play the sound once?

Any help is appreciated. 

 
DeanDeV:

Hey guys,

I seem to be having a problem. I have written the code needed to select the last pending order that has opened, upon opening I use PlaySound(). Now, it seems to keep selecting that order every new candle and playing the sound. Is there any filter that I can use to make the EA select it once only upon the order being opened, then play the sound once?

Any help is appreciated. 

  static int last_pending_order=0;
  //Code to select the last pending order
  if(last_pending_order!=OrderTicket())
    {
    //Code to send alert/play sound
    last_pending_order=OrderTicket();
    }
Should do it
 
DeanDeV:

Hey guys,

I seem to be having a problem. I have written the code needed to select the last pending order that has opened, upon opening I use PlaySound(). Now, it seems to keep selecting that order every new candle and playing the sound. Is there any filter that I can use to make the EA select it once only upon the order being opened, then play the sound once?

Any help is appreciated. 

You need to chek number of orders of buy sell buystop...

When pending order will be less then in previous candle(tick),it means that he was opened. 

 
GumRai:
Should do it
Thanks! :)
 
eevviill: When pending order will be less then in previous candle(tick),it means that he was opened. 
When it opens, OrderType() will change to OP_BUY/OP_SELL
 
GumRai:
Should do it

I seem to be running into a brick wall here.. My code works perfectly while back testing, but forward testing it gives invalid lots, invalid take profit and stop loss. This is my logic, and perhaps you could help?

if(xyz)
 {
  entryprice=pendingprice;

  OrderSend(Symbol(),PendingOrder,LotSize,pendingprice,...)
 }

//If pending order is opened send another order
for()
 {
  OrderSelect()
   {
    lotsize=OrderLots();
   }
 }

if()
 {
  OrderSend(Symbol(),PendingOrder,lotsize,entryprice,3,entryprice-StopLoss,entryprice+TakeProfit,...) PlaySound();
 }

 Is my logic incorrect somewhere? Like I say, it works perfectly in back testing but live it gives OrderSend() errors for the second OrderSend(). I have tried using NormalizeDouble() but it still does the same thing.

 
DeanDeV:

I seem to be running into a brick wall here.. My code works perfectly while back testing, but forward testing it gives invalid lots, invalid take profit and stop loss. This is my logic, and perhaps you could help?

 Is my logic incorrect somewhere? Like I say, it works perfectly in back testing but live it gives OrderSend() errors for the second OrderSend(). I have tried using NormalizeDouble() but it still does the same thing.

Not enough information to guess what the problem may be.

Is pending order a buy or sell?

what lostsize , SL and TP is the order using, do you check if an order send fails? 

 

There should be no need to Normalize lotsize unless you do calculations to get the lotsize value. Then you should normalize by checking that it is an exact multiplication of lotstep. I don't know what happens if you normalize a lot size with Digits as most lot sizes are 2 decimal places.

I don't see any code to place the initial pending order

Any orders placed manually or by another EA on the same pair will interfere with the logic.

 

 

 

if(Open[1]<Close[1] || Open[1]==Close[1]) 
//Can be replaced with
if(Open[1]<=Close[1]) 
 
GumRai:

There should be no need to Normalize lotsize unless you do calculations to get the lotsize value. Then you should normalize by checking that it is an exact multiplication of lotstep. I don't know what happens if you normalize a lot size with Digits as most lot sizes are 2 decimal places.

I don't see any code to place the initial pending order

Any orders placed manually or by another EA on the same pair will interfere with the logic.

 

 

 

 

I normalized the lot size simply because it was giving that error, so I thought I could just normalize it.

double sellstopprice=Bid-(PendingPoints*Point);
sellopenprice=sellstopprice;
            
 int selli=OrderSend(Symbol(),OP_SELLSTOP,LotSize,sellstopprice,3,sellstopprice+(StopLoss*Point),sellstopprice-(TakeProfit*Point),"Sell",2,0,clrRed);
  if(selli<0) Print("Failed to place Sell order, error#",GetLastError());

 This triggers the buy stop order..

 
GumRai:

There should be no need to Normalize lotsize unless you do calculations to get the lotsize value. Then you should normalize by checking that it is an exact multiplication of lotstep. I don't know what happens if you normalize a lot size with Digits as most lot sizes are 2 decimal places.

I don't see any code to place the initial pending order

Any orders placed manually or by another EA on the same pair will interfere with the logic.

 

 

 

 

Working fine now. Thank for your help.
 
WHRoeder:
When it opens, OrderType() will change to OP_BUY/OP_SELL
And?
Reason: