Introduction to stop loss and take profit

Forex, stock, and cryptocurrency traders all require managing risk and accumulating profits by employing stop loss and take profit. When used correctly, stop loss and take profit can maximize profits and minimize losses. A forex trader uses a stop loss to limit the potential for losses on a trade. This is a predetermined price at which the forex trader will automatically exit a trade if the market moves against them. It helps to minimise losses and prevent the trader from losing more money than they are prepared to risk. Take profit, on the other hand, is used by an investors to lock in profits on a trade. To protect profits, the forex trader will automatically exit a trade if the market moves in favour of them. To make the most of risk reduction, stop loss and take profit orders must work in conjunction with each other. By setting both a stop loss and a take profit order, traders can limit their potential losses while also securing profits.

One of the most frequently asked questions I get from my blog readers is how to handle market spread when opening new orders using MetaTrader platform. So in this section I will try to illustrate how I handle Spread vs Stop Loss and Take Profit levels. So let’s first look in the MQL4 manual (MQL4 is the programming language of MT4).

Source: https://docs.mql4.com/trading/ordersend
ordersend with stop loss and take profit

stop loss and take profit example 1
stop loss and take profit example 1

In the example above a ‘Buy’ order is opened at ‘Ask’ price, with a StopLoss and TakeProfit levels equal to minimum allowed StopLoss distance from the current ‘Bid’ price. Using the ‘Bid’ price as reference for SL/TP levels, is the recommended way of opening orders, but is this really the best way?..So it depends on your risk-reward ratio. Most of my own trading systems require a risk-reward of 1:1, so for example: StopLoss = 10 Pips and TakeProfit = 10 Pips. Let’s see what would happen if I have followed recommendation from the MT4 manual and used ‘Bid’ price as reference point for my TP and SL levels:

In this configuration, with assumed spread of 2 Pips, my EA would make only 8 Pips hitting profit and would loss 12 Pips when hitting my StopLoss level. If my trading system had a 50% winning ratio I would be only losing my money!

So how to deal with spread when placing stop loss and take profit?

stop loss and take profit example 2
stop loss and take profit example 2

The answer is very simple: Always use your entry price as SL and TP reference. This means using ‘Ask’ for Buy orders and ‘Bid’ levels for ‘Sell’ orders. In this configuration the EA will always win and lose the same amount of money. Using this approach you need only a winning ratio of 51% in order to be profitable on the long term. (this of course not including slippages and broker commissions).

However, there is a big ‘BUT’ for this strategy! You should avoid spread widening, which can be introduced by your broker e.g.: during high volatile events like market news release. The code below show how to avoid spread widening and how to set SL and TP using entry levels.


bool OpenBuy()
{
   //Get new market prices
   RefreshRates();
   
   //Define lot size
   double Lots = 0.1;
   int LotDigits = (int) - MathLog10(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP));
   double LotSize=NormalizeDouble(Lots,LotDigits); 
   
   //Calculate and check spread  
   double MaxSpreadInPoints = 50; 
   double Spread = Ask - Bid;
   if(Spread>MaxSpreadInPoints*Point)
      return(false);
   
   //Define allowed slippage
   int SlippageInPoints = 20;
   
   //Define TakeProfit and StopLoss levels 
   double TakeProfit = NormalizeDouble(Bid+Spread+10*PIP,Digits);
   double StopLoss = NormalizeDouble(Bid+Spread-10*PIP,Digits);;

   Ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,SlippageInPoints,StopLoss,TakeProfit,"Spread Test",MagicNr,0,Green);
   
   if(Ticket==-1)
   {
      Alert("Buy Error: " ,GetLastError());
      return(false); 
   }
   if(Ticket>=0)
   {
      return(true);
   }
   
   return(false);
}

bool OpenSell()
{
   //Get new market prices
   RefreshRates();
   
   //Define lot size
   double Lots = 0.1;
   int LotDigits = (int) - MathLog10(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP));
   double LotSize=NormalizeDouble(Lots,LotDigits); 
   
   //Calculate and check spread  
   double MaxSpreadInPoints = 50; 
   double Spread = Ask - Bid;
   if(Spread>MaxSpreadInPoints*Point)
      return(false);
   
   //Define allowed slippage
   int SlippageInPoints = 20;
   
   //Define TakeProfit and StopLoss levels 
   double TakeProfit = NormalizeDouble(Bid-10*PIP,Digits);
   double StopLoss = NormalizeDouble(Bid+10*PIP,Digits);;

   Ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,SlippageInPoints,StopLoss,TakeProfit,"Spread Test",MagicNr,0,Red);
   
   if(Ticket==-1)
   {
      Alert("Sell Error: " ,GetLastError());
      return(false); 
   }
   if(Ticket>=0)
   {
      return(true);
   }
   
   return(false);
}	

 

As you can see only ‘Buy’ orders need an additional entry level correction, since ‘Sell’ orders are using ‘Bid’ as entry price. The following figure shows the outcome of this approach:
1:1 risk-reward example
The EA based on this strategy always wins and losses equal amount of money, which in this example is equal to $10.

That’s it;) If you want to learn more about my trading read my blog.

Greets,
Chris


[DISCLAIMER]: This site contains valuable and informative high quality material, that can be used for any kind of trading. The presented information is meant for non-commercial, informational and personal purposes only, and all of freely downloadable materials are meant for non-commercial home use only. To the maximum extent permitted by applicable law, in no event shall Coensio.com, or its suppliers be liable for any special, incidental, indirect, or consequential damages whatsoever (including, without limitation, damages for loss of business time, business profits, business information, or any other kind of loss) arising out of the use of, or inability to use the Software developed by coensio.com, or the failure to provide support services, even if Software, or one of its supplies has been advised of the possibility of such damages. Copyright © 2021 coensio.com. The majority of the links in coensio.com posts and sidebar are affiliate program links. This means that (most of the time) when you purchase a product linked from my site, owner(s) of this website receive a commission. CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN. [OUR PRIVACY POLICY]: READ HERE