<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Forex Software — Auto Lot Size Calculation]]></title>
	<link rel="self" href="https://forexsb.com/forum/feed/atom/topic/6251/" />
	<updated>2021-11-27T12:11:58Z</updated>
	<generator>PunBB</generator>
	<id>https://forexsb.com/forum/topic/6251/auto-lot-size-calculation/</id>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/67026/#p67026" />
			<content type="html"><![CDATA[<p>i struggling to let run a perfecct function for the entry percent..maybe popov can you make it for the new mt5 porttfolio?</p>]]></content>
			<author>
				<name><![CDATA[Roughey]]></name>
				<uri>https://forexsb.com/forum/user/10939/</uri>
			</author>
			<updated>2021-11-27T12:11:58Z</updated>
			<id>https://forexsb.com/forum/post/67026/#p67026</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/65090/#p65090" />
			<content type="html"><![CDATA[<p>Dear Popov,</p><p>can you please make an update for this old topic? I compared the code from a fresh new strategy with the old one from the EA updated here and it seems to me that the coding is different. </p><p>I am very interested (as you know <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /> ) in using percentages instead of lots and I haven&#039;t found a solution yet.</p><p>I tried to use FSB because of the percentage, but still I have more other problems there. With Expert Advisor I miss only this function, otherwise it is PERFECT !</p><p><img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>thanks<br />Sebastian</p>]]></content>
			<author>
				<name><![CDATA[mentosan]]></name>
				<uri>https://forexsb.com/forum/user/2989/</uri>
			</author>
			<updated>2021-05-18T10:39:51Z</updated>
			<id>https://forexsb.com/forum/post/65090/#p65090</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/52241/#p52241" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Popov wrote:</cite><blockquote><p>Yes, it is possible. You can use the follow function (taken from the FSB Pro scripts):</p><div class="codebox"><pre><code>double NormalizeEntrySize(double size)
{
    double minlot  = MarketInfo(_Symbol, MODE_MINLOT);
    double lotstep = MarketInfo(_Symbol, MODE_LOTSTEP);

    if (size &lt;= minlot)
        return (minlot);

    int steps = (int) MathRound((size - minlot) / lotstep);
    size = minlot + steps * lotstep;

    if (size &gt;= Maximum_Lots)
        size = Maximum_Lots;

    size = NormalizeDouble(size, digits);

    return (size);
}</code></pre></div><p>Put this function somewhere in the file and use it like that:</p><div class="codebox"><pre><code>Entry_Amount = NormalizeEntrySize(Entry_Amount);</code></pre></div></blockquote></div><p>Is it posible to make the EA detect minimum alllowed lot size and maximum lotsize automatically?<br />I think the code check the minlot size but what to do if the lotsize reached the maxium allowed from broker?<br />Is this code correct?<br /></p><div class="codebox"><pre><code>double NormalizeEntrySize(double size) {
   double minlot  = MarketInfo(_Symbol, MODE_MINLOT);
   double maxlot  = MarketInfo(_Symbol, MODE_MAXLOT);
   double lotstep = MarketInfo(_Symbol, MODE_LOTSTEP);

   if (size &lt;= minlot)
       return (minlot);

   int steps = (int) MathRound((size - minlot) / lotstep);
   size = minlot + steps * lotstep;

   if (size &gt;= maxlot || size &gt;=Maximum_Lots)
       size = maxlot;
       
   size = NormalizeDouble(size, digits);   

   return (size);
}   </code></pre></div>]]></content>
			<author>
				<name><![CDATA[deadlef]]></name>
				<uri>https://forexsb.com/forum/user/9894/</uri>
			</author>
			<updated>2018-09-16T17:36:31Z</updated>
			<id>https://forexsb.com/forum/post/52241/#p52241</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/49615/#p49615" />
			<content type="html"><![CDATA[<p>if i want to have both. Entry amount fix and entry amount with percent. If Lot size percent true...how will be the code for ea studi portfolio or generall normal strats`?</p>]]></content>
			<author>
				<name><![CDATA[deadlef]]></name>
				<uri>https://forexsb.com/forum/user/9894/</uri>
			</author>
			<updated>2018-03-17T22:26:38Z</updated>
			<id>https://forexsb.com/forum/post/49615/#p49615</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/43751/#p43751" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Blaiserboy wrote:</cite><blockquote><p><strong>yonkuro</strong></p><p>Thanks for asking these features and developing solutions...</p><p>These are most helpful... I had been asking a couple of them and now see in this thread that you are months ahead of me..</p><p>Thank you again!</p></blockquote></div><p>No problem Sir... <img src="https://forexsb.com/forum/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></content>
			<author>
				<name><![CDATA[yonkuro]]></name>
				<uri>https://forexsb.com/forum/user/8447/</uri>
			</author>
			<updated>2017-05-20T12:47:29Z</updated>
			<id>https://forexsb.com/forum/post/43751/#p43751</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/43748/#p43748" />
			<content type="html"><![CDATA[<p><strong>yonkuro</strong></p><p>Thanks for asking these features and developing solutions...</p><p>These are most helpful... I had been asking a couple of them and now see in this thread that you are months ahead of me..</p><p>Thank you again!</p>]]></content>
			<author>
				<name><![CDATA[Blaiserboy]]></name>
				<uri>https://forexsb.com/forum/user/2491/</uri>
			</author>
			<updated>2017-05-20T08:55:40Z</updated>
			<id>https://forexsb.com/forum/post/43748/#p43748</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38836/#p38836" />
			<content type="html"><![CDATA[<p>Thank you so much, it works perfectly <img src="https://forexsb.com/forum/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></content>
			<author>
				<name><![CDATA[yonkuro]]></name>
				<uri>https://forexsb.com/forum/user/8447/</uri>
			</author>
			<updated>2016-09-28T05:52:15Z</updated>
			<id>https://forexsb.com/forum/post/38836/#p38836</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38833/#p38833" />
			<content type="html"><![CDATA[<p>This error is because the NormalizeEntrySize is inside the OpenPosition function. MQL doesn&#039;t allow nesting functions. The solution is very simple - move NormalizeEntrySize before OpenPosition function.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2016-09-28T04:30:08Z</updated>
			<id>https://forexsb.com/forum/post/38833/#p38833</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38832/#p38832" />
			<content type="html"><![CDATA[<p>Hi Popov, I got this error when applying that code, I don&#039;t know, may be I applied it incorrectly<br /><a href="https://postimg.org/image/6ub45v5z9/"><span class="postimg"><img src="https://s18.postimg.org/6ub45v5z9/SS_FSB_28092016.jpg" alt="https://s18.postimg.org/6ub45v5z9/SS_FSB_28092016.jpg" /></span></a></p><p>The EA is attached.</p>]]></content>
			<author>
				<name><![CDATA[yonkuro]]></name>
				<uri>https://forexsb.com/forum/user/8447/</uri>
			</author>
			<updated>2016-09-28T02:49:00Z</updated>
			<id>https://forexsb.com/forum/post/38832/#p38832</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38822/#p38822" />
			<content type="html"><![CDATA[<p>Yes, it is possible. You can use the follow function (taken from the FSB Pro scripts):</p><div class="codebox"><pre><code>double NormalizeEntrySize(double size)
{
    double minlot  = MarketInfo(_Symbol, MODE_MINLOT);
    double lotstep = MarketInfo(_Symbol, MODE_LOTSTEP);

    if (size &lt;= minlot)
        return (minlot);

    int steps = (int) MathRound((size - minlot) / lotstep);
    size = minlot + steps * lotstep;

    if (size &gt;= Maximum_Lots)
        size = Maximum_Lots;

    size = NormalizeDouble(size, digits);

    return (size);
}</code></pre></div><p>Put this function somewhere in the file and use it like that:</p><div class="codebox"><pre><code>Entry_Amount = NormalizeEntrySize(Entry_Amount);</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2016-09-27T13:21:43Z</updated>
			<id>https://forexsb.com/forum/post/38822/#p38822</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38809/#p38809" />
			<content type="html"><![CDATA[<p>Thanks, but is it posible to make the EA detect minimum alllowed lot size automatically?</p>]]></content>
			<author>
				<name><![CDATA[yonkuro]]></name>
				<uri>https://forexsb.com/forum/user/8447/</uri>
			</author>
			<updated>2016-09-27T08:12:50Z</updated>
			<id>https://forexsb.com/forum/post/38809/#p38809</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38807/#p38807" />
			<content type="html"><![CDATA[<p>You are correct. You have to make the following changes:</p><div class="codebox"><pre><code>    Entry_Amount=MathMax(Entry_Amount,0.1);
    Entry_Amount=NormalizeDouble(Entry_Amount,1);</code></pre></div><p>This must work. You don&#039;t need to set additional increment value because it is most probably 0.1 and when the <em>NormalizeDouble(Entry_Amount,1)</em> function round it to the first decimal digit, it will work fine.</p>]]></content>
			<author>
				<name><![CDATA[Popov]]></name>
				<uri>https://forexsb.com/forum/user/2/</uri>
			</author>
			<updated>2016-09-27T07:48:37Z</updated>
			<id>https://forexsb.com/forum/post/38807/#p38807</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38805/#p38805" />
			<content type="html"><![CDATA[<p>Ah I got it I should change NormalizeDouble(Entry_Amount,2); to NormalizeDouble(Entry_Amount,1);. </p><p>But how do I make the EA to detect the minimum allowed increment automatically?</p>]]></content>
			<author>
				<name><![CDATA[yonkuro]]></name>
				<uri>https://forexsb.com/forum/user/8447/</uri>
			</author>
			<updated>2016-09-27T07:25:11Z</updated>
			<id>https://forexsb.com/forum/post/38805/#p38805</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38804/#p38804" />
			<content type="html"><![CDATA[<p>Hi Popov, if the broker only allows mini lot (0.1) step/increment, which code should I change?</p><p>The backtest show this error : OrderSend error 131, after I searched in Google, it&#039;s said the error is due to broker doesn&#039;t allow micro lot increment.</p><p>I test it using fixed lot version with 0.11 lot and it give the same error, but when I change the lot size to round number such as 0.1 or 0.2, it works well. So I&#039;m sure the problem is the allowed increment</p>]]></content>
			<author>
				<name><![CDATA[yonkuro]]></name>
				<uri>https://forexsb.com/forum/user/8447/</uri>
			</author>
			<updated>2016-09-27T07:10:16Z</updated>
			<id>https://forexsb.com/forum/post/38804/#p38804</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Auto Lot Size Calculation]]></title>
			<link rel="alternate" href="https://forexsb.com/forum/post/38106/#p38106" />
			<content type="html"><![CDATA[<p>Thanks a lot, it works and unexpectedly fun <img src="https://forexsb.com/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[yonkuro]]></name>
				<uri>https://forexsb.com/forum/user/8447/</uri>
			</author>
			<updated>2016-08-11T13:17:40Z</updated>
			<id>https://forexsb.com/forum/post/38106/#p38106</id>
		</entry>
</feed>
