<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Cubesteak Central &#187; MT4 Tips</title>
	<atom:link href="http://www.cubesteak.net/category/mt4/mt4-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cubesteak.net</link>
	<description>Forex Trading with MetaTrader 4</description>
	<pubDate>Sat, 02 Dec 2006 03:21:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
	<language>en</language>
			<item>
		<title>Adding a Magic Number to an EA</title>
		<link>http://www.cubesteak.net/2006/10/adding-a-magic-number-to-an-ea/</link>
		<comments>http://www.cubesteak.net/2006/10/adding-a-magic-number-to-an-ea/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 07:04:43 +0000</pubDate>
		<dc:creator>cubesteak</dc:creator>
		
		<category><![CDATA[MT4]]></category>

		<category><![CDATA[MT4 Tips]]></category>

		<guid isPermaLink="false">http://www.cubesteak.net/2006/10/adding-a-magic-number-to-an-ea/</guid>
		<description><![CDATA[Someone asked me if there was a manual on how to add a Magic Number to an EA.  Since I haven’t seen one, I put together the following basic steps
and thought that others may find it useful too.  These steps can also be used to verify that an EA properly uses a Magic [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial; color: black">Someone asked me if there was a manual on how to add a Magic Number to an EA.  <span />Since I haven’t seen one, I put together the following basic steps<br />
and thought that others may find it useful too.  These steps can also be used to verify that an EA properly uses a Magic Number, as some don’t!  </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial; color: black">First off, to the completely uninitiated, a Magic Number is simply an arbitrary number that can be added to an EA that is used to uniquely identify trades that are made from that EA with an eye towards differentiating them from trades made by any other EA.  Without a Magic Number, a EA that closes all orders will not only close orders that it has made, but it will also close any orders made by a different EA, and it will even close orders that were made manually, as it has no way of telling which orders came from which EA.</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial; color: black">This obviously is not an optimal situation.  The Magic Number lets you differentiate these orders programatically so that you can run multiple EA&#8217;s on multiple charts from within the same MT4 instance and still be able to trade manually as well.<br />
</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial; color: black">Anyway, now on to the steps:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial; color: black">1) On a global level in the EA add:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial" /><span style="font-size: 10pt">int MagicNumber = 233423;  // where 233423 is any old number that is unique from any of your other running EA’s<br />
</span><span style="font-size: 10pt; font-family: Arial" /></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">The easiest way to describe declaring on the &#8220;global level&#8221; of the EA is a variable that is declared outside of the</span><span style="font-size: 10pt"> Start, Init </span><span style="font-size: 10pt; font-family: Arial">and</span><span style="font-size: 10pt"> Deinit </span><span style="font-size: 10pt; font-family: Arial">functions</span><span style="font-size: 10pt">.  </span><span style="font-size: 10pt; font-family: Arial">The easiest way to ensure that you are on the global level of the EA is to put the</span><span style="font-size: 10pt"> MagicNumber </span><span style="font-size: 10pt; font-family: Arial">declaration immediately after the top comments and any</span><span style="font-size: 10pt"> #property, #include </span><span style="font-size: 10pt; font-family: Arial">or</span><span style="font-size: 10pt"> #import </span><span style="font-size: 10pt; font-family: Arial">statements and BEFORE the</span><span style="font-size: 10pt"> Init, Deinit </span><span style="font-size: 10pt; font-family: Arial">and</span><span style="font-size: 10pt"> Start </span><span style="font-size: 10pt; font-family: Arial">functions.</span><span style="font-size: 10pt"><br />
</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">2) Next, make sure that the </span><span style="font-size: 10pt">OrderSend </span><span style="font-size: 10pt; font-family: Arial">function uses this magic number.  </span><span style="font-size: 10pt">OrderSend </span><span style="font-size: 10pt; font-family: Arial">uses the following form:</span><span style="font-size: 10pt" /></p>
<p class="MsoNormal"><span style="font-size: 10pt">int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">So, you want to make sure that it is called with the </span><span style="font-size: 10pt">MagicNumber </span><span style="font-size: 10pt; font-family: Arial">in it, e.g:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt">OrderSend(Symbol(),OP_BUY,1.0,Ask,2,10,20,&#8221;My Buy&#8221;,MagicNumber,0,Lime)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">3) Then, search the EA for each instance of </span><span style="font-size: 10pt">OrderClose, OrderModify </span><span style="font-size: 10pt; font-family: Arial">or</span><span style="font-size: 10pt"> OrderDelete.  </span><span style="font-size: 10pt; font-family: Arial">Usually these are sandwiched by at least one IF statement.  Add to that IF statement the following condition:  </span><span style="font-size: 10pt">(OrderMagicNumber() == MagicNumber)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">So, something like this:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt">if (OrderSymbol == Symbol())<br />
{<br />
OrderClose(blah blah&#8230;);<br />
} </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">Becomes:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt">if (OrderSymbol == Symbol() &#038;&#038;<br />
OrderMagicNumber() == MagicNumber)<br />
{<br />
OrderClose(blah blah blah);<br />
}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">Voila!  Your EA now uses a magic number and should be able to trade with other EAs.</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">Please note that any money management that an EA uses, like lot optimization based on available margin or equity, etc. will also &#8220;interfere&#8221; with each other.  This is either desirable or undesirable based upon how you want to trade with the specific EA&#8217;s. </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Arial">Hope that helps!</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubesteak.net/2006/10/adding-a-magic-number-to-an-ea/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to debug custom DLL&#8217;s with MT4</title>
		<link>http://www.cubesteak.net/2006/08/how-to-debug-custom-dlls-with-mt4/</link>
		<comments>http://www.cubesteak.net/2006/08/how-to-debug-custom-dlls-with-mt4/#comments</comments>
		<pubDate>Wed, 09 Aug 2006 09:18:09 +0000</pubDate>
		<dc:creator>cubesteak</dc:creator>
		
		<category><![CDATA[MT4 Tips]]></category>

		<guid isPermaLink="false">http://www.cubesteak.net/2006/08/how-to-debug-custom-dlls-with-mt4/</guid>
		<description><![CDATA[It could be that I&#8217;m just dense and this was readily apparent to everyone else,  but I&#8217;ll post this anyway for the sake of community.  For those of you who would like to know how to use Visual Studio to debug your custom dll, do the following - I&#8217;ll use the example of [...]]]></description>
			<content:encoded><![CDATA[<p>It could be that I&#8217;m just dense and this was readily apparent to everyone else,  but I&#8217;ll post this anyway for the sake of community.  For those of you who would like to know how to use Visual Studio to debug your custom dll, do the following - I&#8217;ll use the example of the ExpertSample.dll that comes with MT4.</p>
<p>After getting the sample up and running, do the following:</p>
<p>1. Setup your sampledll.mqh file to point directly to your DEBUG library file (C:blah\experts\samples\DLLSample\Debug\ExpertSample.dll)</p>
<p>2. If you just try to just select Debug from the VS IDE, you will be asked to select an EXE file.  DON&#8217;T do this.  If you did go ahead and select terminal.exe as the exe, the whole process simply exits and the debugger won&#8217;t catch anything.  Maybe someone smarter than me can explain why..</p>
<p>3. But, to really be able to debug your DLL, you have to attach to the terminal.exe process explicitly from VS.  Go to Debug, Processes and select your terminal .exe process.  Now, the debugger will start, and you can set breakpoints, etc.</p>
<p>It is really the combination of using the correct DLL that VS has source access to and attaching to the running terminal process that does the trick.<strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubesteak.net/2006/08/how-to-debug-custom-dlls-with-mt4/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
