Untitled
//+------------------------------------------------------------------+ //| SmartBTC_EA_v3.mq4| //| Expert Advisor con Integrazione della Logica di Galaxy BTC Pro | //+------------------------------------------------------------------+ #property strict // Parametri di input ottimizzati input double RiskPercent = 1.5; // Percentuale di rischio per trade input double InitialStopLossPercentage = 0.25; // Stop-Loss iniziale al momento dell'ingresso input double DynamicStopLossPercentage = 0.01; // Stop-Loss dinamico durante il movimento input double ProfitStopLossOffset = 0.05; // Offset Stop-Loss dopo il raggiungimento del profitto input int TakeProfitMultiplier = 4; // Moltiplicatore ATR per Take-Profit input bool EnableTrailingStop = true; // Abilita Trailing Stop input double MaxDrawdown = 10.0; // Drawdown massimo in % per stop automatico input double MinATRThreshold = 0.0005; // Soglia minima di ATR per evitare bassa volatilità input int MinVolumeThreshold = 100; // Soglia minima di volume per evitare mercati illiquidi input bool EnableBreakoutStrategy = true; // Abilita strategia di breakout input bool EnableSentimentAnalysis = true; // Abilita analisi del sentiment // Variabili globali double atrValue; double accountEquityStart; datetime lastOrderTime = 0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { accountEquityStart = AccountEquity(); Print("SmartBTC_EA_v3 inizializzato correttamente!"); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { atrValue = iATR(NULL, 0, 14, 0); double currentVolume = iVolume(NULL, 0, 0); if(atrValue <= MinATRThreshold) { Print("Volatilità troppo bassa (ATR: ", atrValue, "), nessun ordine aperto."); return; } if(currentVolume < MinVolumeThreshold) { Print("Volume troppo basso (", currentVolume, "), nessun ordine aperto."); return; } if(AccountEquity() < (accountEquityStart * (1 - MaxDrawdown / 100))) { Print("Drawdown massimo raggiunto. Blocco temporaneo delle operazioni."); return; } ManageOpenTrades(); if(TimeCurrent() - lastOrderTime >= 30) { int trend = DetermineBalancedTrend(); Print("Trend rilevato: ", trend); if(trend == OP_BUY) { Print("Trend favorevole per BUY, apertura ordine..."); if(OpenBuyOrder()) lastOrderTime = TimeCurrent(); } else if(trend == OP_SELL) { Print("Trend favorevole per SELL, apertura ordine..."); if(OpenSellOrder()) lastOrderTime = TimeCurrent(); } else { Print("Nessun trend chiaro rilevato o condizioni incerte, nessun ordine aperto."); } } } //+------------------------------------------------------------------+ //| Determina il Trend Bilanciato su M1, M5, M15 e M30 | //+------------------------------------------------------------------+ int DetermineBalancedTrend() { double maShortM1 = iMA(NULL, PERIOD_M1, 5, 0, MODE_EMA, PRICE_CLOSE, 0); double maLongM1 = iMA(NULL, PERIOD_M1, 20, 0, MODE_EMA, PRICE_CLOSE, 0); double maShortM5 = iMA(NULL, PERIOD_M5, 5, 0, MODE_EMA, PRICE_CLOSE, 0); double maLongM5 = iMA(NULL, PERIOD_M5, 20, 0, MODE_EMA, PRICE_CLOSE, 0); double maShortM15 = iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, PRICE_CLOSE, 0); double maLongM15 = iMA(NULL, PERIOD_M15, 20, 0, MODE_EMA, PRICE_CLOSE, 0); double maShortM30 = iMA(NULL, PERIOD_M30, 5, 0, MODE_EMA, PRICE_CLOSE, 0); double maLongM30 = iMA(NULL, PERIOD_M30, 20, 0, MODE_EMA, PRICE_CLOSE, 0); int buyCount = 0; int sellCount = 0; if(maShortM1 > maLongM1) buyCount++; else sellCount++; if(maShortM5 > maLongM5) buyCount++; else sellCount++; if(maShortM15 > maLongM15) buyCount++; else sellCount++; if(maShortM30 > maLongM30) buyCount++; else sellCount++; if(MathAbs(maShortM1 - maLongM1) < Point * 10 || MathAbs(maShortM5 - maLongM5) < Point * 10) { Print("Medie mobili troppo vicine, condizioni di incertezza."); return -1; } if(buyCount >= 3) return OP_BUY; else if(sellCount >= 3) return OP_SELL; return -1; } //+------------------------------------------------------------------+ //| Apertura Ordine Buy | //+------------------------------------------------------------------+ bool OpenBuyOrder() { double sl = Bid * (1.0 - InitialStopLossPercentage / 100.0); double tp = Bid + (atrValue * TakeProfitMultiplier); double lotSize = 0.01; int ticket = OrderSend(Symbol(), OP_BUY, lotSize, Ask, 3, sl, tp, "BTC Buy", 0, 0, clrBlue); return (ticket >= 0); } //+------------------------------------------------------------------+ //| Apertura Ordine Sell | //+------------------------------------------------------------------+ bool OpenSellOrder() { double sl = Ask * (1.0 + InitialStopLossPercentage / 100.0); double tp = Ask - (atrValue * TakeProfitMultiplier); double lotSize = 0.01; int ticket = OrderSend(Symbol(), OP_SELL, lotSize, Bid, 3, sl, tp, "BTC Sell", 0, 0, clrRed); return (ticket >= 0); } //+------------------------------------------------------------------+ //| Gestione delle Operazioni Aperte | //+------------------------------------------------------------------+ void ManageOpenTrades() { for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol()) { double profit = OrderProfit(); double takeProfitTarget = atrValue * TakeProfitMultiplier; if(OrderType() == OP_BUY) { double dynamicSL = Bid * (1.0 - DynamicStopLossPercentage / 100.0); if(profit > 0) dynamicSL = Bid - ProfitStopLossOffset; OrderModify(OrderTicket(), OrderOpenPrice(), dynamicSL, OrderTakeProfit(), 0, clrYellow); } else if(OrderType() == OP_SELL) { double dynamicSL = Ask * (1.0 + DynamicStopLossPercentage / 100.0); if(profit > 0) dynamicSL = Ask + ProfitStopLossOffset; OrderModify(OrderTicket(), OrderOpenPrice(), dynamicSL, OrderTakeProfit(), 0, clrYellow); } if(profit >= takeProfitTarget) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, clrGreen); } } } } //+------------------------------------------------------------------+ //| Funzione di chiusura per il timer | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); } //+------------------------------------------------------------------+
Leave a Comment