<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — StopLoss Checking]]></title>
		<link>https://forexsb.com/forum/topic/8973/stoploss-checking/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/8973/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in StopLoss Checking.]]></description>
		<lastBuildDate>Mon, 29 Nov 2021 23:22:18 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: StopLoss Checking]]></title>
			<link>https://forexsb.com/forum/post/67059/#p67059</link>
			<description><![CDATA[<p>Change ENUM_ORDER_TYPE with OrderDirection</p><br /><div class="codebox"><pre><code>bool CheckStopLoss_Takeprofit(OrderDirection type, double SL, double TP)
  {
   ...
   switch(type)
     {
      case  ORDER_DIRECTION_BUY:
        ...
      case  ORDER_DIRECTION_SELL:
        ...
      break;
     }
   ...
  }</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Mon, 29 Nov 2021 23:22:18 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/67059/#p67059</guid>
		</item>
		<item>
			<title><![CDATA[Re: StopLoss Checking]]></title>
			<link>https://forexsb.com/forum/post/67057/#p67057</link>
			<description><![CDATA[<p>thanks for reply...signal.Direction doesnt work cause function need enum.</p><div class="codebox"><pre><code>bool CheckStopLoss_Takeprofit(ENUM_ORDER_TYPE type,double SL,double TP)</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Roughey)]]></author>
			<pubDate>Mon, 29 Nov 2021 21:15:29 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/67057/#p67057</guid>
		</item>
		<item>
			<title><![CDATA[Re: StopLoss Checking]]></title>
			<link>https://forexsb.com/forum/post/67056/#p67056</link>
			<description><![CDATA[<p>The Portfolio Expert calculates the correct SL and TP for each entry.<br />Please see the GetStopLossPrice and GetTakeProfitPrice functions.<br />You don&#039;t need to check them further.</p><p>Anyway, the problem with your code is that you check SL and TP against <strong>both</strong> long and short positions.<br /></p><div class="codebox"><pre><code>   if(!CheckStopLoss_Takeprofit(ORDER_TYPE_BUY,stopLoss,takeProfit)) return;
   if(!CheckStopLoss_Takeprofit(ORDER_TYPE_SELL,stopLoss,takeProfit)) return;</code></pre></div><p> Imagine that the order is for a Long entry. The first function call will check the SL and TP and will continue. However, the second call will check the SL and TP if it was a short entry, but it is not. So, it will give an error every time.</p><p>You have to call your check only once with the correct position direction. The correct way is:<br /></p><div class="codebox"><pre><code>   if ( !CheckStopLoss_Takeprofit(signal.Direction, stopLoss, takeProfit) ) return;</code></pre></div><p>But, as I said before, it is pointless in that case because the GetStopLossPrice and GetTakeProfitPrice do the same.</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Mon, 29 Nov 2021 20:48:02 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/67056/#p67056</guid>
		</item>
		<item>
			<title><![CDATA[StopLoss Checking]]></title>
			<link>https://forexsb.com/forum/post/67055/#p67055</link>
			<description><![CDATA[<p>Hi,</p><p>i want to let check my SL and TP before sending an Order. Cause some brokers make trouble that ea not working correctly.</p><p>I have found this on mql site. This is the function:<br /></p><div class="codebox"><pre><code>bool CheckStopLoss_Takeprofit(ENUM_ORDER_TYPE type,double SL,double TP)
  {
//--- get the SYMBOL_TRADE_STOPS_LEVEL level
   int stops_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
   if(stops_level!=0)
     {
      PrintFormat(&quot;SYMBOL_TRADE_STOPS_LEVEL=%d: StopLoss and TakeProfit must&quot;+
                  &quot; not be nearer than %d points from the closing price&quot;,stops_level,stops_level);
     }
//---
   bool SL_check=false,TP_check=false;
//--- check only two order types
   switch(type)
     {
      //--- Buy operation
      case  ORDER_TYPE_BUY:
        {
         //--- check the StopLoss
         SL_check=(Bid-SL&gt;stops_level*_Point);
         if(!SL_check)
            PrintFormat(&quot;For order %s StopLoss=%.5f must be less than %.5f&quot;+
                        &quot; (Bid=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d points)&quot;,
                        EnumToString(type),SL,Bid-stops_level*_Point,Bid,stops_level);
         //--- check the TakeProfit
         TP_check=(TP-Bid&gt;stops_level*_Point);
         if(!TP_check)
            PrintFormat(&quot;For order %s TakeProfit=%.5f must be greater than %.5f&quot;+
                        &quot; (Bid=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d points)&quot;,
                        EnumToString(type),TP,Bid+stops_level*_Point,Bid,stops_level);
         //--- return the result of checking
         return(SL_check&amp;&amp;TP_check);
        }
      //--- Sell operation
      case  ORDER_TYPE_SELL:
        {
         //--- check the StopLoss
         SL_check=(SL-Ask&gt;stops_level*_Point);
         if(!SL_check)
            PrintFormat(&quot;For order %s StopLoss=%.5f must be greater than %.5f &quot;+
                        &quot; (Ask=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d points)&quot;,
                        EnumToString(type),SL,Ask+stops_level*_Point,Ask,stops_level);
         //--- check the TakeProfit
         TP_check=(Ask-TP&gt;stops_level*_Point);
         if(!TP_check)
            PrintFormat(&quot;For order %s TakeProfit=%.5f must be less than %.5f &quot;+
                        &quot; (Ask=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d points)&quot;,
                        EnumToString(type),TP,Ask-stops_level*_Point,Ask,stops_level);
         //--- return the result of checking
         return(TP_check&amp;&amp;SL_check);
        }
      break;
     }
//--- a slightly different function is required for pending orders
   return false;
  }</code></pre></div><p>and in Portfolio MT5 i add this before order send:<br /></p><div class="codebox"><pre><code>void OpenPosition(Signal &amp;signal)
  {     
   int    command    = OrderDirectionToCommand(signal.Direction);
   double stopLoss   = GetStopLossPrice(command,   signal.StopLossPips);
   double takeProfit = GetTakeProfitPrice(command, signal.TakeProfitPips);

//--- This is to see in Journal what TP &amp; SL i have
   Print(&quot;SL:&quot;+DoubleToString(stopLoss,_Digits)+&quot;TP:&quot;+DoubleToString(takeProfit,_Digits));

   if(!CheckStopLoss_Takeprofit(ORDER_TYPE_BUY,stopLoss,takeProfit)) return;
   if(!CheckStopLoss_Takeprofit(ORDER_TYPE_SELL,stopLoss,takeProfit)) return;
   ManageOrderSend(command, Entry_Amount, stopLoss, takeProfit, 0, signal.MagicNumber);
  }</code></pre></div><br /><p>In Journal in get such Mistakes an no order send.</p><div class="codebox"><pre><code>2021.11.29 20:54:44.136    Core 1    2020.03.09 11:00:00   SL:1.13446TP:1.14796
2021.11.29 20:54:44.136    Core 1    2020.03.09 11:00:00   For order ORDER_TYPE_SELL StopLoss=1.13446 must be greater than 1.14387  (Ask=1.14387 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 11:00:00   For order ORDER_TYPE_SELL TakeProfit=1.14796 must be less than 1.14387  (Ask=1.14387 - SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 11:00:00   SL:1.13066TP:1.14976
2021.11.29 20:54:44.136    Core 1    2020.03.09 11:00:00   For order ORDER_TYPE_SELL StopLoss=1.13066 must be greater than 1.14387  (Ask=1.14387 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 11:00:00   For order ORDER_TYPE_SELL TakeProfit=1.14976 must be less than 1.14387  (Ask=1.14387 - SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 17:00:00   SL:1.12091TP:1.15611
2021.11.29 20:54:44.136    Core 1    2020.03.09 17:00:00   For order ORDER_TYPE_SELL StopLoss=1.12091 must be greater than 1.14013  (Ask=1.14013 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 17:00:00   For order ORDER_TYPE_SELL TakeProfit=1.15611 must be less than 1.14013  (Ask=1.14013 - SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 17:00:00   SL:1.12251TP:1.14431
2021.11.29 20:54:44.136    Core 1    2020.03.09 17:00:00   For order ORDER_TYPE_SELL StopLoss=1.12251 must be greater than 1.14013  (Ask=1.14013 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 17:00:00   For order ORDER_TYPE_SELL TakeProfit=1.14431 must be less than 1.14013  (Ask=1.14013 - SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 22:00:00   SL:1.12902TP:1.16212
2021.11.29 20:54:44.136    Core 1    2020.03.09 22:00:00   For order ORDER_TYPE_SELL StopLoss=1.12902 must be greater than 1.14614  (Ask=1.14614 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 22:00:00   For order ORDER_TYPE_SELL TakeProfit=1.16212 must be less than 1.14614  (Ask=1.14614 - SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 22:00:00   SL:1.12852TP:1.15032
2021.11.29 20:54:44.136    Core 1    2020.03.09 22:00:00   For order ORDER_TYPE_SELL StopLoss=1.12852 must be greater than 1.14614  (Ask=1.14614 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 20:54:44.136    Core 1    2020.03.09 22:00:00   For order ORDER_TYPE_SELL TakeProfit=1.15032 must be less than 1.14614  (Ask=1.14614 - SYMBOL_TRADE_STOPS_LEVEL=0 points)</code></pre></div><p>Can someone help me out? I dont know why?</p><br /><p>when i look directly into stoploss and takeprofit without the digit.</p><p>&nbsp; &nbsp;Print(&quot;SL:&quot;+DoubleToString(stopLoss)+&quot;TP:&quot;+DoubleToString(takeProfit));</p><p>this in journal<br /></p><div class="codebox"><pre><code>2021.11.29 21:23:52.953    Core 1    2020.05.07 23:00:00   SL:1.06365000TP:1.09685000
2021.11.29 21:23:52.953    Core 1    2020.05.07 23:00:00   For order ORDER_TYPE_SELL StopLoss=1.06365 must be greater than 1.08297  (Ask=1.08297 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 21:23:52.953    Core 1    2020.05.07 23:00:00   For order ORDER_TYPE_SELL TakeProfit=1.09685 must be less than 1.08297  (Ask=1.08297 - SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 21:23:52.953    Core 1    2020.05.07 23:00:00   SL:1.07185000TP:1.08905000
2021.11.29 21:23:52.953    Core 1    2020.05.07 23:00:00   For order ORDER_TYPE_SELL StopLoss=1.07185 must be greater than 1.08297  (Ask=1.08297 + SYMBOL_TRADE_STOPS_LEVEL=0 points)
2021.11.29 21:23:52.953    Core 1    2020.05.07 23:00:00   For order ORDER_TYPE_SELL TakeProfit=1.08905 must be less than 1.08297  (Ask=1.08297 - SYMBOL_TRADE_STOPS_LEVEL=0 points)</code></pre></div><br /><p>Are there too much digits????</p>]]></description>
			<author><![CDATA[null@example.com (Roughey)]]></author>
			<pubDate>Mon, 29 Nov 2021 20:11:14 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/67055/#p67055</guid>
		</item>
	</channel>
</rss>
