<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forex Software — Possible logical error in MQ4 code for session management]]></title>
	<link rel="self" href="https://forexsb.com/forum/feed/atom/topic/7523/" />
	<updated>2019-01-08T21:19:36Z</updated>
	<generator>PunBB</generator>
	<id>https://forexsb.com/forum/topic/7523/possible-logical-error-in-mq4-code-for-session-management/</id>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/53690/#p53690" />
			<content type="html"><![CDATA[<p>Just to make this complete: this bug has been fixed today by Popov. Thank you :-)</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2019-01-08T21:19:36Z</updated>
			<id>https://forexsb.com/forum/post/53690/#p53690</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/53507/#p53507" />
			<content type="html"><![CDATA[<p>Popov, can you do something about it please? It really is unreliable because the backtests in EAS / MT4 differ because of that issue and EAS finds strategies that won´t work live because it ignores the session times for the exits. Thanks so much :-)</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-12-31T07:40:13Z</updated>
			<id>https://forexsb.com/forum/post/53507/#p53507</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/53087/#p53087" />
			<content type="html"><![CDATA[<p>Just checked and the bug is still there :-(</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-11-28T06:22:47Z</updated>
			<id>https://forexsb.com/forum/post/53087/#p53087</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52632/#p52632" />
			<content type="html"><![CDATA[<p>Hi Popov,</p><p>has this been fixed already in one of the latest updates? Just wondering.</p><p>Thanks.</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-10-19T03:04:59Z</updated>
			<id>https://forexsb.com/forum/post/52632/#p52632</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52422/#p52422" />
			<content type="html"><![CDATA[<p>Here is another example comparing the EA Studio backtest (Session is again 01:00 - 23:58) to the exported MQ4, as you can see, EA Studio closes at 00:00 (inside the &quot;forbidden time&quot;), MT4 closes (correctly) at 05:00:</p><p><a href="https://ibb.co/madHBz"><span class="postimg"><img src="https://preview.ibb.co/e9q8Je/picture04.jpg" alt="https://preview.ibb.co/e9q8Je/picture04.jpg" /></span></a></p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-10-01T17:45:08Z</updated>
			<id>https://forexsb.com/forum/post/52422/#p52422</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52421/#p52421" />
			<content type="html"><![CDATA[<p>Here is the example. The strategy (on H1) used is just a dummy I´ve thrown together (unprofitable), you can recreate it with any strategy that trades something really.</p><p>Settings show that the session is from 01:00 to 23:58:</p><p><a href="https://ibb.co/dhXo1z"><span class="postimg"><img src="https://preview.ibb.co/iztHuK/picture01.jpg" alt="https://preview.ibb.co/iztHuK/picture01.jpg" /></span></a></p><p>While it never enters trades at 00:00 (which is correct), it closes trades at 00:00 several times:</p><p><a href="https://ibb.co/nRnAEK"><span class="postimg"><img src="https://preview.ibb.co/b7mRoe/picture02.jpg" alt="https://preview.ibb.co/b7mRoe/picture02.jpg" /></span></a></p><p>As already noticed, in the exported MQ4 code of such strategies, it never closes trades at 00:00 because the session check is implemented correctly there.</p><p>Let me know if you need more information. Thanks <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-10-01T17:36:20Z</updated>
			<id>https://forexsb.com/forum/post/52421/#p52421</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52408/#p52408" />
			<content type="html"><![CDATA[<p>Hi :-) I will do that this evening most likely and post it here.</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-10-01T09:26:33Z</updated>
			<id>https://forexsb.com/forum/post/52408/#p52408</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52404/#p52404" />
			<content type="html"><![CDATA[<p>GeekTrader, I cannot reproduce the issue.</p><p>Please make a screenshot of the &quot;Trading session&quot; page and attach a simple expert for further examination.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2018-10-01T06:56:13Z</updated>
			<id>https://forexsb.com/forum/post/52404/#p52404</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52350/#p52350" />
			<content type="html"><![CDATA[<p>Possibly that would make the most sense to fix it in EA Studio, although that will &quot;screw up&quot; some of my existing strategies....</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-09-24T16:02:05Z</updated>
			<id>https://forexsb.com/forum/post/52350/#p52350</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52347/#p52347" />
			<content type="html"><![CDATA[<p>Interesting observation!</p><p>Probably it is better to fix the EA Studio behaviour.</p><p>I&#039;m planning an update next week. I&#039;ll try to fix that also. </p><p>Thank you for the report!</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2018-09-24T12:36:38Z</updated>
			<id>https://forexsb.com/forum/post/52347/#p52347</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Possible logical error in MQ4 code for session management]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52342/#p52342" />
			<content type="html"><![CDATA[<p>Hi Mr. Popov,</p><p>I´ve noticed that EA Studio backtests (in the App) still close positions if the exit indicator has given an exit signal, even if it´s outside of the session. For example, my sessions always start at 00:05 and EA Studio (app) hence never opens any position at 00:00 - which is correct. However, it still closes positions at 00:00 in the backtest. I am OK with that, but the exported MQ4´s act different, they do not exit outside of the session because the session check comes before the close check in the MQ4 code, see:</p><div class="codebox"><pre><code>void OnBar()
  {
   UpdatePosition();

   if(posType!=OP_FLAT &amp;&amp; IsForceSessionClose())
     {
      ClosePosition();
      return;
     }

   if(IsOutOfSession())
      return;

   if(posType!=OP_FLAT)
     {
      ManageClose();
      UpdatePosition();
     }

   if(posType!=OP_FLAT &amp;&amp; isTrailingStop)
     {
      double trailingStop=GetTrailingStop();
      ManageTrailingStop(trailingStop);
      UpdatePosition();
     }

   if(posType==OP_FLAT)
     {
      ManageOpen();
      UpdatePosition();
     }
  }</code></pre></div><p>To make it match the backtest behavior of the EA Studio backtests, it would have to be:</p><div class="codebox"><pre><code>void OnBar()
  {
   UpdatePosition();

   if(posType!=OP_FLAT &amp;&amp; IsForceSessionClose())
     {
      ClosePosition();
      return;
     }

   if(posType!=OP_FLAT)
     {
      ManageClose();
      UpdatePosition();
     }

   if(posType!=OP_FLAT &amp;&amp; isTrailingStop)
     {
      double trailingStop=GetTrailingStop();
      ManageTrailingStop(trailingStop);
      UpdatePosition();
     }


   if(IsOutOfSession())
      return;

   if(posType==OP_FLAT)
     {
      ManageOpen();
      UpdatePosition();
     }
  }</code></pre></div><br /><p>If the session check is done like this in the MQ4 code, it will replicate the behavior of EA Studio backtests correctly.</p><br /><p>Thank you,</p><p>Geek</p>]]></content>
			<author>
				<name><![CDATA[geektrader]]></name>
				<uri>https://forexsb.com/forum/user/1841/</uri>
			</author>
			<updated>2018-09-24T08:53:34Z</updated>
			<id>https://forexsb.com/forum/post/52342/#p52342</id>
		</entry>
</feed>
