How do you do if you want to open a sell that has the SL at the exact price in which you opened from the moment the order is fired that works 100 per cent of the time?
The following code uses Ask as the SL and it fires right sometimes yes sometimes not. Why?
How do you do if you want to open a sell that has the SL at the exact price in which you opened from the moment the order is fired that works 100 per cent of the time?
The code you posted still isn't checking the return code - take a look at the documentation for an example on how to do it. If you check the return code, you don't have to guess why your OrderSend isn't working.
I also suggest reading up about stops level. Your SL and TP must be a minimum distance away (set by the broker). So what you want is not really possible, if I'm understanding you correctly.
Here is a table from the article I have linked:
StopLevel Minimum Distance Limitation.
A trade operation will not be performed if any of the following conditions is disrupted.
Order Type | Open Price | StopLoss (SL) | TakeProfit (TP) |
---|---|---|---|
Buy | Modification is prohibited | Bid-SL≥StopLevel | TP-Bid≥StopLevel |
Sell | Modification is prohibited | SL-Ask≥StopLevel | Ask-TP≥StopLevel |
BuyLimit | Ask-OpenPrice≥StopLevel | OpenPrice-SL≥StopLevel | TP-OpenPrice≥StopLevel |
SellLimit | OpenPrice-Bid≥StopLevel | SL-OpenPrice≥StopLevel | OpenPrice-TP≥StopLevel |
BuyStop | OpenPrice-Ask≥StopLevel | OpenPrice-SL≥StopLevel | TP-OpenPrice≥StopLevel |
SellStop | Bid-OpenPrice≥StopLevel | SL-OpenPrice≥StopLevel | OpenPrice-TP≥StopLevel |
- book.mql4.com
The code you posted still isn't checking the return code - take a look at the documentation for an example on how to do it. If you check the return code, you don't have to guess why your OrderSend isn't working.
I also suggest reading up about stops level. Your SL and TP must be a minimum distance away (set by the broker). So what you want is not really possible, if I'm understanding you correctly.
Here is a table from the article I have linked:
StopLevel Minimum Distance Limitation.
A trade operation will not be performed if any of the following conditions is disrupted.
Order Type | Open Price | StopLoss (SL) | TakeProfit (TP) |
---|---|---|---|
Buy | Modification is prohibited | Bid-SL≥StopLevel | TP-Bid≥StopLevel |
Sell | Modification is prohibited | SL-Ask≥StopLevel | Ask-TP≥StopLevel |
BuyLimit | Ask-OpenPrice≥StopLevel | OpenPrice-SL≥StopLevel | TP-OpenPrice≥StopLevel |
SellLimit | OpenPrice-Bid≥StopLevel | SL-OpenPrice≥StopLevel | OpenPrice-TP≥StopLevel |
BuyStop | OpenPrice-Ask≥StopLevel | OpenPrice-SL≥StopLevel | TP-OpenPrice≥StopLevel |
SellStop | Bid-OpenPrice≥StopLevel | SL-OpenPrice≥StopLevel | OpenPrice-TP≥StopLevel |
Not Possible
This post helps explain about return codes.
A sell order is opened at the Bid, and closed at the Ask (which is above the Bid).
A sell SL will trigger when the Ask price is at or above the SL price.
If you set the SL to the Bid price, the Ask is already above this...
OrderSend(_Symbol,OP_SELL,.01,MarketInfo(_Symbol,MODE_BID),0,MarketInfo(_Symbol,MODE_ASK),0,NULL,0,0,clrNONE);
Gives no errors. Can't find any more info on return codes that could help. Will keep searching.
Friend here said that its just not possible. Is he correct?
nadiawicket:
Friend here said that its just not possible. Is he correct? |
|
|
|
1. No minimum Stop Level with my broker.. How does this violate if that rule is for nonzero StopLevels?
2. I really don't understand why you are mentioning Take Profits at all? Maybe I'm missing your point or something.We are dealing with Stop Loss. ( which I'm using to effectively create a Trailing Stop)
Something else; no matter how I set the initial Stop Loss of my OrderSends, they bork out like 50 per cent of the time like its some glitch or I'm just not doing it right. If anyone could post the correct code for an OrderSend that puts the right Stop Loss from the get go without having to ordermodify afterwards, I'd really appreciate it.
OrderSend(_Symbol,OP_SELL,.01,MarketInfo(_Symbol,MODE_BID),0,MarketInfo(_Symbol,MODE_ASK)+10*Point,0,NULL,0,0,clrNONE);
For example the code above; whats wrong with it that it fails about 50 per cent of the times at setting the correct SL (10 points above) from the get go? They keep telling me to check return codes; however I get nothing with GetLastError() thats not a 0. What else can I check about "return codes"? The standard link doesn't say anything else I can make sense out of other than using the GetLastError()? Any other way to retrieve other return codes thats not GetlastError()?
Thanks a zillion.
Example:
Ask: 1.10020
Bid: 1.10010
(spread 10 points)
If you set your SL on a sell order to 1.10010 (the Bid) then the closing price (Ask) is already above it. If this worked, your order would instantly close as the SL has been passed.
If you feed those numbers into the equation on the table:
A trade operation will not be performed if any of the following conditions is disrupted.
SL - Ask ≥ StopLevel
1.10010 - 1.10020 = - 10 points
Even if your StopLevel is 0, a negative number is still less than 0.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Why does this code produce a wrong SL sometimes yes sometimes no?