#property version "3.00"
#property strict
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
/*
⚠️⚠️⚠️ CRITICAL WARNING ⚠️⚠️⚠️
This EA uses MARTINGALE and GRID strategies which are EXTREMELY RISKY!
- Can wipe out your account in unfavorable conditions
- Requires large capital and proper risk management
- Strong trending markets can cause catastrophic losses
- Only use with money you can afford to LOSE COMPLETELY
- Recommended: Demo test for 3+ months minimum
- Professional traders only
You have been warned!
*/
input group "=== ???? Profit & Risk Targets ==="
input double InpDailyProfitTarget = 200.0; // Daily Profit Target ($)
input double InpMaxDailyLoss = 500.0; // Max Daily Loss ($) - CRITICAL!
input double InpGridProfitTarget = 50.0; // Grid Profit Target ($)
input bool InpStopAfterTarget = true; // Stop After Daily Target
input group "=== ???? Grid Settings ==="
input double InpInitialLot = 0.01; // Initial Lot Size
input double InpGridDistance = 20.0; // Grid Distance (Pips)
input int InpMaxGridLevels = 10; // Maximum Grid Levels ⚠️
input bool InpUseDynamicGrid = true; // Dynamic Grid (ATR-based)
input double InpGridATRMultiplier = 1.5; // ATR Multiplier for Grid
input group "=== ???? Martingale Settings ==="
input bool InpUseMartingale = true; // Enable Martingale
input double InpMartingaleMultiplier = 1.5; // Martingale Multiplier ⚠️
input int InpMaxMartingaleLevels = 8; // Max Martingale Levels
input bool InpUseProgressiveMartingale = true; // Progressive Martingale
input double InpMaxLotSize = 10.0; // Maximum Lot Size (Safety)
input group "=== ???? Hedging System ==="
input bool InpEnableHedging = true; // Enable Hedging
input int InpHedgeAfterLevel = 3; // Hedge After Grid Level
input double InpHedgeLotMultiplier = 1.0; // Hedge Lot Multiplier
input bool InpCloseHedgeOnProfit = true; // Close Hedge When Profitable
input bool InpDynamicHedging = true; // Dynamic Hedge Adjustment
input group "=== ???? Zone Recovery ==="
input bool InpUseZoneRecovery = true; // Zone Recovery System
input double InpZoneSize = 50.0; // Recovery Zone Size (Pips)
input double InpZoneRecoveryMultiplier = 2.0; // Zone Recovery Lot Multiplier
input bool InpBreakevenZone = true; // Move to Breakeven in Zone
input group "=== ???? Aggressive Features ==="
input bool InpDoubleSidedGrid = true; // Both Buy & Sell Grids
input bool InpPyramiding = false; // Add to Winners ⚠️
input double InpPyramidDistance = 30.0; // Pyramid Distance (Pips)
input int InpMaxPyramidLevels = 3; // Max Pyramid Levels
input bool InpUseBreakevenAll = true; // Breakeven All Positions
input double InpBreakevenProfit = 100.0; // Breakeven at Total Profit ($)
input group "=== ???? Smart Features ==="
input bool InpUseVirtualTP = true; // Virtual Take Profit
input bool InpCloseInProfit = true; // Close All in Profit
input double InpMinProfitToClose = 30.0; // Min Profit to Close All ($)
input bool InpTrailingGrid = true; // Trailing for Grid
input double InpTrailingDistance = 25.0; // Trailing Distance (Pips)
input group "=== ???? Market Filters ==="
input bool InpTradeOnlyTrend = false; // Trade Only in Trend
input int InpTrendMAPeriod = 100; // Trend MA Period
input bool InpAvoidHighVolatility = true; // Avoid High Volatility
input double InpMaxVolatilityATR = 30.0; // Max ATR to Trade
input double InpMaxSpread = 5.0; // Max Spread (Pips)
input group "=== ????️ Emergency Protection ==="
input bool InpUseEquityStop = true; // Equity Stop Loss
input double InpEquityStopPercent = 30.0; // Equity Stop % ⚠️
input double InpMaxDrawdownPercent = 25.0; // Max Drawdown %
input bool InpEmergencyCloseAll = true; // Emergency Close Button
input double InpMaxFloatingLoss = 300.0; // Max Floating Loss ($)
input group "=== ⏰ Trading Times ==="
input bool InpUseTimeFilter = false; // Use Time Filter
input int InpStartHour = 0; // Start Hour
input int InpEndHour = 23; // End Hour
input bool InpAvoidWeekend = true; // Avoid Weekend
input group "=== ???? Visual & Alerts ==="
input bool InpShowPanel = true; // Show Dashboard
input bool InpShowGridLines = true; // Show Grid Lines
input bool InpSendAlerts = true; // Send Alerts
input color InpBuyColor = clrBlue; // Buy Grid Color
input color InpSellColor = clrRed; // Sell Grid Color
input color InpHedgeColor = clrOrange; // Hedge Color
input group "=== ⚙️ System ==="
input int InpMagicBuy = 111111; // Magic Number Buy
input int InpMagicSell = 222222; // Magic Number Sell
input int InpMagicHedge = 333333; // Magic Number Hedge
input string InpComment = "GridMartingale"; // Trade Comment
CTrade trade;
CPositionInfo positionInfo;
CAccountInfo accountInfo;
double dailyProfit = 0.0;
datetime lastResetDate = 0;
bool tradingEnabled = true;
double startingBalance = 0.0;
double startingEquity = 0.0;
double lastBuyPrice = 0.0;
double lastSellPrice = 0.0;
int buyGridLevel = 0;
int sellGridLevel = 0;
double buyGridLots[];
double sellGridLots[];
ulong buyTickets[];
ulong sellTickets[];
ulong hedgeTickets[];
double buyZoneStart = 0.0;
double sellZoneStart = 0.0;
bool inBuyZone = false;
bool inSellZone = false;
int totalGridTrades = 0;
int gridWins = 0;
int gridLosses = 0;
double totalProfit = 0.0;
double maxDrawdown = 0.0;
double peakEquity = 0.0;
int OnInit()
{
// код доступен только после оплаты
}
void OnDeinit(const int reason)
{
EventKillTimer();
ObjectsDeleteAll(0, "GridLine");
ObjectsDeleteAll(0, "Panel");
Print("╔═══════════════════════════════════════════════════════════╗");
Print("║ AGGRESSIVE GRID MARTINGALE EA STOPPED ║");
Print("╚═══════════════════════════════════════════════════════════╝");
Print("Statistics:");
Print(" Total Grid Trades: ", totalGridTrades);
Print(" Grid Wins: ", gridWins);
Print(" Grid Losses: ", gridLosses);
if(totalGridTrades > 0)
Print(" Win Rate: ", NormalizeDouble((double)gridWins/totalGridTrades*100, 2), "%");
Print(" Max Drawdown: $", NormalizeDouble(maxDrawdown, 2));
Print("═══════════════════════════════════════════════════════════");
}
void OnTimer()
{
if(InpShowPanel) {
DrawAdvancedPanel();
}
if(InpShowGridLines) {
DrawGridLines();
}
CheckEmergencyStop();
}
void OnTick()
{
// код доступен только после оплаты
}
void CheckAndResetDaily()
{
datetime currentDate = TimeCurrent();
MqlDateTime dtCurrent;
TimeToStruct(currentDate, dtCurrent);
MqlDateTime dtLast;
TimeToStruct(lastResetDate, dtLast);
if(dtCurrent.day != dtLast.day || lastResetDate == 0) {
dailyProfit = 0.0;
tradingEnabled = true;
lastResetDate = currentDate;
startingBalance = accountInfo.Balance();
startingEquity = accountInfo.Equity();
peakEquity = startingEquity;
buyGridLevel = 0;
sellGridLevel = 0;
lastBuyPrice = 0.0;
lastSellPrice = 0.0;
ArrayInitialize(buyGridLots, 0);
ArrayInitialize(sellGridLots, 0);
Print("═══════════════════════════════════════════════════════════");
Print("NEW TRADING DAY - Grid Martingale EA");
Print("Starting Balance: $", NormalizeDouble(startingBalance, 2));
Print("═══════════════════════════════════════════════════════════");
}
}
void UpdateDailyProfit()
{
datetime today = TimeCurrent();
MqlDateTime dtToday;
TimeToStruct(today, dtToday);
dtToday.hour = 0;
dtToday.min = 0;
dtToday.sec = 0;
datetime dayStart = StructToTime(dtToday);
dailyProfit = 0.0;
HistorySelect(dayStart, TimeCurrent());
int totalDeals = HistoryDealsTotal();
for(int i = 0; i < totalDeals; i++) {
ulong ticket = HistoryDealGetTicket(i);
if(ticket > 0) {
long magic = HistoryDealGetInteger(ticket, DEAL_MAGIC);
if(magic == InpMagicBuy || magic == InpMagicSell || magic == InpMagicHedge) {
if(HistoryDealGetInteger(ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT) {
double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);
double swap = HistoryDealGetDouble(ticket, DEAL_SWAP);
double commission = HistoryDealGetDouble(ticket, DEAL_COMMISSION);
double tradeResult = profit + swap + commission;
dailyProfit += tradeResult;
if(tradeResult > 0) {
gridWins++;
} else {
gridLosses++;
}
totalGridTrades++;
}
}
}
}
totalProfit = dailyProfit;
}
void UpdateFloatingProfit()
{
double floatingProfit = 0.0;
for(int i = 0; i < PositionsTotal(); i++) {
if(positionInfo.SelectByIndex(i)) {
long magic = positionInfo.Magic();
if(magic == InpMagicBuy || magic == InpMagicSell || magic == InpMagicHedge) {
if(positionInfo.Symbol() == _Symbol) {
floatingProfit += positionInfo.Profit();
floatingProfit += positionInfo.Swap();
}
}
}
}
double currentEquity = accountInfo.Equity();
if(currentEquity > peakEquity) {
peakEquity = currentEquity;
}
double drawdown = peakEquity - currentEquity;
if(drawdown > maxDrawdown) {
maxDrawdown = drawdown;
}
}
bool CheckAllSafetyConditions()
{
if(InpStopAfterTarget && dailyProfit >= InpDailyProfitTarget) {
if(tradingEnabled) {
Print("???? DAILY TARGET REACHED: $", NormalizeDouble(dailyProfit, 2));
CloseAllPositions();
tradingEnabled = false;
if(InpSendAlerts) {
Alert("Daily profit target reached!");
}
}
return false;
}
if(dailyProfit <= -InpMaxDailyLoss) {
if(tradingEnabled) {
Print("⛔ MAX DAILY LOSS HIT: $", NormalizeDouble(dailyProfit, 2));
CloseAllPositions();
tradingEnabled = false;
if(InpSendAlerts) {
Alert("Max daily loss reached! Trading stopped.");
}
}
return false;
}
if(InpUseEquityStop) {
double equityPercent = (accountInfo.Equity() / startingEquity - 1.0) * 100.0;
if(equityPercent <= -InpEquityStopPercent) {
Print("???? EQUITY STOP TRIGGERED: ", NormalizeDouble(equityPercent, 2), "%");
CloseAllPositions();
tradingEnabled = false;
return false;
}
}
double drawdownPercent = (maxDrawdown / peakEquity) * 100.0;
if(drawdownPercent >= InpMaxDrawdownPercent) {
Print("???? MAX DRAWDOWN REACHED: ", NormalizeDouble(drawdownPercent, 2), "%");
CloseAllPositions();
tradingEnabled = false;
return false;
}
double floatingLoss = GetTotalFloatingProfit();
if(floatingLoss < -InpMaxFloatingLoss) {
Print("⚠️ Max floating loss reached: $", NormalizeDouble(floatingLoss, 2));
return false;
}
if(!CheckSpread()) {
return false;
}
if(InpUseTimeFilter && !IsWithinTradingHours()) {
return false;
}
if(InpAvoidWeekend && IsWeekend()) {
return false;
}
if(InpAvoidHighVolatility) {
double atr = iATRGet(_Symbol, PERIOD_CURRENT, 14);
double pipSize = GetPipSize();
double atrPips = atr / pipSize;
if(atrPips > InpMaxVolatilityATR) {
return false;
}
}
return tradingEnabled;
}
void CheckEmergencyStop()
{
}
bool ShouldOpenNewGrid()
{
int totalPos = CountAllPositions();
if(totalPos == 0) {
return true;
}
double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double gridDistance = GetDynamicGridDistance();
if(InpDoubleSidedGrid || lastSellPrice == 0.0) {
if(lastBuyPrice == 0.0 ||
(currentPrice < lastBuyPrice - gridDistance && buyGridLevel < InpMaxGridLevels)) {
return true;
}
}
if(InpDoubleSidedGrid || lastBuyPrice == 0.0) {
if(lastSellPrice == 0.0 ||
(currentPrice > lastSellPrice + gridDistance && sellGridLevel < InpMaxGridLevels)) {
return true;
}
}
return false;
}
void OpenGridPositions()
{
double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double gridDistance = GetDynamicGridDistance();
bool shouldBuy = false;
bool shouldSell = false;
if(InpDoubleSidedGrid) {
if(lastBuyPrice == 0.0 || currentPrice < lastBuyPrice - gridDistance) {
if(buyGridLevel < InpMaxGridLevels) {
shouldBuy = true;
}
}
if(lastSellPrice == 0.0 || currentPrice > lastSellPrice + gridDistance) {
if(sellGridLevel < InpMaxGridLevels) {
shouldSell = true;
}
}
}
else {
if(InpTradeOnlyTrend) {
int trend = GetTrendDirection();
if(trend > 0) shouldBuy = true;
else if(trend < 0) shouldSell = true;
}
else {
if(lastBuyPrice == 0.0 Показано первые 50% кода (символов: 23354)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.