<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forex Software — (Bug?) Slightly Different GetTrailingStopPrice() code between MT4/5]]></title>
	<link rel="self" href="https://forexsb.com/forum/feed/atom/topic/9071/" />
	<updated>2022-03-22T23:03:30Z</updated>
	<generator>PunBB</generator>
	<id>https://forexsb.com/forum/topic/9071/bug-slightly-different-gettrailingstopprice-code-between-mt45/</id>
		<entry>
			<title type="html"><![CDATA[Re: (Bug?) Slightly Different GetTrailingStopPrice() code between MT4/5]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/68407/#p68407" />
			<content type="html"><![CDATA[<p>Thank you for fixing it.</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2022-03-22T23:03:30Z</updated>
			<id>https://forexsb.com/forum/post/68407/#p68407</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: (Bug?) Slightly Different GetTrailingStopPrice() code between MT4/5]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/68388/#p68388" />
			<content type="html"><![CDATA[<p>The Experts code is updated.</p><p>Thank you again for the report!</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2022-03-21T10:39:38Z</updated>
			<id>https://forexsb.com/forum/post/68388/#p68388</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: (Bug?) Slightly Different GetTrailingStopPrice() code between MT4/5]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/68253/#p68253" />
			<content type="html"><![CDATA[<p>I see, smart idea. Then I will remove it. Many thanks.</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2022-03-10T06:26:27Z</updated>
			<id>https://forexsb.com/forum/post/68253/#p68253</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: (Bug?) Slightly Different GetTrailingStopPrice() code between MT4/5]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/68239/#p68239" />
			<content type="html"><![CDATA[<p>Hello GeekTrader,</p><p>Thank you for the report.<br />Actually the <em>&quot;&amp;&amp; stopLossPrice &lt; bid&quot;</em> should be removed from MT4 code.</p><p>We do the check inside the <strong>if</strong>. <br />If &quot;<em>stopLossPrice &lt; bid</em>&quot; then we set SL. The SL is set to &quot;bid&quot; otherwise.<br />It works in the case of a big gap where the &quot;bid&quot; jumps over SL.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2022-03-09T11:06:11Z</updated>
			<id>https://forexsb.com/forum/post/68239/#p68239</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[(Bug?) Slightly Different GetTrailingStopPrice() code between MT4/5]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/68229/#p68229" />
			<content type="html"><![CDATA[<p>Hi Mr. Popov,</p><p>I´ve noticed that the GetTrailingStopPrice() function between MT4/5 is almost 100% identical, just one line (an extra check) is different. Shouldn´t this extra line from the MT4 function be added to the MT5 function as well?</p><p>MT4 function:</p><div class="codebox"><pre><code>double GetTrailingStopPrice()
  {
   double bid = Bid();
   double ask = Ask();
   double stopLevelPoints = _Point * stopLevel;
   double stopLossPoints  = pip * Stop_Loss;

   if (posType == OP_BUY)
     {
      double stopLossPrice = High[1] - stopLossPoints;
      if (posStopLoss &lt; stopLossPrice - pip &amp;&amp; stopLossPrice &lt; bid)
         return stopLossPrice &lt; bid
                 ? stopLossPrice &gt;= bid - stopLevelPoints
                    ? bid - stopLevelPoints
                    : stopLossPrice
                 : bid;
     }

   if (posType == OP_SELL)
     {
      double stopLossPrice = Low[1] + stopLossPoints;
      if (posStopLoss &gt; stopLossPrice + pip)
         return stopLossPrice &gt; ask
                 ? stopLossPrice &lt;= ask + stopLevelPoints
                    ? ask + stopLevelPoints
                    : stopLossPrice
                 : ask;
     }

   return posStopLoss;
  }</code></pre></div><p>MT5 function:</p><div class="codebox"><pre><code>double GetTrailingStopPrice()
  {
   double bid = Bid();
   double ask = Ask();
   double stopLevelPoints = _Point * stopLevel;
   double stopLossPoints  = pip * Stop_Loss;

   if (posType == OP_BUY)
     {
      double stopLossPrice = High(1) - stopLossPoints;
      if (posStopLoss &lt; stopLossPrice - pip)
         return stopLossPrice &lt; bid
                  ? stopLossPrice &gt;= bid - stopLevelPoints
                     ? bid - stopLevelPoints
                     : stopLossPrice
                  : bid;
     }

   if (posType == OP_SELL)
     {
      double stopLossPrice = Low(1) + stopLossPoints;
      if (posStopLoss &gt; stopLossPrice + pip)
         return stopLossPrice &gt; ask
                  ? stopLossPrice &lt;= ask + stopLevelPoints
                     ? ask + stopLevelPoints
                     : stopLossPrice
                  : ask;
     }

   return posStopLoss;
  }</code></pre></div><p>The difference is in this line (MT4) which is missing in MT5:</p><div class="codebox"><pre><code>      if (posStopLoss &lt; stopLossPrice - pip &amp;&amp; stopLossPrice &lt; bid)</code></pre></div><p>I think that extra check &quot;&amp;&amp; stopLossPrice &lt; bid&quot; should be added to the MT5 function as well?</p><p>Thank you :-)</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2022-03-09T00:37:37Z</updated>
			<id>https://forexsb.com/forum/post/68229/#p68229</id>
		</entry>
</feed>
