Files
mt5_report_parser/output/mae_mfe.html
T

109 lines
213 KiB
HTML
Raw Normal View History

<!doctype html><html lang="zh-CN"><head><meta charset="utf-8">
<title>MAE/MFE 分析</title>
<style>
body { font-family:-apple-system,"Microsoft YaHei",sans-serif; background:#f8fafc; color:#111827; margin:0; padding:20px;}
.wrap { max-width:1100px; margin:0 auto;}
h1,h2 { color:#1e3a8a;} h1 { border-bottom:3px solid #1e3a8a; padding-bottom:8px;}
.muted { color:#6b7280; font-size:12px;}
.cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:12px; margin:16px 0;}
.card { background:#fff; padding:12px; border-radius:8px; border:1px solid #e2e8f0;}
.card .k { color:#6b7280; font-size:11px;} .card .v { font-size:18px; font-weight:600; margin-top:4px;}
.card .v.pos { color:#16a34a;}
.chart { width:100%; height:auto; background:#fff; border:1px solid #e2e8f0; border-radius:6px;}
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:12px;}
.note { background:#fef3c7; border-left:4px solid #f59e0b; padding:10px 14px; margin:12px 0; border-radius:4px;}
pre { background:#1e293b; color:#e2e8f0; padding:14px; border-radius:6px; overflow:auto; font-size:11px;}
footer { color:#6b7280; font-size:11px; margin-top:32px; text-align:center;}
</style></head><body><div class="wrap">
<h1>MAE / MFE 分析报告</h1>
<p class='muted'>样本: 400 笔 · 盈亏-MAE 相关 -0.37 · 盈亏-MFE 相关 0.72</p>
<div class='cards'><div class='card'><div class='k'>样本笔数</div><div class='v'>400</div></div><div class='card'><div class='k'>最优 TP(点)</div><div class='v'>36</div></div><div class='card'><div class='k'>最优 SL(点)</div><div class='v'>0</div></div><div class='card'><div class='k'>理论净盈利(点)</div><div class='v pos'>8385</div></div><div class='card'><div class='k'>理论胜率</div><div class='v'>79.8%</div></div><div class='card'><div class='k'>理论 PF</div><div class='v'>14.47</div></div></div>
<p class='muted'>盈亏与 MAE 负相关 (-0.37):逆向偏移越大越易亏,设 SL 合理。SL 候选 = 亏损笔 MAE 75 分位 ≈ <b>38 点</b></p><p class='muted'>盈亏与 MFE 正相关 (0.72):能跑到 X 点的笔更易盈利,TP 候选 = 盈利笔 MFE 中位 ≈ <b>45 点</b></p><div class='note'><b>理论最优 TP/SL</b>TP=36点 / SL=0点,在该组合下重算净盈利 8385点、胜率 79.8%、PF 14.47。此为基于历史 MAE/MFE 的理论值,需回测验证。</div>
<h2>1. MAE / MFE 散点</h2>
<div class="grid2"><div><svg viewBox="0 0 460 320" class="chart"><text x="230" y="16" font-size="11" fill="#374151" text-anchor="middle">MAE vs 盈亏(绿=赢/红=输)</text><line x1="50.0" y1="30" x2="50.0" y2="280" stroke="#f1f5f9" stroke-width="0.5"/><text x="50.0" y="294.0" font-size="9" fill="#6b7280" text-anchor="middle">0</text><line x1="50" y1="280.0" x2="444" y2="280.0" stroke="#f1f5f9" stroke-width="0.5"/><text x="44.0" y="283.0" font-size="9" fill="#6b7280" text-anchor="end">-16</text><line x1="247.0" y1="30" x2="247.0" y2="280" stroke="#f1f5f9" stroke-width="0.5"/><text x="247.0" y="294.0" font-size="9" fill="#6b7280" text-anchor="middle">32</text><line x1="50" y1="155.0" x2="444" y2="155.0" stroke="#f1f5f9" stroke-width="0.5"/><text x="44.0" y="158.0" font-size="9" fill="#6b7280" text-anchor="end">3</text><line x1="444.0" y1="30" x2="444.0" y2="280" stroke="#f1f5f9" stroke-width="0.5"/><text x="444.0" y="294.0" font-size="9" fill="#6b7280" text-anchor="middle">64</text><line x1="50" y1="30.0" x2="444" y2="30.0" stroke="#f1f5f9" stroke-width="0.5"/><text x="44.0" y="33.0" font-size="9" fill="#6b7280" text-anchor="end">21</text><circle cx="187.3" cy="106.2" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=22.2, 盈利($)=9.91, profit=9.91</title></circle><circle cx="269.6" cy="151.4" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=35.5, 盈利($)=3.24, profit=3.24</title></circle><circle cx="189.2" cy="91.9" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=22.5, 盈利($)=12.02, profit=12.02</title></circle><circle cx="231.8" cy="237.8" r="2.2" fill="#dc2626" opacity="0.45"><title>MAE(点)=29.4, 盈利($)=-9.51, profit=-9.51</title></circle><circle cx="325.2" cy="263.5" r="2.2" fill="#dc2626" opacity="0.45"><title>MAE(点)=44.5, 盈利($)=-13.31, profit=-13.31</title></circle><circle cx="199.1" cy="131.4" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=24.1, 盈利($)=6.19, profit=6.19</title></circle><circle cx="191.6" cy="212.0" r="2.2" fill="#dc2626" opacity="0.45"><title>MAE(点)=22.9, 盈利($)=-5.71, profit=-5.71</title></circle><circle cx="148.3" cy="144.7" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=15.9, 盈利($)=4.22, profit=4.22</title></circle><circle cx="75.4" cy="96.1" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=4.1, 盈利($)=11.40, profit=11.40</title></circle><circle cx="244.2" cy="156.9" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=31.4, 盈利($)=2.43, profit=2.43</title></circle><circle cx="89.0" cy="97.4" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=6.3, 盈利($)=11.21, profit=11.21</title></circle><circle cx="234.3" cy="131.9" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=29.8, 盈利($)=6.12, profit=6.12</title></circle><circle cx="172.5" cy="136.7" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=19.8, 盈利($)=5.41, profit=5.41</title></circle><circle cx="278.2" cy="230.7" r="2.2" fill="#dc2626" opacity="0.45"><title>MAE(点)=36.9, 盈利($)=-8.47, profit=-8.47</title></circle><circle cx="167.5" cy="111.1" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=19.0, 盈利($)=9.19, profit=9.19</title></circle><circle cx="97.6" cy="96.4" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=7.7, 盈利($)=11.35, profit=11.35</title></circle><circle cx="207.1" cy="204.1" r="2.2" fill="#dc2626" opacity="0.45"><title>MAE(点)=25.4, 盈利($)=-4.54, profit=-4.54</title></circle><circle cx="121.7" cy="87.6" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=11.6, 盈利($)=12.65, profit=12.65</title></circle><circle cx="157.0" cy="83.6" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=17.3, 盈利($)=13.24, profit=13.24</title></circle><circle cx="177.4" cy="114.0" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=20.6, 盈利($)=8.76, profit=8.76</title></circle><circle cx="161.3" cy="83.7" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=18.0, 盈利($)=13.22, profit=13.22</title></circle><circle cx="156.4" cy="53.4" r="2.2" fill="#16a34a" opacity="0.45"><title>MAE(点)=17.2, 盈利($)=17.69, p
<p class='muted'>蓝虚线 = 推荐的 SL/TP 候选阈值。MAE 图:右侧红点=逆向走很远还亏=该早止损;MFE 图:右侧绿点=涨得高最终赚=TP 可放到此处。</p>
<h2>2. TP × SL 扫描热力图</h2>
<svg viewBox="0 0 460 360" class="chart"><text x="230" y="16" font-size="11" fill="#374151" text-anchor="middle">理论净盈利 (TP × SL 扫描) — 圈=最优</text><rect x="60.0" y="310.3" width="12.8" height="9.7" fill="rgb(137,210,90)" stroke="#fff" stroke-width="0.4"/><rect x="72.8" y="310.3" width="12.8" height="9.7" fill="rgb(168,197,94)" stroke="#fff" stroke-width="0.4"/><rect x="85.6" y="310.3" width="12.8" height="9.7" fill="rgb(154,217,97)" stroke="#fff" stroke-width="0.4"/><rect x="98.4" y="310.3" width="12.8" height="9.7" fill="rgb(135,210,90)" stroke="#fff" stroke-width="0.4"/><rect x="111.2" y="310.3" width="12.8" height="9.7" fill="rgb(117,203,83)" stroke="#fff" stroke-width="0.4"/><rect x="124.0" y="310.3" width="12.8" height="9.7" fill="rgb(100,196,76)" stroke="#fff" stroke-width="0.4"/><rect x="136.8" y="310.3" width="12.8" height="9.7" fill="rgb(89,191,71)" stroke="#fff" stroke-width="0.4"/><rect x="149.6" y="310.3" width="12.8" height="9.7" fill="rgb(78,187,67)" stroke="#fff" stroke-width="0.4"/><rect x="162.4" y="310.3" width="12.8" height="9.7" fill="rgb(71,184,64)" stroke="#fff" stroke-width="0.4"/><rect x="175.2" y="310.3" width="12.8" height="9.7" fill="rgb(64,181,61)" stroke="#fff" stroke-width="0.4"/><rect x="188.0" y="310.3" width="12.8" height="9.7" fill="rgb(60,180,60)" stroke="#fff" stroke-width="0.4"/><rect x="200.8" y="310.3" width="12.8" height="9.7" fill="rgb(60,180,60)" stroke="#fff" stroke-width="0.4"/><rect x="213.6" y="310.3" width="12.8" height="9.7" fill="rgb(65,182,62)" stroke="#fff" stroke-width="0.4"/><rect x="226.4" y="310.3" width="12.8" height="9.7" fill="rgb(75,186,66)" stroke="#fff" stroke-width="0.4"/><rect x="239.2" y="310.3" width="12.8" height="9.7" fill="rgb(79,187,67)" stroke="#fff" stroke-width="0.4"/><rect x="252.0" y="310.3" width="12.8" height="9.7" fill="rgb(83,189,69)" stroke="#fff" stroke-width="0.4"/><rect x="264.8" y="310.3" width="12.8" height="9.7" fill="rgb(92,193,73)" stroke="#fff" stroke-width="0.4"/><rect x="277.6" y="310.3" width="12.8" height="9.7" fill="rgb(101,196,76)" stroke="#fff" stroke-width="0.4"/><rect x="290.4" y="310.3" width="12.8" height="9.7" fill="rgb(104,197,77)" stroke="#fff" stroke-width="0.4"/><rect x="303.2" y="310.3" width="12.8" height="9.7" fill="rgb(110,200,80)" stroke="#fff" stroke-width="0.4"/><rect x="316.0" y="310.3" width="12.8" height="9.7" fill="rgb(117,202,82)" stroke="#fff" stroke-width="0.4"/><rect x="328.8" y="310.3" width="12.8" height="9.7" fill="rgb(124,205,85)" stroke="#fff" stroke-width="0.4"/><rect x="341.6" y="310.3" width="12.8" height="9.7" fill="rgb(129,207,87)" stroke="#fff" stroke-width="0.4"/><rect x="354.4" y="310.3" width="12.8" height="9.7" fill="rgb(132,208,88)" stroke="#fff" stroke-width="0.4"/><rect x="367.2" y="310.3" width="12.8" height="9.7" fill="rgb(132,209,89)" stroke="#fff" stroke-width="0.4"/><rect x="380.0" y="310.3" width="12.8" height="9.7" fill="rgb(134,209,89)" stroke="#fff" stroke-width="0.4"/><rect x="392.8" y="310.3" width="12.8" height="9.7" fill="rgb(136,210,90)" stroke="#fff" stroke-width="0.4"/><rect x="405.6" y="310.3" width="12.8" height="9.7" fill="rgb(136,210,90)" stroke="#fff" stroke-width="0.4"/><rect x="418.4" y="310.3" width="12.8" height="9.7" fill="rgb(136,210,90)" stroke="#fff" stroke-width="0.4"/><rect x="431.2" y="310.3" width="12.8" height="9.7" fill="rgb(135,210,90)" stroke="#fff" stroke-width="0.4"/><rect x="60.0" y="300.7" width="12.8" height="9.7" fill="rgb(187,147,81)" stroke="#fff" stroke-width="0.4"/><rect x="72.8" y="300.7" width="12.8" height="9.7" fill="rgb(189,141,80)" stroke="#fff" stroke-width="0.4"/><rect x="85.6" y="300.7" width="12.8" height="9.7" fill="rgb(188,143,80)" stroke="#fff" stroke-width="0.4"/><rect x="98.4" y="300.7" width="12.8" height="9.7" fill="rgb(188,144,81)" stroke="#fff" stroke-width="0.4"/><rect x="111.2" y="300.7" width="12.8" height="9.7" fill="rgb(187,145,81)" stroke="#fff" stroke-width="0.4"/><rect x="124.0" y="300.7" width="12.8" height="9.7" fill="rgb(187,147,81)" stroke="#fff" stroke-width="0.4"/><rect x="136.8" y="300
<p class='muted'>圈=理论最优组合。色越绿=净盈利越高。注意"宽绿区""单点深绿"更稳健。</p>
<h2>3. 如何获取 MAE/MFE 数据</h2>
<p class='muted'>MT5 标准 xlsx 报告不含逐笔 MAE/MFE。需在 EA 的 OnDeinit 里加如下代码导出 CSV,再喂给本工具:</p>
<pre>// ====== MAE/MFE 日志片段(粘贴进 EA ======
// 在文件顶部加:
#include &lt;Trade\DealInfo.mqh&gt;
#include &lt;Trade\PositionInfo.mqh&gt;
// 在 OnDeinit(const int reason) 末尾加:
void ExportMAEMFE()
{
string fname = &quot;mae_mfe_&quot; + TimeToString(TimeCurrent(), TIME_DATE) + &quot;.csv&quot;;
int h = FileOpen(fname, FILE_WRITE | FILE_CSV | FILE_ANSI, &#x27;,&#x27;);
if(h == INVALID_HANDLE) { Print(&quot;MAE/MFE: 文件打开失败&quot;); return; }
FileWrite(h, &quot;ticket&quot;,&quot;direction&quot;,&quot;open_time&quot;,&quot;close_time&quot;,&quot;open_price&quot;,&quot;close_price&quot;,
&quot;mae_points&quot;,&quot;mfe_points&quot;,&quot;profit_money&quot;);
HistorySelect(0, TimeCurrent() + 86400);
int total = HistoryDealsTotal();
// 按订单(order)配对 in/out
for(int i = 0; i &lt; total; i++)
{
ulong dealIn = HistoryDealGetTicket(i);
if(HistoryDealGetInteger(dealIn, DEAL_ENTRY) != DEAL_ENTRY_IN) continue;
long order = HistoryDealGetInteger(dealIn, DEAL_ORDER);
ulong dealOut = 0;
// 找同 order 的 out 成交
for(int j = i + 1; j &lt; total; j++)
{
ulong d = HistoryDealGetTicket(j);
if(HistoryDealGetInteger(d, DEAL_ORDER) == order &amp;&amp;
HistoryDealGetInteger(d, DEAL_ENTRY) == DEAL_ENTRY_OUT)
{ dealOut = d; break; }
}
if(dealOut == 0) continue;
datetime tIn = (datetime)HistoryDealGetInteger(dealIn, DEAL_TIME);
datetime tOut = (datetime)HistoryDealGetInteger(dealOut, DEAL_TIME);
double pIn = HistoryDealGetDouble(dealIn, DEAL_PRICE);
double pOut = HistoryDealGetDouble(dealOut, DEAL_PRICE);
long type = HistoryDealGetInteger(dealIn, DEAL_TYPE); // DEAL_TYPE_BUY / SELL
double profit = HistoryDealGetDouble(dealOut, DEAL_PROFIT)
+ HistoryDealGetDouble(dealOut, DEAL_SWAP)
+ HistoryDealGetDouble(dealOut, DEAL_COMMISSION);
string dir = (type == DEAL_TYPE_BUY) ? &quot;long&quot; : &quot;short&quot;;
// 扫描持仓期间最高/最低价算 MAE/MFE(点)
double mfe = 0, mae = 0;
double pt = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
for(datetime t = tIn; t &lt;= tOut; t += PeriodSeconds())
{
double hi = iHigh(_Symbol, PERIOD_M1, iBarShift(_Symbol, PERIOD_M1, t, false));
double lo = iLow (_Symbol, PERIOD_M1, iBarShift(_Symbol, PERIOD_M1, t, false));
if(hi &lt;= 0 || lo &lt;= 0) continue;
if(type == DEAL_TYPE_BUY)
{
double fav = (hi - pIn) / pt; // 有利
double adv = (pIn - lo) / pt; // 不利
if(fav &gt; mfe) mfe = fav;
if(adv &gt; mae) mae = adv;
}
else
{
double fav = (pIn - lo) / pt;
double adv = (hi - pIn) / pt;
if(fav &gt; mfe) mfe = fav;
if(adv &gt; mae) mae = adv;
}
}
FileWrite(h, order, dir, TimeToString(tIn), TimeToString(tOut),
DoubleToString(pIn, _Digits), DoubleToString(pOut, _Digits),
DoubleToString(mae, 1), DoubleToString(mfe, 1),
DoubleToString(profit, 2));
}
FileClose(h);
Print(&quot;MAE/MFE 已导出: &quot;, fname);
}
// 在 OnDeinit 里调用: ExportMAEMFE();
// ====== 片段结束 ======
</pre>
<footer>由 mae_mfe.py 生成 · 2026-06-28 02:13</footer>
</div></body></html>