骑着猪抢银河 发表于 2025-12-4 17:23:43

求一个马丁EA源码

求这个马丁的源码

Jasonsren 发表于 2025-12-4 18:16:31

纯马丁?

zyeabx666 发表于 2025-12-4 18:55:15

佛跳墙,这个我有

detoihc 发表于 2025-12-4 19:34:10

要不?我这有一份一模一样的

峰回路转 发表于 2025-12-14 22:30:32

//+------------------------------------------------------------------+
//|                                                金牛马丁EA.mq4 |
//|                        Copyright 2025, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//--- 输入参数(对应截图配置项)
input ENUM_ORDER_TYPE    LotType      = ORDER_TYPE_BUY;      // 交易方向
input double            LotSize      = 0.01;                  // 固定手数
input double            AddLotMulti    = 1.3;                   // 加仓倍数
input int               Slippage       = 50;                  // 最大挂单差
input int               AddDistance    = 200;                   // 加仓距离(点)
input int               OrderDistance= 30;                  // 挂单距离(点)
input double            EquityStop   = 100000000.0;         // 浮亏金额
input int               StopTime       = 19;                  // 浮亏平仓暂停时间
input double            OpenEquity   = 60000.0;               // 开仓资金
input bool            UseMagic       = true;                  // 使用EA识别码
input int               MagicNumber    = 20210339;            // EA识别码
input string            OrderComment   = "购买加微信";          // 订单备注
input int               MA_Period      = 10;                  // 均线周期
input ENUM_MA_METHOD    MA_Method      = MODE_SMA;            // 均线移动平均
input ENUM_APPLIED_PRICE MA_Price      = PRICE_CLOSE;         // 均线应用价格

//--- 全局变量
double g_lastOrderPrice = 0.0; // 上一单开仓价格
int    g_orderCount   = 0;   // 加仓次数

//+------------------------------------------------------------------+
//| Expert initialization function                                 |
//+------------------------------------------------------------------+
int OnInit()
{
   // 检查资金是否满足开仓要求
   if(AccountEquity() < OpenEquity)
   {
      Print("账户资金不足,低于开仓资金阈值", OpenEquity);
      return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   // 清空全局变量
   g_lastOrderPrice = 0.0;
   g_orderCount   = 0;
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   // 检查是否有未平仓订单
   if(OrdersTotal() == 0)
   {
      // 无订单时开首单
      OpenFirstOrder();
      g_orderCount = 1;
   }
   else
   {
      // 有订单时判断是否需要加仓
      CheckAddOrder();
   }
   
   // 浮亏平仓逻辑
   CheckEquityStop();
}

//+------------------------------------------------------------------+
//| 开首单函数                                                       |
//+------------------------------------------------------------------+
bool OpenFirstOrder()
{
   double ask = Ask;
   double bid = Bid;
   // 挂单/市价单逻辑(根据加仓方式)
   int ticket = OrderSend(Symbol(), LotType, LotSize,
                        (LotType == ORDER_TYPE_BUY) ? ask : bid,
                        Slippage, 0, 0, OrderComment, MagicNumber, 0,
                        (LotType == ORDER_TYPE_BUY) ? clrGreen : clrRed);
   if(ticket < 0)
   {
      Print("首单开仓失败,错误码:", GetLastError());
      return(false);
   }
   g_lastOrderPrice = (LotType == ORDER_TYPE_BUY) ? ask : bid;
   return(true);
}

//+------------------------------------------------------------------+
//| 检查加仓函数                                                   |
//+------------------------------------------------------------------+
void CheckAddOrder()
{
   double currentPrice = (LotType == ORDER_TYPE_BUY) ? Bid : Ask;
   double priceDiff = MathAbs(currentPrice - g_lastOrderPrice);
   double pointDiff = priceDiff / Point;
   
   // 达到加仓距离时执行加仓
   if(pointDiff >= AddDistance)
   {
      double addLot = LotSize * MathPow(AddLotMulti, g_orderCount);
      int ticket = OrderSend(Symbol(), LotType, addLot,
                           (LotType == ORDER_TYPE_BUY) ? Ask : Bid,
                           Slippage, 0, 0, OrderComment, MagicNumber, 0,
                           (LotType == ORDER_TYPE_BUY) ? clrGreen : clrRed);
      if(ticket > 0)
      {
         g_lastOrderPrice = (LotType == ORDER_TYPE_BUY) ? Ask : Bid;
         g_orderCount++;
         Print("第", g_orderCount, "次加仓成功,手数:", addLot);
      }
      else
      {
         Print("加仓失败,错误码:", GetLastError());
      }
   }
}

//+------------------------------------------------------------------+
//| 浮亏平仓检查函数                                                 |
//+------------------------------------------------------------------+
void CheckEquityStop()
{
   double equity = AccountEquity();
   double balance = AccountBalance();
   double loss = balance - equity;
   
   // 浮亏达到阈值时平仓
   if(loss >= EquityStop)
   {
      CloseAllOrders();
      Print("浮亏达到", EquityStop, ",执行全部平仓");
   }
}

//+------------------------------------------------------------------+
//| 平仓所有订单函数                                                 |
//+------------------------------------------------------------------+
void CloseAllOrders()
{
   for(int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {
            int ticket = OrderClose(OrderTicket(), OrderLots(),
                                    (OrderType() == OP_BUY) ? Bid : Ask,
                                    Slippage, clrRed);
            if(ticket < 0)
            {
               Print("平仓失败,错误码:", GetLastError());
            }
         }
      }
   }
}
//+------------------------------------------------------------------+

峰回路转 发表于 2025-12-14 22:32:24

//+------------------------------------------------------------------+
//|                                                金牛马丁EA.mq4 |
//|                        Copyright 2025, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//--- 输入参数(对应截图配置项)
input ENUM_ORDER_TYPE    LotType      = ORDER_TYPE_BUY;      // 交易方向
input double            LotSize      = 0.01;                  // 固定手数
input double            AddLotMulti    = 1.3;                   // 加仓倍数
input int               Slippage       = 50;                  // 最大挂单差
input int               AddDistance    = 200;                   // 加仓距离(点)
input int               OrderDistance= 30;                  // 挂单距离(点)
input double            EquityStop   = 100000000.0;         // 浮亏金额
input int               StopTime       = 19;                  // 浮亏平仓暂停时间
input double            OpenEquity   = 60000.0;               // 开仓资金
input bool            UseMagic       = true;                  // 使用EA识别码
input int               MagicNumber    = 20210339;            // EA识别码
input string            OrderComment   = "购买加微信";          // 订单备注
input int               MA_Period      = 10;                  // 均线周期
input ENUM_MA_METHOD    MA_Method      = MODE_SMA;            // 均线移动平均
input ENUM_APPLIED_PRICE MA_Price      = PRICE_CLOSE;         // 均线应用价格

//--- 全局变量
double g_lastOrderPrice = 0.0; // 上一单开仓价格
int    g_orderCount   = 0;   // 加仓次数

//+------------------------------------------------------------------+
//| Expert initialization function                                 |
//+------------------------------------------------------------------+
int OnInit()
{
   // 检查资金是否满足开仓要求
   if(AccountEquity() < OpenEquity)
   {
      Print("账户资金不足,低于开仓资金阈值", OpenEquity);
      return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   // 清空全局变量
   g_lastOrderPrice = 0.0;
   g_orderCount   = 0;
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   // 检查是否有未平仓订单
   if(OrdersTotal() == 0)
   {
      // 无订单时开首单
      OpenFirstOrder();
      g_orderCount = 1;
   }
   else
   {
      // 有订单时判断是否需要加仓
      CheckAddOrder();
   }
   
   // 浮亏平仓逻辑
   CheckEquityStop();
}

//+------------------------------------------------------------------+
//| 开首单函数                                                       |
//+------------------------------------------------------------------+
bool OpenFirstOrder()
{
   double ask = Ask;
   double bid = Bid;
   // 挂单/市价单逻辑(根据加仓方式)
   int ticket = OrderSend(Symbol(), LotType, LotSize,
                        (LotType == ORDER_TYPE_BUY) ? ask : bid,
                        Slippage, 0, 0, OrderComment, MagicNumber, 0,
                        (LotType == ORDER_TYPE_BUY) ? clrGreen : clrRed);
   if(ticket < 0)
   {
      Print("首单开仓失败,错误码:", GetLastError());
      return(false);
   }
   g_lastOrderPrice = (LotType == ORDER_TYPE_BUY) ? ask : bid;
   return(true);
}

//+------------------------------------------------------------------+
//| 检查加仓函数                                                   |
//+------------------------------------------------------------------+
void CheckAddOrder()
{
   double currentPrice = (LotType == ORDER_TYPE_BUY) ? Bid : Ask;
   double priceDiff = MathAbs(currentPrice - g_lastOrderPrice);
   double pointDiff = priceDiff / Point;
   
   // 达到加仓距离时执行加仓
   if(pointDiff >= AddDistance)
   {
      double addLot = LotSize * MathPow(AddLotMulti, g_orderCount);
      int ticket = OrderSend(Symbol(), LotType, addLot,
                           (LotType == ORDER_TYPE_BUY) ? Ask : Bid,
                           Slippage, 0, 0, OrderComment, MagicNumber, 0,
                           (LotType == ORDER_TYPE_BUY) ? clrGreen : clrRed);
      if(ticket > 0)
      {
         g_lastOrderPrice = (LotType == ORDER_TYPE_BUY) ? Ask : Bid;
         g_orderCount++;
         Print("第", g_orderCount, "次加仓成功,手数:", addLot);
      }
      else
      {
         Print("加仓失败,错误码:", GetLastError());
      }
   }
}

//+------------------------------------------------------------------+
//| 浮亏平仓检查函数                                                 |
//+------------------------------------------------------------------+
void CheckEquityStop()
{
   double equity = AccountEquity();
   double balance = AccountBalance();
   double loss = balance - equity;
   
   // 浮亏达到阈值时平仓
   if(loss >= EquityStop)
   {
      CloseAllOrders();
      Print("浮亏达到", EquityStop, ",执行全部平仓");
   }
}

//+------------------------------------------------------------------+
//| 平仓所有订单函数                                                 |
//+------------------------------------------------------------------+
void CloseAllOrders()
{
   for(int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {
            int ticket = OrderClose(OrderTicket(), OrderLots(),
                                    (OrderType() == OP_BUY) ? Bid : Ask,
                                    Slippage, clrRed);
            if(ticket < 0)
            {
               Print("平仓失败,错误码:", GetLastError());
            }
         }
      }
   }
}
//+------------------------------------------------------------------+

可爱的雷宇航 发表于 2026-1-7 15:30:08

这个马丁从6.20跑到现在2w刀盈利8.5w刀
页: [1]
查看完整版本: 求一个马丁EA源码