MQL4 Sell Order Issue

 

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.

 

[code]

 

 extern double StopLoss = 10; //Stop loss in pips

  extern double TakeProfit = 21; //Take profit in pips

  extern double Lots = 0.01; //Lot Size

  extern int magic = 1337; // Used to differentiate trades, so all the trades will be using this magic number for this EA



   int ticket = OrderSend(Symbol(),OP_BUY,0.1,Ask,3, Ask-StopLoss*Point,Ask+TakeProfit*Point,"Buy Order",magic,0,clrGreen);

    int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Sell Order",magic,0,clrRed);

[/code] 

 

Thanks in advance for the help! 

 

**NOTE the buy does execute with the same #130 error. 

 
bryce910: error #130 which means invalid stoploss.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. int ticket = OrderSend(Symbol(),OP_BUY ,0.1,Ask,3, Ask-StopLoss*Point, Ask+TakeProfit*Point,"Buy Order",magic,0,clrGreen);
    int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,3, Bid+StopLoss*Point, Bid-TakeProfit*Point,"Sell Order",magic,0,clrRed);
    You buy at the Ask and sell at the Bid. For a buy order, the SL is relative to the Bid.
  3. 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
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. int ticket = OrderSend(Symbol(),OP_BUY ,0.1,Ask,3, Ask-StopLoss*Point, Ask+TakeProfit*Point,"Buy Order",magic,0,clrGreen);
    int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,3, Bid+StopLoss*Point, Bid-TakeProfit*Point,"Sell Order",magic,0,clrRed);
    You buy at the Ask and sell at the Bid. For a buy order, the SL is relative to the Bid.
  3. 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! 

 
bryce910:


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