基于 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
} |