MT4 EA源码:Trading strategy Heads or Tails 抛硬币随机开仓教学 EA|星钻会员尊享 - 资源合集论坛 - Meta Trade 4 - BBTrading

MT4 EA源码:Trading strategy Heads or Tails 抛硬币随机开仓教学 EA|星钻会员尊享

此资源为星钻会员专享,每日更新,收录于《大白EA宝库:星钻会员专属合集》。

这是经典「抛硬币」随机策略教学 EA:无持仓时用 MathRand 随机决定多空方向开仓,带固定止盈(默认 450 点)、止损(默认 390 点)、滑点与 MagicNumber 设置,适合理解 EA 信号模块的代码结构。本帖文件为 MT4 源码,打包成 zip 下载,解压后在 MetaEditor 里编译使用,参数与文件开头见下方源码预览。

源码预览(先看代码,再决定下不下)

本帖是源码 EA:G3_Heads_or_Tails.mq4,全文共 114 行。下面是它的全部可调参数与文件开头,完整源码在上方下载区,星钻会员可见。

可调参数(5 个)

  • double iStartLots = 0.01;(Initial trade volume (lot size))
  • int iTakeProfit = 450;(Take Profit distance in points)
  • int iStopLoss = 390;(Stop Loss distance in points)
  • int iMagicNumber = 227;(Unique identifier for this EA's trades)
  • int iSlippage = 30;(Maximum allowed slippage in points)
//+------------------------------------------------------------------+
//|                                            VR Heads or Tails.mq4 |
//|                                      Copyright 2026, Trading-Go. |
//+------------------------------------------------------------------+
#property copyright "@ Voldemar"                                       // Copyright information shown in terminal
#property link      "https://www.b123.com/"  //
#property version   "26.010"                                           // Version number of the Expert Advisor
#property strict                                                       // Enables strict code compilation mode
// --- Input parameters (configurable by user) ---
input double  iStartLots    = 0.01;   // Initial trade volume (lot size)
input int     iTakeProfit   = 450;    // Take Profit distance in points
input int     iStopLoss     = 390;    // Stop Loss distance in points
input int     iMagicNumber  = 227;    // Unique identifier for this EA's trades
input int     iSlippage     = 30;     // Maximum allowed slippage in points

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
// ---
   MathSrand(GetTickCount());                         // Seed the random number generator with current system time
// ---
   return(INIT_SUCCEEDED);                            // Return success code to terminal
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
// --- Count open positions managed by this EA ---
   int total = OrdersTotal(), b = 0, s = 0;     // total = number of all orders, b = buy count, s = sell count

// Loop through all existing orders
   for(int i = 0; i < total; i++)

风险提示:EA 交易有风险,过往与参数表现不代表未来。正式使用前先在模拟盘跑够样本,确认在自己的点差、滑点环境下仍符合预期,再决定是否上实盘。

版本说明:资源随 MT4/MT5 版本迭代可能失效,如遇失效请在本帖留言反馈。

请登录后发表评论