📢 AnnouncementsBeginner guide: posting, points and community rulesMT4/MT5 免安装包(Windows+安卓 APK)Free Download(0 Points)Beginner basics: how to earn points and activity
Community › Functions › CopyRates()/CopyClose():历史数据批量

🏷 Functions CopyRates()/CopyClose():历史数据批量读取

admin Senior AA · 2026-11-12 20:43 · Views 88 · replies 0
MT5 读历史 K 线的标配Functions。
【基本用法】MqlRates rates[]; int n = CopyRates(Symbol(), PERIOD_H1, 0, 100, rates); 一次取 100 根 H1 K 线(含 OHLC、tick_volume、spread、time)。
【两种取法】
- 起点模式:CopyRates(symbol, tf, start_pos, count, array);
- time模式:CopyRates(symbol, tf, start_time, stop_time, array)。
【配合 ArraySetAsSeries】CopyBuffer/CopyRates Back数组default index0=最旧,SetAsSeries(rates, true) 后 index0=Latest,写Strategy逻辑更直观。
【Back值检查】n<0 是Failed(数据未加载完,用 BarsCalculated 检查),n<count 是部分Success——都要Handle。
【性能建议】每根 K 线只copy一次(新 K 线检测后再Refresh),不要每个 tick 都全量copy,回测速度差十倍。
← TimeCurrent()/TimeTo OnTick() 与 OnTimer() →

Replies(0)

No replies yet — grab the sofa