<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — Question about Bar Closing indicator]]></title>
		<link>https://forexsb.com/forum/topic/3246/question-about-bar-closing-indicator/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/3246/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Question about Bar Closing indicator.]]></description>
		<lastBuildDate>Wed, 25 Apr 2012 00:44:27 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Question about Bar Closing indicator]]></title>
			<link>https://forexsb.com/forum/post/14161/#p14161</link>
			<description><![CDATA[<p>Popov,</p><p>Thank you so much. That code is very helpful.</p>]]></description>
			<author><![CDATA[null@example.com (eshapard)]]></author>
			<pubDate>Wed, 25 Apr 2012 00:44:27 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/14161/#p14161</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about Bar Closing indicator]]></title>
			<link>https://forexsb.com/forum/post/14157/#p14157</link>
			<description><![CDATA[<p>I found some old source code of an expert where I tested bar opening and bar closing in MQL4</p><div class="codebox"><pre><code>bool bIsFirstTick;// It is used to catch the Bar Opening.
datetime dtCurrentBarOpeningTime;

int init()
{
   bIsFirstTick = false;
   dtCurrentBarOpeningTime = Time[0];
   return(0);
}

int start()
{
   // Is this the first tick for the bar
   bIsFirstTick = (dtCurrentBarOpeningTime != Time[0]);
   if(bIsFirstTick)
   {
      dtCurrentBarOpeningTime = Time[0];
   }

...
...



///
/// Exit at a Bar Closing price (almost).
///
/// MetaTrader does not provide an onBarClose event so we are not able to close a position
/// exactly at Bar Closing. We workaround the problem by closing the position within a time span
/// near to the bar closing time. In the cases when there is no any ticks within this period,
/// we close the position att he next bar opening price.
///
int ClosePositionsAtBarClosing(bool bCloseLong, bool bCloseShort, datetime dtClosingTimeSpan)
{
   int  iOrders = OrdersTotal();
   bool bIsOpen = false;

   for(int iOrder = 0; iOrder &lt; iOrders; iOrder++)
   {
      OrderSelect(iOrder, SELECT_BY_POS, MODE_TRADES);
      
      if((OrderType() == OP_BUY || OrderType() == OP_SELL) &amp;&amp; OrderSymbol() == Symbol())
      {  // There is an open position for this symbol.

         datetime dtOpeningTime     = Time[0] - TimeSeconds(Time[0]); // The opening time of current bar
         datetime dtClosingTime     = dtOpeningTime + Period() * 60;  // The closing time of current bars
         datetime dtCurrentTickTime = TimeCurrent() ;                 // The time of current tick
         
         if(dtCurrentTickTime &gt; dtClosingTime - dtClosingTimeSpan ||  bIsFirstTick)
         {  // The current tick is within the closing time span or this is the first tick of the bar.

            // Code

         }
       }
    }
}</code></pre></div><p>The full code is attached.<br />Use at your own risk. Not supported!</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Wed, 25 Apr 2012 00:19:03 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/14157/#p14157</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about Bar Closing indicator]]></title>
			<link>https://forexsb.com/forum/post/14155/#p14155</link>
			<description><![CDATA[<p>Ah, I see.</p><p>I figured it was a timing issue and it tried to enter close to the end time for the bar.</p><p>Anyone know how to script this functionality in mt4? is there an mt4 indicator for this?</p>]]></description>
			<author><![CDATA[null@example.com (eshapard)]]></author>
			<pubDate>Tue, 24 Apr 2012 22:39:49 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/14155/#p14155</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about Bar Closing indicator]]></title>
			<link>https://forexsb.com/forum/post/14153/#p14153</link>
			<description><![CDATA[<p>FST enters 3 seconds before bar closing. This period is adjustable from Trade Settings window.</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Tue, 24 Apr 2012 22:13:12 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/14153/#p14153</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about Bar Closing indicator]]></title>
			<link>https://forexsb.com/forum/post/14152/#p14152</link>
			<description><![CDATA[<p>Bar Closing will enter the position up to 5 secs before the bar closes. It assumes the price at that time is the price that the bar will actually close at and calculate the indicators accordingly. Unless something dramatic happens during the last few seconds this price will be very close to the actual bar closing price. </p><p>Since Forex is 24 hours there shouldn&#039;t be much difference between&nbsp; closing and opening prices except at the weekend. </p><p>Use of Bar Closing might be a good way to enter a trade over the weekend if you are that way inclined.</p>]]></description>
			<author><![CDATA[null@example.com (SpiderMan)]]></author>
			<pubDate>Tue, 24 Apr 2012 22:12:55 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/14152/#p14152</guid>
		</item>
		<item>
			<title><![CDATA[Re: Question about Bar Closing indicator]]></title>
			<link>https://forexsb.com/forum/post/14149/#p14149</link>
			<description><![CDATA[<p>No answer yet?</p><p>This seems like an important point. I don&#039;t see how you could reliably enter at bar closing. The problem here is that you cannot know what the last tick of a bar is. Depending on liquidity, the last tick might come milliseconds or even minutes before the end of the bar.</p>]]></description>
			<author><![CDATA[null@example.com (eshapard)]]></author>
			<pubDate>Tue, 24 Apr 2012 21:17:17 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/14149/#p14149</guid>
		</item>
		<item>
			<title><![CDATA[Question about Bar Closing indicator]]></title>
			<link>https://forexsb.com/forum/post/14091/#p14091</link>
			<description><![CDATA[<p>I&#039;ve come accross some strategies with FSB that open a trade at the end of the bar.</p><p>Looking back at historical prices, you can just find the closing price of a bar. But how does it work in live trading?</p><p>Does the indicator somehow tell you when the bar is about to close during live trading?</p><p>Is there an mt4 indicator for this? I&#039;d like to experiment with scripting some EAs to trade the strategies that FSB uncovers, but I have no idea how to script the EA to enter at the end of the bar without cheating by looking ahead at the closing price.</p><p>Thanks,<br />Ed</p>]]></description>
			<author><![CDATA[null@example.com (eshapard)]]></author>
			<pubDate>Sun, 22 Apr 2012 20:54:04 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/14091/#p14091</guid>
		</item>
	</channel>
</rss>
