User Guide – Metatrader Stop Loss/Take Profit Advisor
The following guide is for the Metatrader Stop Loss/Take Profit Advisor.
Place the indicator onto the required chart. There are two modes to choose from. Panel mode shows the output in tabular form at the bottom of the chart. Graph mode displays the output in graphical format. The figure below shows panel mode.
The default settings are for convenience only and are not intended as a recommendation. By default the trade time is 288 bars – corresponding to exactly 1 day on the five minute chart (M5). Whichever timeframe is used, the number of bars should be greater than 10 and less than 1000. The indicator will automatically unload if it cannot make reliable estimates.
The indicator generates the following numerical signals.
|0||sl(b)||Buy side stop loss in pips (points ÷ 10) from the current price|
|1||tp(b)||Buy side take profit in pips (points ÷ 10) from the current price|
|2||sl(s)||Sell side stop loss in pips (points ÷ 10) from the current price|
|3||tp(s)||Sell side take profit in pips (points ÷ 10) from the current price|
|4||dvdt||Rate of change of the stop/profit spread. Used as measure of volatility.|
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 (in chart bars)||Stops and profits will be calculated according to the trade time|
|Target win ratio||The ratio of winners to losers you are trying to achieve|
|Market behavior||Specify market expectations such as trend reversal. Leave “random” if none.|
|Averaging period (in chart bars)||Use a longer averaging period for longer trade times|
|Trade side (main signal to output)||Which signal should be displayed on chart – buy side/sell side or both|
|Buy side SL color||Color setting|
|Buy side TP color||Color setting|
|Sell side SL color||Color setting|
|Sell side TP color||Color setting|
|Rate of Change color||Color setting|
|Show panel||Choose either panel mode or graphic mode|
A further explanation of the inputs is provided here.
Frequently Asked Questions
The following frequently asked questions are for the indicator.
What do “Target Trade Time”, “Win Ratio” and “Averaging Period” mean and what is their relationship to one another?
Win ratio: The “win ratio” is a target percentage and is the ratio of winning to losing trades that you are aiming for. For example if “win ratio” is 0.75 that means you want to win 3 out of every 4 trades (75%).
Target trade time: The “Target Trade Time” is set in chart bars and this is the average duration for your trades. For example:
- M5 chart
- Target Trade Time=288 bars (24 hours)
- Target Win Ratio=0.75 (75%)
With this setup the indicator will output stop loss/take profit levels such that a trade is likely to reach either the stop loss or take profit within 24 hours. The size of the stop and profit level are computed such that the ratio of winners to losers will be 75% given a) the current market volatility and b) any trending condition.
Note that the maximal curves never reach zero. This means there is always a finite probability that the trade will not close within the time period. Thus it is impossible to set an exact win ratio but only place it within a target range.
Averaging period: To calculate the stop/profit levels the indicator estimates volatility. The “Averaging Period” sets the period over which this volatility is measured. A longer period means more bars are taken into consideration which will be less sensitive to recent market activity. This period is also used to measure trending.
What is the numerical output in the data window and how can it be used?
The stop and profit levels are output in “pips” in the data window and in the panel (if displayed). To convert to points for the current chart:
- 1 Pip = 10 Point. Using MQL value from MarketInfo(symbol,MODE_POINT).
- Multiply pip value by 10 to convert to points.
The indicators seems to return equal values for the sell and the buy side, i.e. sell TP = buy TP and sell SL = buy SL. Is this correct?
When “market behavior=0” (flat) the outputs are the same for both buy and sell side. This is because the indicator uses a flat market model such that there is no prior assumption on market direction. The other two options for trend behavior (=1 and =-1) would usually give a different value for the buy and sell side because here assumptions about trend will be used.
What is dvdt?
Signal output # 5 is the dvdt – rate of change. This output is a measure of how quickly the SL and TP are changing. It is a rate of change measure so when the stops are getting wider this value increases. When they are getting closer it reduces. The number is computed over a fixed window size of 4 bars and is scaled by a constant so that it displays in the output window. The number is proportional to the SL-TP signal. You can also compute this directly from the signal outputs and scale it as you choose.
What is vol?
The volatility is displayed in the panel. It is shown for information purposes only. The formula used is:
Vol=ATR( averaging period ) / Point size.
Volatility is adjusted for trend when a trend setting is used.
Why would a trader look to a signal for a better chance of losing than winning – that is why would anyone set a win ratio less than 50 percent?
The indicator is outputting probabilities based on a market model. With a win ratio less than 50% you also have a profit value that is bigger than the loss value so it can make sense for some strategies.
You can only gain (have positive expectation) when you predict the correct movement of the market over the period of the trade. Otherwise you will have even odds (less actually with spread) regardless of win ratio and where you set your stops/profits.
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. It doesn’t recommend which way to trade. By that it doesn’t tell you to buy or to sell. The stop loss and take profit that is displayed are calculated based on the volatility of the market and, if you choose the trending condition (see market model). These are calculated to reach a certain win ratio. So suppose you are aiming for a 60% win ratio for a 3 day-trade the indicator will tell you where to place the stop and profit for optimum effect.
If I set the target win ratio higher than 0.50 the SL is always greater than the TP. Why can’t I set my stop losses smaller?
Because the numbers won’t work. Assuming a flat market, if you set the target win ratio above 0.50 (50 percent) the SL will be bigger than the TP. If you set the target win ratio less than 0.50 the SL will get smaller and the TP bigger. This holds true if you are using the random walk model.
With the other models there would be a bias depending on the trend direction. The two most important settings are the target trade time and win ratio. If you adjust the win ratio there will be changes in the position of the stop and profits (pip distance).
For example with EURUSD setting the win ratio to 0.35 currently gives an SL=48 pips and TP=72 pips. The win ratio is 24% and lose ratio is 52%. So this means there is 24% chance that after 1 day this trade will close in profit and 52% chance it will close in the red. There is a 24% chance it doesn’t close at all. The “flat” random walk model is unbiased because there is no assumption about trend direction – only on volatility which could swing the market either way.
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 indicator uses the same algorithm as the Excel spreadsheet. There will be some minor differences in the output because not all of the Excel functions are available in Metatrader and so alternatives are used where this is the case.
Probability Trade Wins / Loses / Open or Estimated Win Ratio from the SLTP Advisor:
This is displayed in the panel as p(win), p(lose) and p(open). To display this you will need to switch on the “show panel” option. This output isn’t displayed in the indicator graph because it’s usually the stop loss and take profit which is used in practice. The SL and TP are shown on the signal lines for the buy and sell side. If you look at Metatrader’s Data Window it should show the labels for all outputs.
What does the SLTP Advisor “Target Win Ratio” do?
The target win ratio is the ratio of winning trades to losing trades that the trader wants to achieve. The algorithm uses this number to estimate take profit and stop loss points that will achieve this win ratio. It is a hypothetical number because as explained above it is impossible to guarantee that it will be achieved. Generally a high win ratio will give a wider SL and narrower TP whereas a low win ratio will give narrower stop loss and wider take profit.
Why do the indicator’s values sometimes jump in steps rather than smoothly?
To calculate the probabilities for the maximal curves there is a conversion from a continuous stochastic process to a discrete one. This means you can see step changes in the values of the probabilities as it moves from one discrete interval to the next. That means if volatility is very small or values are at extreme points you can see big incremental changes in p(win) and p(lose).
The “Target Win Ratio” is as it says a target. Since the calculation is made on discrete intervals there may be no solution to a given win ratio so in this case it jumps to the next point.
When I extend the time period why do the probabilities nearly always stay the same?
If you extend the days (time) out it just extends the curve out. The “flat” random walk model is also symmetric. So when the “pip” value increases on both sides (stop and profit) the win ratio stays the same. The ratios are then in nearly equal measures so the probabilities stay the same or close to.
Using a longer averaging period will make the indicator sample a wider time period in the chart. The averaging period should be extended as you extend out the trade time.
Why does the output panel sometimes appear empty or in the wrong place on the chart?
The indicator hasn’t updated because the chart needs to be refreshed. This refreshing usually happens automatically in Metatrader. If it doesn’t just open the indicator’s settings box (Ctrl+I) and click OK.
If the “Target Trade Time” is the same (in minutes) and the win ratio is the same but on a different time frame why are the SL and TP values that the indicator shows different?
To make the results comparable you should also set the averaging period to be the same (in time not bars). But even doing this it would be unlikely to give identical outputs because there is different intra-bar volatility when you go down to a lower time frame (see image below). This detail isn’t taken into consideration at longer time frames.
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:
double buy_sl, buy_tp, sell_sl, sell_tp, roc; buy_sl=iCustom(NULL,PERIOD_CURRENT,”test\myindicator”,0,1); buy_tp=iCustom(NULL,PERIOD_CURRENT,”test\myindicator”,1,1); sell_sl=iCustom(NULL,PERIOD_CURRENT,”test\myindicator”,2,1); sell_tp=iCustom(NULL,PERIOD_CURRENT,”test\myindicator”,3,1); roc=iCustom(NULL,PERIOD_CURRENT,”test\myindicator”,4,1);
Simply replace “test\myindicator” with the name of the indicator in your local Metatrader folder. The above code will use the default parameters. To enter custom parameters, simply enter them as a list after the indicator name.