OrderSend stop loss question

 

I'm in the middle of coding my strategy right now, and I'm about to enter the stage where I will start writing the OrderSend parts. Here's my question:

Say I make sure only one order is open at a time for this strategy. If I do an OrderSend with a stop loss > 0, then I exit the ticket, what happens to the stop loss? I had this strategy programmed in GFT's language but GFT's language kept the stop loss level even after the ticket was closed, which ended up getting filled sooner or later and ended in losses most of the time. I want to know if this will happen in MQL4.

Bonus cookie question: if I set the stop loss to 0, what happens? Does this mean "no stop loss, thanks"?

 
ubuntuboy:

Say I make sure only one order is open at a time for this strategy. If I do an OrderSend with a stop loss > 0, then I exit the ticket, what happens to the stop loss? I had this strategy programmed in GFT's language but GFT's language kept the stop loss level even after the ticket was closed, which ended up getting filled sooner or later and ended in losses most of the time. I want to know if this will happen in MQL4.

Bonus cookie question: if I set the stop loss to 0, what happens? Does this mean "no stop loss, thanks"?

MT4 is a little unusual in that (a) each order is treated as a separate position, and (b) stop-losses and profit-targets are attributes of an order/position, not separate orders. When an order/position is closed, any attached stop-loss or profit-target dies with it. To put it another way, MT4 doesn't have an OCO mechanism because it doesn't really need one.

A stop-loss of zero does indeed mean "no stop loss, thanks".

 

What do you mean "exit the ticket"?

When you successfully open an order (programmatically checking for success of course), then the stop loss is set on the broker's server at the level you requested.

If you subsequently select that order and successfully close it, then the stop loss has no context as there is no open order.

If you set the stop loss to 0, it means no stop loss.

Some brokers require that you open each order with a stop loss of 0 and then select and modify the order to apply the stop loss (market execution).

Other brokers permit the stop loss to be set when opening the order (instant execution).

You can check this by attempting to place a manual trade and checking the dialog box.

CB

 
Thanks both for the quick replies. I haven't gotten the no stop loss part working yet, but I'll keep working on it.
Reason: