devi aiutarmi a migliorare un ea per mt4. voglio aggiungere un filtro ATR alle regole…
- User
devi aiutarmi a migliorare un ea per mt4. voglio aggiungere un filtro ATR alle regole per aprire i trade. se l'atr ha un'impennata improvvisa (non so come codificarlo), non deve aprire trade. ecco il mio codice #property strict
// Input parameters input int bbPeriod = 30; // Bollinger Bands period input double bbDeviation = 2.0; // Bollinger Bands deviation input int rsiPeriod = 5; // RSI period input double rsiOverbought = 80; // RSI overbought level input double rsiOversold = 20; // RSI oversold level input bool aggressiveMode = true; // Aggressive mode boolean input double LotSize = 0.1; // Lot size for each trade input int Slippage = 3; // Maximum slippage input bool useStopLoss = true; // Use stop loss input double StopLossPips = 150; // Stop loss in pips input bool useTakeProfit = true; // Use take profit input double TakeProfitPips = 200; // Take profit in pips input bool useTrailingStop = true; // Use trailing stop input double TrailingStop = 10; // Trailing stop distance in pips input double TrailingStep = 5; // Trailing step distance in pips
// Expert initialization function int OnInit() { // Initialization code here return(INIT_SUCCEEDED); }
// Expert tick function void OnTick() { static datetime last_bar_time = 0;
// Checking new bar if (Time[0] != last_bar_time) { last_bar_time = Time[0]; double upper_band = iBands(NULL, 0, bbPeriod, bbDeviation, 0, PRICE_CLOSE, MODE_UPPER, 0); double lower_band = iBands(NULL, 0, bbPeriod, bbDeviation, 0, PRICE_CLOSE, MODE_LOWER, 0); double middle_band = iBands(NULL, 0, bbPeriod, bbDeviation, 0, PRICE_CLOSE, MODE_MAIN, 0); double rsi_current = iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, 0); // Check for Buy Condition if ((Close[1] < lower_band) || (aggressiveMode && Close[1] > middle_band && Close[2] <= middle_band)) { OpenBuyTrade(); } // Check for Sell Condition if ((Close[1] > upper_band) || (aggressiveMode && Close[1] < middle_band && Close[2] >= middle_band)) { OpenSellTrade(); } // Check for Close Buy Conditions if (rsi_current > rsiOverbought) { CloseBuyTrades(); } // Check for Close Sell Conditions if (rsi_current < rsiOversold) { CloseSellTrades(); } }}
void OpenBuyTrade() { double stop_loss = useStopLoss ? NormalizedStopLoss(StopLossPips, OP_BUY) : 0; double take_profit= useTakeProfit? NormalizedTakeProfit(TakeProfitPips, OP_BUY) : 0; if (!OrderSend(Symbol(), OP_BUY, LotSize, Ask, Slippage, stop_loss, take_profit, "Buy Order", 0, 0, Blue)) { Print("Buy Order Send Error: ", GetLastError()); } }
void OpenSellTrade() { double stop_loss = useStopLoss ? NormalizedStopLoss(StopLossPips, OP_SELL) : 0; double take_profit= useTakeProfit? NormalizedTakeProfit(TakeProfitPips, OP_SELL) : 0; if (!OrderSend(Symbol(), OP_SELL, LotSize, Bid, Slippage, stop_loss, take_profit, "Sell Order", 0, 0, Red)) { Print("Sell Order Send Error: ", GetLastError()); } }
- Assistant
Per aggiungere un filtro ATR (Average True Range) e impedire l'apertura di nuovi trade in caso di un'impennata improvvisa dell'ATR, dovrai:
- User
hai alternative? devo evitare che il mio ea apra delle posizioni in cambi repentini di trend, ossia, quando le bande di bollinger si espandono molto. essendo che il mio ea funziona sul reverse, quando ci sono queste condizioni il reverse si può verificare molte barre dopo le aperture risultando in perdite
- Assistant
- User
altre idee?
- Assistant
- User
l'ideale è aprire dei trades quando il merceto è sideway. come posso capire questo?
- Assistant