Disliked{quote}... (bid/ask) lines always floating,can we clone these lines at required distance (up/down) and use as tp/sl - keep in mind these tp/sl never ever will be triggered at all till the terminal is on,but will stopped where these are when terminal turned offIgnored
QuoteDisliked...main idea and logic behind is when a trader is disconnected from his broker,how to avoid big losses and stay safe...
If I understand this right, if not please correct-
- purpose is to limit a potential full-sl (or more) loss on an open order, when connection to the broker (and control over an order) is gone (for whatever reason, from any connection like a user terminal or vps), such that the potential loss is minimal and less than the trader's intended full stop loss distance
Some thoughts-
- tp and sl values, if provided when opening a new order, are saved on the broker end, so the user terminal is not required to remain connected/active/on, for those levels be active and abided to
- depending on the broker, the sl price may or may not be guaranteed, ie do they uphold your sl even if price gaps past it and there is no liquidity at that price?
- sl values have to be a minimum distance away from the order open price when opening or modifying the order, eg 5points or 1pip
- - the minimum distance can be checked via mt4- marketinfo() and mode_stoplevel, mt5- symbolinfo() and SYMBOL_TRADE_STOPS_LEVEL
- - per https://book.mql4.com/appendix/limits, buys(Bid-SL ≥ StopLevel), sells(SL-Ask ≥ StopLevel)
- changing a sl value outside the minimum distance is no problem, changing it a lot is generally no problem, some brokers will limit how many times you can modify an order/s and give you/the ea an 141 error which is ERR_TOO_MANY_REQUESTS
- there are 2 stoplosses active for any order, first is the normal intended sl, the second is this emergency disconnection sl
- connection to the broker can be checked periodically via isconnected()
Implementing-
- in the event of disconnection, the order will need to already have the emergency sl as it's sl, so that's saved on the broker end
- a disconnection can't be predicted, so that emergency stop will have to be the order's sl all along
- with no disconnection, the emergency sl needs to be regularly updated to stay untriggered, but another mechanism needs to be active to regularly check the order's intended sl further away
- price of the intended sl needs to be kept somewhere and checked regularly to close an order normally
- when opening the order, the emergency sl is the sl, but the intended sl is saved elsewhere-
- - inside the order's comment
- - inside an ea
- - on a chart object like a hline
- updating the emergency sl - every x seconds/min/ticks/price movement, loop through all open orders, modify the sl to the ask/bid price +- minimum stoplevel distance or further
- checking for a natural sl close - every tick, loop through all open orders and check the closing price of ask/bid is further or equal to the saved natural sl, if so, close order
tldr-
- the emergency disconnection sl needs to be the order's sl, so it's already saved at the broker upon a disconnection
- on opening the order, save the intended sl price somewhere, in ordercomment, a variable in an ea, or a chart object like hline
- every x secs/mins/ticks, update that order's sl to be some near distance from current price, to be ready for a disconnection
- every tick, check the saved intended sl price to see if the order should be closed normally