User Guide – Metatrader Stop Loss/Take Profit Advisor
The following guide is for the Metatrader Stop Loss/Take Profit Advisor.
To place the indicator onto the required chart, right click the icon and select attach to chart. To view all of the output make sure the Metatrader setting “shift end of the chart from right border” is switched on. See the image below.
On start up the trade time is set at 1.0 days and the target win and loss ratios are both set to zero. For the display to work properly, data should be available in all time frames for the selected instrument.
Choosing the Win/Lose Ratio
The most important settings are the target trade time, the win ratio and the loss ratio. The indicator will attempt to find the optimum placement for stop loss and take profit to achieve these targets.
The win ratio (W) and lose ratio (L) are both percentages and must both be set somewhere between 0 and 1. For example with W=50% and L=40% the indicator will calculate the required stop loss and take profit so that trade is likely to close within 24 hours with 90% confidence (50%+40%).
The exact placement of the stops and profits, will depend on the trending, and the market volatility. But generally speaking, the closer W+L is to 1 (W+L->1) the lower the chance of the trade remaining open, and therefore, the closer the stop loss and take profit will be to each other. When W->1, and L->0, the closer the take profit will be to the market’s current price. When L->1, and W->0, the closer the stop will be to the market price.
A frequently asked question is “can I set W=1 and L=0?”. There is typically no meaningful solution to settings like W=1, L=0 (win on every trade) because the random components of markets would mean having to set the take profit at the current market price to achieve this.
The Target Trade Time
The target trade time will be dependent on the strategy being used. The indicator allows you to set a target trade time from 10 minutes upwards. It will then find the stop loss and take profit that has the highest likelihood of attaining the win/loss ratio within the required trade time. Generally speaking, the shorter the trade time, the tighter the stop/profit levels will be.
After setting the trade time, you may need to switch the chart to a lower or higher time frame so that the maximal curves are visible. The confidence curves for a trade on the minute scale won’t be visible on a daily time frame. Likewise the curves for a 12-month trade won’t be visible on a minute chart.
The main display is divided into three sections. The top section displays the target win ratio (W), the target trade time (t), and predicted expectancy.
The predicted expectancy can be understood as the mean profit that would be achieved for the trade. There are two expectancies. One for the buy side and one for the sell side. The calculations can take a few minutes to complete and fully update – dependent on the settings.
The lower two sections display the predicted outcome of a buy and sell side trade. A trading position will always be in one of three states and each of these will have a probability:
- Open – p(open)
- Closed in profit – p(win)
- Closed in loss – p(lose)
The two lower panels show the probabilities of the trade closing in profit, closing in loss or still being open at time=t.
The expectancy is the mean predicted profit of the trade and this graph displays this against time.
The expectancy graph, used together with the outcome graph, will show up differences between the expected returns on the buy/sell side. It will also highlight times of potential high-value profit or loss.
Trade Outcome Graph
The graph above the main panel shows how these probabilities will change over time.
The horizontal axis represents time and the vertical axis represents probability. The graph will show you for example if the probability of profit p(win) will increase or decrease over time and how quickly this will occur.
Initially the indicator displays the graph for the calculated stop loss and take profit. You can switch the display in the setting panel between buy-side or sell-side.
You can also analyze any stop loss/take profit combination you choose by entering your own settings into the input panel. In this mode, the tool will detect whether the potential order is sell-side or buy-side and will display the appropriate graph.
The trade analyzer will check any open trades and will calculate their exit probabilities. This calculation is based on the instrument’s market and the broker-side stop loss/take profits.
The panel lists open trades in order, with those with the highest chance of exit listed first. Open trades which are close to profit are displayed green, those that are close to loss are displayed red. The threshold at which trades are highlighted can be set in the input panel:
- Threshold for alert on profit trades (default is 50%)
- Threshold for alert on loss trades (default is 50%)
You can set an alert that will trigger as soon as an open trade reaches its threshold probability of profit/loss. The alert can be via a terminal popup, or by SMS or email. SMS and email will only work if you have these services configured in your Metatrader terminal.
The alerting period can be set from 10-minutes ahead.
For example, with the following settings
- Threshold on profit trades=90%
- Threshold on loss trades=80%
- Exit time period check=1 days
- Alert type=Terminal
The indicator will create an alert whenever any open trade has an 80% chance or higher of loss in 1 day. Or it will create an alert whenever an open trade has a 90% chance or higher of reaching its take profit within 1 day.
The trade analyzer can be used to check the profit/loss probabilities for all open trades from 10-minutes ahead to any point in the future.
The indicator generates the following data outputs.
|Buy/sell stop loss
|Buy/sell take profit
Open Metatrader’s data window (CTRL+D) to show the signal values. You can hover with the mouse cursor over any point to display the value in the data window.
|Target trade time (days)
|Time point for calculations - 0.007 days (10 minutes) or higher
|Target trade win %
|Target win rate you are trying to achieve
|Target trade loss %
|Target loss rate you are trying to achieve
|Analyze open trades?
|Show or hide the trade analyzer panel
|Show probability graph?
|Show or hide the outcome probability graph
|To analyze your own stop loss, enter value here in pips
|To analyze your own take profit, enter value here in pips
|Alert on pending profit trades?
|Create an alert when an open trade is near profit - None/Terminal/SMS/EMail
|Alert on pending loss trades?
|Create an alert when an open trade is near loss - None/Terminal/SMS/EMail
|Threshold for alert of profit trades
|Probability threshold on profitable trades
|Threshold for alert of loss trades
|Probability threshold on loss trades
|Exit time period check (days)
|The time point for which the alert threshold probabilities apply
|Specify market expectations such as trend reversal. Leave “random” if none. (0=None, 1=Trend, -1=Reverse Trend)
|Trade side (main signal to output)
|Which sl/tp lines should be displayed – buy side/sell side (0=Buy, 1=Sell)
|Curve 1 %
|The percentage for the 1st maximal curve
|Curve 2 %
|The percentage for the 2nd maximal curve
|Curve 3 %
|The percentage for the 3rd maximal curve
|Curve 4 %
|The percentage for the 4th maximal curve
|Curve 1 color
|Curve 2 color
|Curve 3 color
|Curve 4 color
A further explanation of the inputs is provided here.
Frequently Asked Questions
The following are the most frequently asked questions.
What are the curves on the chart and how do I use them?
The curves show the probability of the price reaching (touching) a certain level within a certain time. Or put another way, these are regions where the price could be in the future, within a certain degree of confidence. The wider the curve, the higher the certainty that the price will fall within it. The narrower the curve, the less certainty there is that the price will fall within it.
The curves extend forwards in time, from the current time. For example, with the red 20% curve, the price has a 20% chance of touching the curve. In other words, 80% of the time, the price will remain inside that curve. The curves get bigger as time increases because the chances of the price moving further away also increase.
What do “Target Trade Time”, “Win/Lose Ratio” mean and what is their relationship to one another?
Win ratio: The “win ratio” is a target percentage and is the probability of a trade resulting in a profit.
Lose ratio: This is the probability of a trade resulting in a loss.
Target trade time: The “Target Trade Time” is set in days and is the expected duration for your trades. For example
- Target Trade Time=1.00 days (24 hours)
- Target Win Ratio=0.50 (50%)
- Target Loss Ratio=0.40 (40%)
With this setup the indicator will calculate stop loss/take profit levels so that a trade is likely to reach either the stop loss or take profit within 24 hours with 90% confidence (50%+40%). The size of the stop and profit level are computed given a) the current and future market volatility and b) any trending condition.
The confidence of a trade closure can never be 100% because the maximal curves never reach zero. There is always a chance (non-zero probability) that the trade will not close within the predicted time period.
If the target win/lose ratio is impossible, the indicator will find the nearest valid solution.
When the stop loss and take profit are the same size how can the probability of a loss be higher?
The market has to move a greater distance to reach the profit side than the loss side because of the spread. If the market is trending (and the trend model is selected), the probability of profit may be higher/lower depending on the strength of the trend.
The stop loss is bigger than the take profit. How can I make it smaller and keep a high win:loss rate?
An impossible trade is one where the payoff is much greater than the risk would allow. For example, a common mistake is setting the win rate very high and the loss rate very low. Financial markets are far too efficient to allow for such easy wins to occur.
The indicator uses a highly realistic pricing model, so it will give a solution that matches the inputs provided and the current market conditions. Typically the only way to achieve a high win/low loss rate is to place the take profit close to the market price, and the stop further away.
The way around this is to set a more realistic win/loss rate and look for trending conditions that might tip the odds in favor of a win.
Why would a trader want a better chance of losing than winning – that is why would anyone set a win ratio less than 50 percent?
A profitable return (expectancy) can be obtained with any win/loss rate above zero provided you predict the correct movement of the market over the period of the trades better than chance alone.
There is a fixed relationship between the profit size, stop size and the win/lose ratio. With a win ratio less than 50% you typically also have a profit value that is bigger than the loss value. So this can still result in a profitable strategy.
The win/loss rate is primarily a decision for your account requirements and money management as well as your trading style.
What is the numerical output in the data window and how can it be used?
The stop and profit levels are output in the data window and in the panel. The values are output as price levels (not pips or points).
- SL – the stop loss price level.
- TP – the take profit price level.
The indicator sometimes returns equal sizes for the sell and the buy side, i.e. sell TP = buy TP and sell SL = buy SL. Is this correct?
This will depend on the inputs, the market type and the bid/ask spread. With the trendless (flat) market setting the size of the stop level could be the same on both sides. This is because there is no assumed trend and therefore the probility of a price move is the same in either direction. The other two options for trending and reverse would usually give a different value for the buy and sell side unless there is no trend in that market.
Can I use this indicator to decide which side to trade?
The purpose of this indicator is to advise on stop loss and take profit placement in any given market. While it will show you when there are good risk/reward opportunities, it doesn’t tell you which way to trade. Meaning that it doesn’t tell you to buy or to sell but gives the information to make more informed decisions.
Does the SLTP Advisor use the same calculations found in the stop loss calculations Excel spreadsheet?
I don’t see how to get the output for Trade Wins/Loses/Open or estimated Win Ratio from the SLTP Advisor?
The Excel spreadsheet is only a basic demo. Due to limitations in creating a portable Excel file the system only uses a simplified model and doesn’t support any live market data feeds.
Probability Trade Wins / Loses / Open or Estimated Win Ratio from the SLTP Advisor:
This is displayed in the indicator panel as p(win), p(lose) and p(open). The SL and TP lines are also displayed on the chart for the buy and sell side. The values are also output to Metatrader’s Data Window.
Why do the indicator’s values sometimes jump in steps rather than smoothly?
To calculate the probabilities for the model there is a necessary conversion from continuous to discrete values. This means you can sometimes see step changes in the values of the probabilities as it moves from one interval to the next. Usually this will only be noticeable when volatility is very low or values are at extreme points in the calculation model (when trade time is very close or very far in the future).
If the input settings are not valid or are for an impossible trade, the indicator will automatically give the nearest solution.
When I extend the time period why do the probabilities nearly always stay the same?
The probabilities will converge towards a maximum and will then change increasingly slowly as time goes forward. The rate this convergence happens will depend on the market and how close the stop loss and take profit is to the current bid/ask price. The closer they are to the bid/ask, the quicker the convergence will be.
For longer time periods (weeks, months, years), the indicator will need to use data from different timeframes.
Why does the output panel sometimes appear empty or in the wrong place on the chart?
This is usually when the indicator hasn’t updated because the chart needs to be refreshed. This refresh normally happens automatically in Metatrader. If it doesn’t just open the indicator’s settings box (Ctrl+I) and click OK.
If the market is closed, the indicator will not receive any refresh signals from Metatrader. This means parts of the tool will not work until the market is open.
Also if the indicator launches before Metatrader connects to your broker account, the initialization won’t be performed properly and the indicator won’t work. This can happen when Metatrader is started and the indicator automatically loads onto a saved chart.
In either of these situations, if the tool display isn’t refreshing or showing correctly, simply close the chart, open a new one and place the indicator onto the new chart.
How do I call the indicator from MQL?
Accessing the indicator outputs can be achieved easily with MQL using the custom indicator function (iCustom). The example code below demonstrates for MQL4:
double sl, tp; sl=iCustom(NULL,PERIOD_CURRENT,"test\myindicator",... comma separated list of parameters ... ,0,1); tp=iCustom(NULL,PERIOD_CURRENT,"test\myindicator", ... comma separated list of parameters ... ,1,1);
Simply replace “test\myindicator” with the name of the indicator in your local Metatrader folder. Replace the parameters in the list with the required values. For MQL5 the call is:
int MA_handle=iCustom(NULL,PERIOD_CURRENT,"test\myindicator",... comma separated list of parameters ... );
Please note that we are unable to assist with coding issues.