| MT5,欧元兑美元,H1,要求十年或以上数据,99.9%精度。请评论效图给我,请说明是回测的加好友。 
 #property copyright "Trading Strategy"
 #property version   "1.00"
 int OnInit()
 {
 double pre_open  = iOpen(Symbol(), Period(), 1);
 double pre_close = iClose(Symbol(), Period(), 1);
 // 当前货币对,当前图表周期,1柱开盘价和收盘价
 
 // 全局变量
 double previousLot = 0.00; // 记录上一次平仓时的仓位大小
 datetime lastBarTime = 0; // 记录最后处理的K线时间
 
 void OnTick()
 {
 // 检查新K线形成
 datetime currentBarTime = iTime(_Symbol, _Period, 0);
 if(currentBarTime != lastBarTime)
 {
 lastBarTime = currentBarTime;
 
 // 平掉所有持仓
 CloseAllPositions();
 // 平仓函数:关闭所有持仓
 void CloseAllPositions()
 {
 for(int i = PositionsTotal()-1; i >= 0; i--)
 {
 PositionSelectByTicket(PositionsGetTicket(i));
 PositionClose(PositionsGetVolume(), PositionsGetSL(), PositionsGetTP());
 }
 }
 
 // 获取平台手数限制
 double minLot = MarketInfo(symbol, MODE_MINLOT);
 double maxLot = MarketInfo(symbol, MODE_MAXLOT);
 
 // 计算新仓位大小
 double newLot = previousLot + minLot;
 if(newLot > maxLot) newLot = maxLot;
 
 // 根据K线类型建仓
 if(pre_close > pre_open)
 MqlTradeRequest request = { };
 MqlTradeResult result = { };
 // 设置交易请求参数
 request.action = TRADE_ACTION_DEAL; // 立即执行交易
 request.symbol = Symbol() ; // 交易品种
 request.volume = newLot; // 交易量
 request.price = NormalizeDouble(Bid, _Digits); // 交易价格
 request.type = ORDER_TYPE_BUY; // 买入订单
 request.deviation =3; // 滑点
 request.magic = 12345; // 订单魔术码
 
 else if(pre_close < pre_open)
 MqlTradeRequest request = { };
 MqlTradeResult result = { };
 // 设置交易请求参数
 request.action = TRADE_ACTION_DEAL; // 立即执行交易
 request.symbol = Symbol() ; // 交易品种
 request.volume = newLot; // 交易量
 request.price = NormalizeDouble(Bid, _Digits); // 交易价格
 request.type = ORDER_TYPE_SELL
 ; // 买入订单
 request.deviation =3; // 滑点
 request.magic = 12345; // 订单魔术码
 
 //  更新仓位记录
 if(OrderTotal() > 0)
 previousLot = newLot;
 }
 }
 |