Play videoPlease edit your post.
For large amounts of code, attach it.
- int ticket = OrderSend(Symbol(),OP_BUY ,0.1,Ask,3, Ask-StopLoss*Point, Ask+TakeProfit*Point,"Buy Order",magic,0,clrGreen);You buy at the Ask and sell at the Bid. For a buy order, the SL is relative to the Bid.
int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,3, Bid+StopLoss*Point, Bid-TakeProfit*Point,"Sell Order",magic,0,clrRed); extern double StopLoss = 10; //Stop loss in pips extern double TakeProfit = 21; //Take profit in pips Bid,3, Bid+StopLoss*Point
Not in pips. In points. On a 5 digit broker a pip = 10 points. If you want to use pips, you must convert. TP/SL, and SLIPPAGE. Problems with a calculation - MQL4 forum
Play videoPlease edit your post.
For large amounts of code, attach it.
- int ticket = OrderSend(Symbol(),OP_BUY ,0.1,Ask,3, Ask-StopLoss*Point, Ask+TakeProfit*Point,"Buy Order",magic,0,clrGreen);You buy at the Ask and sell at the Bid. For a buy order, the SL is relative to the Bid.
int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,3, Bid+StopLoss*Point, Bid-TakeProfit*Point,"Sell Order",magic,0,clrRed); - Not in pips. In points. On a 5 digit broker a pip = 10 points. If you want to use pips, you must convert. TP/SL, and SLIPPAGE. Problems with a calculation - MQL4 forum
Okay thank you.
So I adjusted that in my code but some reason my stop loss executed at a -$8 and my Take Profit at a +$4.20. However my Take Profit is much higher then my stop loss so that doesn't make any sense?
Also I edited my top post like suggested!
Okay thank you.
So I adjusted that in my code but some reason my stop loss executed at a -$8 and my Take Profit at a +$4.20. However my Take Profit is much higher then my stop loss so that doesn't make any sense?
Also I edited my top post like suggested!
When you calculate your buy order tp/sl you are calculating a Bid price to close at. The profit/loss is the difference between the opening Ask price and that closing Bid price. You have to decide if you want to close for equal profit/loss or you want to close for equal price movement.
- Equal profit Loss / unequal price movement
- Buy Order
- Spread = 5pt
- Open Price (Ask) = 1.5000
- SL = Ask - 20pt (1.5000 - 0.0020 == 1.4980)
- TP = Ask + 20pt (1.5000 + 0.0020 == 1.5020)
Bid | Ask | Profit | Move | |
---|---|---|---|---|
TP | 1.5020 | 1.5025 | 0.0020 pt | 25 pt |
Open | 1.4995 | 1.5000 | ||
SL | 1.4980 | 1.4985 | -0.0020 pt | 15 pt |
- Equal price movement / unequal profit Loss
- Buy Order
- Spread = 5pt
- Open Price (Ask) = 1.5000
- SL = Bid - 20pt (1.4995 - 0.0020 == 1.4075)
- TP = Bid + 20pt (1.4995 + 0.0020 == 1.5015)
Bid | Ask | Profit | Move | |
---|---|---|---|---|
TP | 1.5015 | 1.5020 | 0.0015 pt | 20 pt |
Open | 1.4995 | 1.5000 | ||
SL | 1.4975 | 1.4980 | -0.0025 pt | 20 pt |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am new to working with mql4 and I have ran into a small issue that I am not able to get fixed! As I use the code before every time it try to sell it gives me the error #130 which means invalid stoploss. But I don't understand what is wrong with the code to cause that.
Thanks in advance for the help!
**NOTE the buy does execute with the same #130 error.