{"id":2713,"date":"2026-11-26T11:16:30","date_gmt":"2026-11-26T17:16:30","guid":{"rendered":"https:\/\/www.patternsmart.com\/cn\/?p=2713"},"modified":"2026-11-26T17:27:41","modified_gmt":"2026-11-26T17:27:41","slug":"mt5-ea-%e5%a6%82%e4%bd%95%e5%9c%a8%e5%85%a5%e5%9c%ba%e5%89%8d%e8%ae%be%e7%bd%ae%e5%8f%af%e7%94%a8%e4%bf%9d%e8%af%81%e9%87%91%e9%a2%84%e7%95%99","status":"publish","type":"post","link":"https:\/\/www.patternsmart.com\/cn\/mt5-ea-%e5%a6%82%e4%bd%95%e5%9c%a8%e5%85%a5%e5%9c%ba%e5%89%8d%e8%ae%be%e7%bd%ae%e5%8f%af%e7%94%a8%e4%bf%9d%e8%af%81%e9%87%91%e9%a2%84%e7%95%99\/","title":{"rendered":"MT5 EA \u5982\u4f55\u5728\u5165\u573a\u524d\u8bbe\u7f6e\u53ef\u7528\u4fdd\u8bc1\u91d1\u9884\u7559"},"content":{"rendered":"<div class=\"postie-post\">\n<p>\u6309\u6b62\u635f\u8ba1\u7b97\u4ed3\u4f4d\u53ea\u80fd\u7ea6\u675f\u8ba1\u5212\u4ea4\u6613\u4e8f\u635f\uff0c\u5e76\u4e0d\u80fd\u786e\u4fdd\u8d26\u6237\u62e5\u6709\u8db3\u591f\u53ef\u7528\u4fdd\u8bc1\u91d1\u3002\u72ec\u7acb\u7684\u4fdd\u8bc1\u91d1\u9884\u7559\u673a\u5236\u80fd\u907f\u514d\u591a\u4e2a\u7b56\u7565\u5171\u7528\u8d26\u6237\u65f6\u8017\u5c3d\u4f30\u7b97\u5bb9\u91cf\u3002\u9884\u7559\u5c5e\u4e8e\u8fd0\u884c\u653f\u7b56\uff0c\u4e0d\u662f\u6700\u5927\u4e8f\u635f\u6307\u6807\u3002<\/p>\n<h2>\u5b9e\u4f8b<\/h2>\n<p>\u5047\u8bbe\u8d26\u6237\u8d27\u5e01\u8ba1\u4ef7\u7684\u53ef\u7528\u4fdd\u8bc1\u91d1\u4e3a3000\uff0c\u8981\u6c42\u9884\u75591000\uff0c\u65b0\u8ba2\u5355\u4f30\u7b97\u4fdd\u8bc1\u91d1\u9884\u7b97\u4e3a2000\u3002\u4f30\u7b971200\u65f6\u5269\u4f591800\uff0c\u901a\u8fc7\uff1b\u4f30\u7b972000\u65f6\u6070\u597d\u5269\u4f591000\uff1b\u4f30\u7b972400\u65f6\u4ec5\u5269600\uff0c\u5e94\u8df3\u8fc7\u3002\u8fd9\u4e9b\u662f\u5047\u8bbe\u6570\u503c\uff0c\u5e76\u975e\u6760\u6746\u5efa\u8bae\u3002<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/www.patternsmart.com\/cn\/wp-content\/uploads\/2026\/11\/PS_MarginBuffer_CN_Fig1.png\" alt=\"PS_MarginBuffer_CN_Fig1.png\" title=\"\u9884\u75591000\u540e\uff0c\u65b0\u8ba2\u5355\u7684\u4f30\u7b97\u4fdd\u8bc1\u91d1\u9884\u7b97\u4e3a2000\u3002\" width=\"960\" height=\"420\" style=\"max-width:100%;height:auto\"><figcaption>\u9884\u75591000\u540e\uff0c\u65b0\u8ba2\u5355\u7684\u4f30\u7b97\u4fdd\u8bc1\u91d1\u9884\u7b97\u4e3a2000\u3002<\/figcaption><\/figure>\n<h2>\u6784\u5efa\u8bf7\u6c42\u524d\u4f7f\u7528OrderCalcMargin<\/h2>\n<p>\u4ee5\u4e0b\u7247\u6bb5\u4f4d\u4e8eOnTick\u5165\u573a\u5206\u652f\uff0c\u5728\u8ba1\u7b97plannedLots\u3001\u9a8c\u8bc1\u624b\u6570\u589e\u91cf\u53ca\u5165\u573a\u4fe1\u53f7\u4e4b\u540e\u6267\u884c\u3002\u4e70\u5355\u4ee5\u5f53\u524dAsk\u4f30\u7b97\uff0c\u5356\u5355\u5e94\u4f7f\u7528\u76f8\u5e94\u8ba2\u5355\u7c7b\u578b\u53caBid\u3002OrderCalcMargin\u7684\u4f30\u7b97\u4e0d\u8003\u8651\u5df2\u6709\u6301\u4ed3\u53ca\u6302\u5355\uff0c\u56e0\u6b64\u5b9e\u9645\u7ec4\u5408\u548c\u51c0\u989d\u6548\u5e94\u53ef\u80fd\u4e0d\u540c\u3002<\/p>\n<pre style=\"white-space:pre;font-family:Consolas,Monaco,monospace\"><code>\/\/ OnTick entry branch, before sending a BUY request<br>MqlTick tick;<br>if (!SymbolInfoTick(_Symbol, tick)) return;<br>double margin = 0.0;<br>if (!OrderCalcMargin(ORDER_TYPE_BUY, _Symbol,<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0plannedLots, tick.ask, margin))<br>\u00a0\u00a0\u00a0\u00a0return;<br>double free = AccountInfoDouble(ACCOUNT_MARGIN_FREE);<br>if (free - margin &lt; 1000.0) return;<br>\/\/ Build MqlTradeRequest; use OrderCheck before OrderSend.<\/code><\/pre>\n<p>\u5bf9\u5b9e\u9645\u8bf7\u6c42\u4f7f\u7528OrderCheck\u8fdb\u884c\u989d\u5916\u9884\u68c0\uff0c\u68c0\u67e5\u8fd4\u56de\u7801\u3001\u9884\u6d4b\u4fdd\u8bc1\u91d1\u548c\u53ef\u7528\u4fdd\u8bc1\u91d1\u3002\u9884\u68c0\u6210\u529f\u4e0d\u4fdd\u8bc1\u540e\u7eed\u6210\u4ea4\u3002\u68c0\u67e5OrderSend\u7ed3\u679c\u7684retcode\u5e76\u6838\u5bf9\u5b9e\u9645\u6267\u884c\u3002\u591a\u4e2aEA\u540c\u65f6\u8fd0\u884c\u65f6\uff0c\u5c40\u90e8\u8bfb\u53d6\u7684\u4fdd\u8bc1\u91d1\u5feb\u7167\u5e76\u975e\u539f\u5b50\u5f0f\u9884\u7559\u3002<\/p>\n<h2>\u6d4b\u8bd5\u4e0e\u4fdd\u62a4<\/h2>\n<ul>\n<li>\u6d4b\u8bd5\u96f6\u9884\u7b97\u3001\u8d1f\u9884\u7b97\u53ca\u7cbe\u786e\u8fb9\u754c\uff1b\u8bb0\u5f55\u8ba1\u7b97\u9519\u8bef\uff0c\u4e0d\u8981\u5c06\u5176\u89c6\u4f5c\u96f6\u4fdd\u8bc1\u91d1\u3002<\/li>\n<li>\u90e8\u5206\u6210\u4ea4\u3001\u6760\u6746\u53d8\u5316\u3001\u4ef7\u683c\u6ce2\u52a8\u6216\u5176\u4ed6\u7b56\u7565\u5f00\u4ed3\u540e\u91cd\u65b0\u5224\u65ad\u3002<\/li>\n<li>\u6bd4\u8f83\u51c0\u989d\u548c\u5bf9\u51b2\u8d26\u6237\uff0c\u4fdd\u8bc1\u91d1\u62b5\u6263\u968f\u7ecf\u7eaa\u5546\u548c\u54c1\u79cd\u800c\u5f02\u3002<\/li>\n<li>\u540c\u65f6\u4f7f\u7528\u6a21\u62df\u8d26\u6237\u53ca\u7b56\u7565\u6d4b\u8bd5\u5668\u9a8c\u8bc1\uff1b\u4fdd\u8bc1\u91d1\u9884\u7559\u3001\u6b62\u635f\u98ce\u9669\u53ca\u8d26\u6237\u56de\u64a4\u9650\u5236\u5e94\u5206\u522b\u7ba1\u7406\u3002<\/li>\n<\/ul>\n<p>\u5b98\u65b9\u53c2\u8003\uff1a<a href=\"https:\/\/www.mql5.com\/en\/docs\/trading\/ordercalcmargin\">OrderCalcMargin<\/a>\u3002<\/p>\n<p>\u4ee5\u4e0a\u4e3a\u5047\u8bbe\u6027\u6559\u5b66\u793a\u4f8b\uff0c\u672a\u8fdb\u884c\u7f16\u8bd1\u6216\u56de\u6d4b\u3002\u4ea4\u6613\u5b58\u5728\u4e8f\u635f\u98ce\u9669\uff0c\u6a21\u62df\u8868\u73b0\u4e0d\u4ee3\u8868\u672a\u6765\u7ed3\u679c\u3002<\/p>\n<p>\u5982\u9700\u5c06\u6b64\u514d\u8d39\u7b56\u7565\u601d\u8def\u6269\u5c55\u4e3a\u81ea\u5df1\u7684\u4ea4\u6613\u7a0b\u5e8f\uff0c\u6b22\u8fce\u8054\u7cfb\u6211\u4eec\u4e86\u89e3<a href=\"https:\/\/www.patternsmart.com\/cn\/custom\/\">MT5\u4ea4\u6613\u7b56\u7565\u5b9a\u5236\u5f00\u53d1\u670d\u52a1<\/a>\u3002<\/p>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6309\u6b62\u635f\u8ba1\u7b97\u4ed3\u4f4d\u53ea\u80fd\u7ea6\u675f\u8ba1\u5212\u4ea4\u6613\u4e8f\u635f\uff0c\u5e76\u4e0d\u80fd\u786e\u4fdd\u8d26\u6237\u62e5\u6709\u8db3\u591f\u53ef\u7528\u4fdd\u8bc1\u91d1\u3002\u72ec\u7acb\u7684\u4fdd\u8bc1\u91d1\u9884\u7559\u673a\u5236\u80fd\u907f\u514d\u591a\u4e2a\u7b56\u7565\u5171\u7528\u8d26 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2714,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"fifu_image_url":"","fifu_image_alt":"","_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[364,520],"tags":[429,128,340,623,614,342],"class_list":["post-2713","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mt5","category-520","tag-mql5","tag-mt5","tag-340","tag-623","tag-614","tag-342"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.patternsmart.com\/cn\/wp-content\/uploads\/2026\/11\/PS_MarginBuffer_CN_Fig1.png","_links":{"self":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts\/2713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/comments?post=2713"}],"version-history":[{"count":0,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/posts\/2713\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/media\/2714"}],"wp:attachment":[{"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/media?parent=2713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/categories?post=2713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.patternsmart.com\/cn\/wp-json\/wp\/v2\/tags?post=2713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}