ubzen:
After RefreshRates(); try adding a variable called iAsk or Whatever. Check if iAsk<=Price and then in OrderSend() use iAsk instead and see if that helps.
After RefreshRates(); try adding a variable called iAsk or Whatever. Check if iAsk<=Price and then in OrderSend() use iAsk instead and see if that helps.
Thanks. I've corrected it to this and am going to test it now.
void OpenLong(double Price){ RefreshRates(); iAsk = MarketInfo(Symbol(),MODE_ASK); if(iAsk<=Price){ OrderSend(Symbol(), OP_BUY, 0.10, iAsk, 0, 0, 0, "", 0, 0, Blue);} return(0); }
OK, so i've just tested it, but unfortunatly it doesn't work. Do you or maybe someone else knows what i am doing wrong here?
I think your (ubzen) solution is good, but just seems that MT4 is making a mess of it?
I think your (ubzen) solution is good, but just seems that MT4 is making a mess of it?
- captaincrunchy:The code says to open a buy at 1.5 +/- 0 (no slippage) If the market is not exactly at 1.5 order fails. If you want 1.5 or less use a OP_BUYLIMIT.
So OpenLong(1.5000) would mean, buy 0.10 lots if available for 1.5000 or less. - Always test return codes
int ticket = OrderSend(... if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
- Why use
MarketInfo(Symbol(),MODE_ASK)
and not just the simpler Ask. iAsk = Ask;
- Unless your EA is looping (not returning from start) or opening multiple orders, the Refresh is unnecessary.
WHRoeder:
- captaincrunchy:The code says to open a buy at 1.5 +/- 0 (no slippage) If the market is not exactly at 1.5 order fails. If you want 1.5 or less use a OP_BUYLIMIT.
So OpenLong(1.5000) would mean, buy 0.10 lots if available for 1.5000 or less. - Always test return codes
- Why use
and not just the simpler Ask. iAsk = Ask;
- Unless your EA is looping (not returning from start) or opening multiple orders, the Refresh is unnecessary.
Thanks, WHRoeder.
1. It's in my strategy to open direct marketorders, my edge is a few pips per trade. Too small to use limit orders. But if i get slippage it will kill my profit.
2. Thanks, will do that.
3. Cause i use it with more pairs all being traded from one EA, one chart.
4. Yes it's looping.
Actually i still don't know why it wouldn't work. Seems that MT4 always allows some slippage (but always negative it seems?)?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
This is the code which i want to use to open a long, with restriction that the orderopenprice can be up to double "Price".
So OpenLong(1.5000) would mean, buy 0.10 lots if available for 1.5000 or less.
But, sometimes the order gets filled at a higher price, say 1.5001 or 1.5002. Even with 0 slippage allowed.
How is this possible and, how can i solve this?
Thanks!