Download MetaTrader 5
To add comments, please log in or register
Read the interviews of the Automated Trading Championship participants
DeanDeV
330
DeanDeV 2015.07.28 10: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. 

Keith Watford
Moderator
7870
Keith Watford 2015.07.28 10: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
Vasyl Nosal
18197
Vasyl Nosal 2015.07.28 12: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. 

DeanDeV
330
DeanDeV 2015.07.28 19:24  
GumRai:
Should do it
Thanks! :)
whroeder1
13593
whroeder1 2015.07.28 20: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
DeanDeV
330
DeanDeV 2015.07.28 21: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.

Keith Watford
Moderator
7870
Keith Watford 2015.07.28 22: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? 

Keith Watford
Moderator
7870
Keith Watford 2015.07.29 05: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]) 
DeanDeV
330
DeanDeV 2015.07.29 05: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..

DeanDeV
330
DeanDeV 2015.07.29 09: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.
Vasyl Nosal
18197
Vasyl Nosal 2015.07.29 12:43  
WHRoeder:
When it opens, OrderType() will change to OP_BUY/OP_SELL
And?
/
To add comments, please log in or register