Select an order once it is opened

Back to topics list To post a new topic, please log in or register
avatar
120
DeanDeV 2015.07.28 12:01
 

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. 

avatar
Moderator
3423
GumRai 2015.07.28 12:26 #
 
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
avatar
872
eevviill 2015.07.28 14:08 #
 
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. 

avatar
120
DeanDeV 2015.07.28 21:24 #
 
GumRai:
Should do it
Thanks! :)
avatar
13009
WHRoeder 2015.07.28 22:23 #
 
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
avatar
120
DeanDeV 2015.07.28 23:19 #
 
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.

avatar
Moderator
3423
GumRai 2015.07.29 00:29 #
 
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? 

avatar
Moderator
3423
GumRai 2015.07.29 07:41 #
 

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]) 

 

avatar
120
DeanDeV 2015.07.29 07:55 #
 
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..

avatar
120
DeanDeV 2015.07.29 11:09 #
 
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.
avatar
872
eevviill 2015.07.29 14:43 #
 
WHRoeder:
When it opens, OrderType() will change to OP_BUY/OP_SELL
And?
Back to topics list  

To add comments, please log in or register