基于 E=mC^2  机器人写出源码:欢迎测试,我没测试,不知能不能通过测试。 //+------------------------------------- ...

| 发表于 2025-5-27 08:51:04 | 显示全部楼层 |复制链接
基于 E=mC^2  机器人写出源码:欢迎测试,我没测试,不知能不能通过测试。
//+------------------------------------------------------------------+
//|                                                      E=mc2EA.mq4 |
//|                                     Copyright 2023, Your Name     |
//|                                             https://www.yoursite.com |
//+------------------------------------------------------------------+
#property strict

//--- Inputs
input double MoneyRisk    = 100;       // Risk per trade (m)
input double StrategyPower = 2.0;      // Strategy efficiency (c)
input int    StopLoss     = 100;       // SL in points
input int    TakeProfit   = 200;       // TP in points

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   if (OrdersTotal() == 0)
   {
      double lots = CalculateLots();
      int signal  = GetTradeSignal();
      
      if (signal == 1) OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask-StopLoss*Point, Ask+TakeProfit*Point, "E=mc² Buy", 0);
      if (signal == -1) OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid+StopLoss*Point, Bid-TakeProfit*Point, "E=mc² Sell", 0);
   }
}

//+------------------------------------------------------------------+
//| Calculate lots based on E=mc² metaphor                           |
//+------------------------------------------------------------------+
double CalculateLots()
{
   double contractSize = MarketInfo(Symbol(), MODE_TICKVALUE) / MarketInfo(Symbol(), MODE_TICKSIZE);
   double riskEnergy  = MoneyRisk * MathPow(StrategyPower, 2);
   double lots        = NormalizeDouble(riskEnergy / (StopLoss * contractSize), 2);
   return lots > 0.01 ? lots : 0.01;
}

//+------------------------------------------------------------------+
//| Generate trade signal (example: MA Cross)                        |
//+------------------------------------------------------------------+
int GetTradeSignal()
{
   double maFast = iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, 0);
   double maSlow = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, 0);
   
   if (maFast > maSlow) return 1;   // Buy
   if (maFast < maSlow) return -1;  // Sell
   return 0;                        // No signal
}
举报

评论 使用道具

精彩评论2

傲天
D
| 发表于 2025-5-27 09:01:32 | 显示全部楼层
这是指标还是ea
举报

点赞 评论 使用道具

NB721
D
 楼主 | 发表于 2025-5-27 09:05:53 | 显示全部楼层
EA,MT4的。这电脑没有交易软件。没测试。
举报

点赞 评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册