<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MQL - 投資家のための検証サイト</title>
	<atom:link href="https://toushika.top/mql/feed/" rel="self" type="application/rss+xml" />
	<link>https://toushika.top</link>
	<description>トレーダーの検証サイト</description>
	<lastBuildDate>Mon, 14 Jun 2021 07:29:12 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://toushika.top/wp-content/uploads/2020/01/cropped-Icon-tousikatop-32x32.png</url>
	<title>MQL - 投資家のための検証サイト</title>
	<link>https://toushika.top</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/>
<atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/>
<atom:link rel="hub" href="https://websubhub.com/hub"/>
<atom:link rel="self" href="https://toushika.top/mql/feed/"/>
	<item>
		<title>[MQL]価格が NormalizeDouble されない？</title>
		<link>https://toushika.top/normalizedouble-do-not-work/</link>
					<comments>https://toushika.top/normalizedouble-do-not-work/#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Sun, 26 Apr 2020 16:57:13 +0000</pubDate>
				<category><![CDATA[Indicator]]></category>
		<category><![CDATA[MQL]]></category>
		<guid isPermaLink="false">https://toushika.top/?p=771</guid>

					<description><![CDATA[勝率判定をするインジケーターを作成していて価格をNormalizeDouble するかしないかで結果か違っていて 調査をしていて本当にGet Crazyな状態になったので、その調査を纏めてみたいと思います。 今後、同じような経験をされる方が…]]></description>
										<content:encoded><![CDATA[<p>勝率判定をするインジケーターを作成していて価格をNormalizeDouble するかしないかで結果か違っていて<br />
調査をしていて本当にGet Crazyな状態になったので、その調査を纏めてみたいと思います。</p>
<p>今後、同じような経験をされる方がいて役に立てるかと思い記録しておきます。</p>
<p>そもそも価格をNormalizeDouble する必要があるかというと価格を保存するためにdoubleを使用します。<br />
doubleは浮動小点型といわれ小数点以下にとんでもない数字が並びます。</p>
<div style="text-align: justify; text-indent: 0; padding: 0 0 0 0; margin: 8px 17px 7px 17px;">
<table class="EnumTable" cellpadding="5" border="1">
<tbody>
<tr class="EnumTable">
<td class="EnumTable" style="background-color: #dbe9f9;">
<p class="p_fortable"><span class="f_fortable" style="font-weight: bold;">Type</span></p>
</td>
<td class="EnumTable" style="background-color: #dbe9f9;">
<p class="p_fortable"><span class="f_fortable" style="font-weight: bold;">バイトサイズ</span></p>
</td>
<td class="EnumTable" style="background-color: #dbe9f9;">
<p class="p_fortable"><span class="f_fortable" style="font-weight: bold;">最小の正の値</span></p>
</td>
<td class="EnumTable" style="background-color: #dbe9f9;">
<p class="p_fortable"><span class="f_fortable" style="font-weight: bold;">最大値</span></p>
</td>
<td class="EnumTable" style="background-color: #dbe9f9;">
<p class="p_fortable"><span class="f_fortable" style="font-weight: bold;">C++</span></p>
</td>
</tr>
<tr class="EnumTable">
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">float</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">4</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">1.175494351e-38</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">3.402823466e+38</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">float</span></p>
</td>
</tr>
<tr class="EnumTable">
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">double</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">8</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">2.2250738585072014e-308</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">1.7976931348623158e+308</span></p>
</td>
<td class="EnumTable">
<p class="p_fortable"><span class="f_fortable">double</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p><a href="https://www.mql5.com/ja/docs/basis/types/double" target="_blank" rel="noopener">https://www.mql5.com/ja/docs/basis/types/double</a></p>
<p>MQLでは有効な数字としては小数点以下15桁が有効な数字らしいです。小数点以下15桁もあるので価格を<br />
NormalizeDoubleであるところで<span>四捨五入していないと</span> 比較する際にマッチしない現象がよく起きます。なので価格を<br />
取得する箇所にはNormalizeDouble を使うようにしていました。</p>
<div class="sc_frame_wrap onframe black">
<div class="sc_frame_title">例</div>
<div class="sc_frame ">
<div class="sc_frame_text">double price = NormalizeDouble(price, Digits);</div>
</div>
</div>
<p>ベストプラクティスにも記載されています。</p>
<blockquote><p>トレード処理では、精度がトレーディングサーバーに要求される最低1桁を超える正規化されていない価格を使用することは不可能であることに注意が必要です。<br />
未決注文に対するストップロス、テイクプロフィット、価格値は、値が定義済み変数 Digits に格納されている値精度で正規化します。</p>
<div class="blockquote_ref">
<div><a href="https://www.mql5.com/ja/articles/1561" target="_blank" rel="noopener noreferrer">MQL4 でダブルスの作業をする</a></div>
</div>
</blockquote>
<h3 class="sc_heading bborder tb black"><span class="sc_title">ところが価格をNormalizeDouble しても正常に表示されない</span><span class="sc_title">ような現象が確認できました。</span></h3>
<p><img fetchpriority="high" decoding="async" src="https://toushika.top/wp-content/uploads/2020/04/priceaudjpym1-300x108.png" alt="[MQL]価格が NormalizeDouble されない？" width="825" height="297" class="alignnone wp-image-772" title="[MQL]価格が NormalizeDouble されない？" srcset="https://toushika.top/wp-content/uploads/2020/04/priceaudjpym1-300x108.png 300w, https://toushika.top/wp-content/uploads/2020/04/priceaudjpym1-768x275.png 768w, https://toushika.top/wp-content/uploads/2020/04/priceaudjpym1.png 898w" sizes="(max-width: 825px) 100vw, 825px" /></p>
<p>こちらはAUDJPY1分足なのですが終値は、68.704になります。<br />
MQLで価格を取得してみると、</p>
<div class="sc_frame_wrap onframe black">
<div class="sc_frame ">
<div class="sc_frame_text">double TestValue = iClose(NULL, 0, 0);<br />
double TestValue_NormalizeDouble = NormalizeDouble(TestValue, Digits);<br />
Print("TestValue ",TestValue, " TestValue_NormalizeDouble ", TestValue_NormalizeDouble);<br />
<strong></strong></div>
<div></div>
<div class="sc_frame_text"><strong>結果</strong><br />
AUDJPY,M1: TestValue 68.70399999999999 TestValue_NormalizeDouble 68.70399999999999</div>
</div>
</div>
<p><strong>-0.00000000000001違います。</strong>DoubleToStrを使用してストリングにして表示した場合は、</p>
<div class="sc_frame_wrap onframe black">
<div class="sc_frame ">
<div class="sc_frame_text">
<p>Print ("TestValueString ", DoubleToStr(TestValue, Digits), " TestValue_NormalizeDoubleString: ", DoubleToStr(TestValue_NormalizeDouble, Digits));</p>
<p><strong>結果</strong><br />
AUDJPY,M1: TestValueString 68.704 TestValue_NormalizeDoubleString: 68.704</p>
</div>
</div>
</div>
<p><strong>こちらは正しくなりました。</strong></p>
<p>これらの現象はMQL5のフォーラムでかなり長い間、熱く議論されております。<br />
英語ですが見たい方はこちら。<br />
<a href="https://www.mql5.com/en/forum/136997" target="_blank" rel="noopener">https://www.mql5.com/en/forum/</a><br />
<a href="https://www.mql5.com/en/forum/146370/" target="_blank" rel="noopener">https://www.mql5.com/en/forum/146370/</a></p>
<p>いろいろ長い間に議論されておりはNormalizeDoubleは使用しないほうがいいのではないかとの意見もありました。<br />
新しい記事では以下の関数を使用するのがいいとのことでした。<br />
<a href="https://www.mql5.com/en/forum/333599" target="_blank" rel="noopener">https://www.mql5.com/en/forum/333599</a></p>
<div class="sc_frame_wrap onframe black">
<div class="sc_frame ">
<div class="sc_frame_text"><strong>double NormalizePrice(double p)</strong><br />
<strong>{</strong><br />
<strong>double ts=SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);</strong><br />
<strong>return(NormalizeDouble(p/ts,0)*ts);</strong></div>
<div class="sc_frame_text"><strong>}</strong></div>
</div>
</div>
<div class="sc_frame_wrap onframe black">
<div class="sc_frame ">
<div class="sc_frame_text">Print("TestValue ",TestValue, " NormalizePrice ", NormalizePrice(TestValue));<br />
Print("NormalizePriceString ", DoubleToStr(<strong>NormalizePrice</strong>(TestValue), Digits));</div>
<div></div>
<div class="sc_frame_text"><strong>結果</strong><br />
AUDJPY,M1: TestValue 68.70399999999999 NormalizePrice 68.70400000000001<br />
AUDJPY,M1: NormalizePriceString 68.704</div>
</div>
</div>
<p>こちらのほうも0.00000000000001違いますがこちらはPrint()の動作のようです。</p>
<blockquote><p>正規化数は小数点以下の桁数を多く含むことがあるので、Print() 関数を使用しての操作ログへの出力時にはご注意ください。<br />
Print(76.671)=76.67100000000001</p>
<div class="blockquote_ref">
<div><a href="https://www.mql5.com/ja/docs/convert/normalizedouble" target="_blank" rel="noopener noreferrer">NormalizeDouble</a></div>
</div>
</blockquote>
<p>stdlib.mqhに含まれているDoubleToStrMorePrecision関数での15桁までの値の確認してみます。そして値を比較してみます。</p>
<div class="sc_frame_wrap onframe black">
<div class="sc_frame ">
<div class="sc_frame_text"><stdlib.mqh>#include &lt;stdlib.mqh&gt;<br />
double TestValue_NormalizeDouble = NormalizeDouble(TestValue, Digits);<br />
double TestValue_NormalizePrice = <strong>NormalizePrice</strong>(TestValue);<br />
Print("DoubleToStrMorePrecision",DoubleToStrMorePrecision(TestValue,15));<br />
Print("DoubleToStrMorePrecision",DoubleToStrMorePrecision(TestValue_NormalizeDouble,15)," ",DoubleToStrMorePrecision(TestValue_NormalizePrice,15));<br />
</stdlib.mqh></div>
<div></div>
<div class="sc_frame_text"><stdlib.mqh>if (TestValue_NormalizeDouble == TestValue_NormalizePrice)<br />
Print (TestValue_NormalizeDouble," ",TestValue_NormalizePrice, " The value is same");<br />
else<br />
Print (TestValue_NormalizeDouble," ",TestValue_NormalizePrice, " The value is NOT same");</stdlib.mqh></div>
<div></div>
<div class="sc_frame_text"><stdlib.mqh>結果</stdlib.mqh></div>
<div class="sc_frame_text"><stdlib.mqh>AUDJPY,M1: DoubleToStrMorePrecision 68.703999999999994<br />
AUDJPY,M1: DoubleToStrMorePrecision 68.703999999999994 68.704000000000008<br />
AUDJPY,M1: 68.70399999999999 68.70400000000001 The value is NOT same<stdlib.mqh><br />
※元の価格とNormalizeDoubleした<stdlib.mqh><stdlib.mqh>価格は全く同じ<br />
</stdlib.mqh></stdlib.mqh><stdlib.mqh><stdlib.mqh><stdlib.mqh>NormalizeDoubleした<stdlib.mqh><stdlib.mqh>価格と</stdlib.mqh></stdlib.mqh></stdlib.mqh></stdlib.mqh>NormalizePriceした値は違っています。</stdlib.mqh></stdlib.mqh>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p></stdlib.mqh></div>
</div>
</div>
<div class="sc_frame_wrap onframe black">
<div class="sc_frame ">
<div class="sc_frame_text">//比較のため手入力したとします。<br />
double TestValue1 = 68.704;<br />
if (TestValue_NormalizeDouble == TestValue1)<br />
Print (TestValue_NormalizeDouble," ",TestValue1, " NormalizeDouble1 The value is same");<br />
else<br />
Print (TestValue_NormalizeDouble," ",TestValue1, " NormalizeDouble1 The value is NOT same");</div>
<div></div>
<div class="sc_frame_text">if (TestValue_NormalizePrice == TestValue1)<br />
Print (TestValue_NormalizePrice," ",TestValue1, " NormalizePrice1 The value is same");<br />
else<br />
Print (TestValue_NormalizePrice," ",TestValue1, " NormalizePrice1 The value is NOT same");</div>
<div>//手入力した値をNormalizeDoubleとNormalizePriceします。</div>
<div class="sc_frame_text">if (TestValue_NormalizeDouble == <strong>NormalizeDouble</strong>(TestValue1, Digits))<br />
Print (TestValue_NormalizeDouble," ",TestValue1, " NormalizeDouble2 The value is same");<br />
else<br />
Print (TestValue_NormalizeDouble," ",TestValue1, " NormalizeDouble2 The value is NOT same");</div>
<div></div>
<div class="sc_frame_text">if (TestValue_NormalizePrice == <strong>NormalizePrice</strong>(TestValue1))<br />
Print (TestValue_NormalizePrice," ",TestValue1, " NormalizePrice2 The value is same");<br />
else<br />
Print (TestValue_NormalizePrice," ",TestValue1, " NormalizePrice2 The value is NOT same");</div>
<div></div>
<div class="sc_frame_text"><strong>結果</strong><br />
AUDJPY,M1: 68.70399999999999 68.70399999999999 NormalizeDouble1 The value is same<br />
AUDJPY,M1: 68.70400000000001 68.70399999999999 NormalizePrice1 The value is NOT same<br />
AUDJPY,M1: 68.70399999999999 68.70399999999999 NormalizeDouble2 The value is same<br />
AUDJPY,M1: <strong><span style="color: #ff0000;">68.70400000000001 68.70399999999999</span></strong> NormalizePrice2 The value is same<br />
＃NormalizeDouble1の価格は手入力した価格と同じになりました。<br />
反対にNormalizePriceの価格は同じ価格との判断にはなりませんでした。手入力した価格もNormalizePriceしなければいけないようで表示もそのままでした。</div>
</div>
</div>
<h3 class="sc_heading bborder tb black"><span class="sc_title">今のところの結論</span></h3>
<p>私が試した限りでは<stdlib.mqh>NormalizeDoubleは別に問題はなく反対に紹介されている関数を使うとすべての価格に適用する必要があるのではないかと思いました。</stdlib.mqh><stdlib.mqh>フォーラム上で<stdlib.mqh>NormalizeDoubleを使わないほうがいいよと言われている人は見るとある特定の方で<stdlib.mqh><stdlib.mqh>NormalizeDoubleが議論になると登場していました。最初はこの方の言葉を信じていろいろと試してみましたが今のところ問題はただの表示上の問題のように見受けられました。今後もこの件については引き続き調査したいとおもいます。</stdlib.mqh></stdlib.mqh></stdlib.mqh></stdlib.mqh></p>
<p>もし<stdlib.mqh>NormalizeDouble関数を使用することで問題があるようであればコメントいただければありがたいです。</stdlib.mqh></p>
]]></content:encoded>
					
					<wfw:commentRss>https://toushika.top/normalizedouble-do-not-work/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
