limit order help required please

 

Hi

I can't get the limit orders below to work with the values given. I get error 3 invalid trade parameters. The orders work if set to instant buy or sell. I can't see which paramters is wrong for the limit orders. It must be something simple but I can't see it.


extern double Limit=10;
extern double takeprofit=200;
extern double stoploss=20;

pnt = Point*10;

NLots = 1;

MagicN=969;

Slip=3;

ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask-Limit*pnt,Slip*pnt,Ask-(Limit+stoploss)*pnt,Ask+(-Limit+takeprofit)*pnt,"R2Buy",MagicN,1800,Cyan);
ticket=OrderSend(Symbol(),OP_SELLLIMIT,NLots,Bid+Limit*pnt,Slip*pnt,Bid+(Limit+stoploss)*pnt,Bid-(Limit+takeprofit)*pnt,"R2Sell",MagicN,1800,Pink);

Thanks

 
Ruptor:

Hi

I can't get the limit orders below to work with the values given. I get error 3 invalid trade parameters. The orders work if set to instant buy or sell. I can't see which paramters is wrong for the limit orders. It must be something simple but I can't see it.


extern double Limit=10;
extern double takeprofit=200;
extern double stoploss=20;

pnt = Point*10;

NLots = 1;

MagicN=969;

Slip=3;

ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask-Limit*pnt,Slip*pnt,Ask-(Limit+stoploss)*pnt,Ask+(-Limit+takeprofit)*pnt,"R2Buy",MagicN,1800,Cyan);
ticket=OrderSend(Symbol(),OP_SELLLIMIT,NLots,Bid+Limit*pnt,Slip*pnt,Bid+(Limit+stoploss)*pnt,Bid-(Limit+takeprofit)*pnt,"R2Sell",MagicN,1800,Pink);

Thanks


Try this:

ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask-Limit*Point,Slip,Ask-(Limit+stoploss)*Point,Ask+(-Limit+takeprofit)*Point,"R2Buy",MagicN,1800,Cyan);
ticket=OrderSend(Symbol(),OP_SELLLIMIT,NLots,Bid+Limit*Point,Slip,Bid+(Limit+stoploss)*Point,Bid-(Limit+takeprofit)*Point,"R2Sell",MagicN,1800,Pink);
Cheers
 

Same result as my original code as I expected but it was worth a try in case there was some quirk with Point. The substituition of pnt is so I can set a multiplier for brokers with different decimal places.

Thanks for trying

 

After further testing I still can't see what is wrong. I print out the values just before order is placed but still get error for valid values.


Print(Symbol()," ",OP_BUYLIMIT," ",NLots," ",Ask-10*Point," ",3," ",Ask-30*Point," ",Ask+30*Point);

ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask-10*Point,3,Ask-30*Point,Ask+30*Point,"R2Buy",MagicN,16000,Cyan);


2009.04.28 01:08:01 2009.04.24 19:00 Limado2 EURUSD,H1: last error code is invalid trade parameters
2009.04.28 01:08:01 2009.04.24 19:00 Limado2 EURUSD,H1: OrderSend error 3
2009.04.28 01:08:01 2009.04.24 19:00 Limado2 EURUSD,H1: EURUSD 2 1 1.3241 3 1.3221 1.3281
2009.04.28 01:08:01 2009.04.24 18:00 Limado2 EURUSD,H1: last error code is invalid trade parameters
2009.04.28 01:08:01 2009.04.24 18:00 Limado2 EURUSD,H1: OrderSend error 3
2009.04.28 01:08:01 2009.04.24 18:00 Limado2 EURUSD,H1: EURUSD 2 1 1.3242 3 1.3222 1.3282


Getting desperate now I might be dangling at the end of a rope if one of you experts can't help soon.

 

I think I've got an idea. Try the following change:

ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask-10*Point,3,Ask-30*Point,Ask+30*Point,"R2Buy",MagicN,16000,Aqua);

Cyan doesn't appear to be a valid color:

https://docs.mql4.com/constants/colors

- Tovan

 

its working fine when you change your before last param for 0

ticket=OrderSend(Symbol(),OP_BUYLIMIT,NLots,Ask-Limit*pnt,Slip*pnt,Ask-(Limit+stoploss)*pnt,Ask+(-Limit+takeprofit)*pnt,"R2Buy",MagicN,0,Cyan);
ticket=OrderSend(Symbol(),OP_SELLLIMIT,NLots,Bid+Limit*pnt,Slip*pnt,Bid+(Limit+stoploss)*pnt,Bid-(Limit+takeprofit)*pnt,"R2Sell",MagicN,0,Pink);

I hope it helps

 

I tried Aqua but still the same thanks for trying Tovan.


2009.04.28 10:27:19 2009.04.24 19:00 Limado2 EURUSD,H1: EURUSD 2 1 1.3241 3 1.3221 1.3281

2009.04.28 10:27:19 2009.04.24 18:00 Limado2 EURUSD,H1: last error code is invalid trade parameters
2009.04.28 10:27:19 2009.04.24 18:00 Limado2 EURUSD,H1: OrderSend error 3


Pink is valid and short limits don't work either. When I set order type to OP_BUY the trade works with cyan like it has for the last four years but it was worth a try I shall change to Aqua anyway I don't need any other problems. So at this point I have to say that limit orders don't work on back testing on Interbank accounts Live or demo. They don't support people writting EAs so what now?

Does anyone have a simple limit order piece of code know to work on back test that I could try?

 
Ruptor:

So at this point I have to say that limit orders don't work on back testing on Interbank accounts Live or demo. They don't support people writting EAs so what now? 

As monpseudo88 is saying, the problem is almost certainly your expiration parameter (1800 or 16000). On my IBFX demo account, expiry needs to be specified as a time, not an offset - for example, TimeCurrent() + 1800 for expiry 30 minutes from now. IBFX don't seem to allow expiries of under about 10.5 minutes. 


Separately, my IBFX demo account doesn't allow Ask-10*Point as a limit price on EURUSD. It reports MODE_STOPLEVEL as 30 on EURUSD, and therefore the closest possible limit is Ask-(30*Point). Anything less than this leads to error 130. Similar issues around an over-tight s/l or t/p.


 

Sorry monpseudo88 your post didn't show up when I logged Tovan's showed as the last post hence my last post.

Fiddle sticks, I have the time set to 0 for instant orders and only changed it for the pending orders having read that an expiration time was required.

It changed the error to 130 like you said jjc I can handle those error ok now because they make sense.

I have removed the test code and gone back to the original limit oders with 0 expiration time set and everything works hunky dory.

Thanks for your help guys. I think the error 3 could be improved upon if it said which parameter was wrong don't you?

See attached graph of first working run. Not bad but will probably go down hill from here.

Thanks again guys. A good thing you mentioned about the time offset jjc I could have spent another week trying to figure out that one.

 

Oops! here it is.


Reason: