Why is my trading bot not working on backtesting on ICmmarkets?

Why is my trading bot not working on backtesting on ICmmarkets?

Manage alerts

Loading saved threads...

James Tolentino · External communityPost link
External question — Stack Overflow Stack Exchange Author: James Tolentino Original post: https://stackoverflow.com/questions/79855789 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I’m building an EA in MQL4 that uses regression equations between GBP/USD and EUR/USD to forecast direction. The regression analysis logic is: GBP/USD forecast = 0.4754 + 0.7466 * EUR/USD EUR/USD forecast = -0.4424 + 1.1914 * GBP/USD The EA compares the forecasted price to the last daily close. If the forecast is higher, it buys; if lower, it sells. Stop loss is set at ATR × 1.5 , and take profit is 2 × SL (risk‑reward 1:2). I’ve added rules for: Max 3 trades per day 1% risk per trade (lot size calculated dynamically) EdgeThreshold filter (forecast must differ from current price by at least 0.0003) The problem: In backtests, optimization shows “results discarded as insignificant.” Sometimes no trades are placed at all, even when conditions look valid. I suspect the edge filter or daily bar detection is blocking trades. What I need help with: Debugging why trades aren’t triggering. Confirming if my lot size calculation for 1% risk is correct. Advice on whether the edge filter should be dynamic (e.g., based on ATR). Any guidance or code corrections would be greatly appreciated. Thanks! //+------------------------------------------------------------------+ //| RegressionForecastEA.mq4 | //| Max 3 trades/day, 1% risk per trade, RR=1:2 | //+------------------------------------------------------------------+ #property strict extern int Slippage = 3; extern int MagicNumber = 220126; extern int ATR_Period = 14; extern double ATR_Multiplier = 1.5; extern double EdgeThreshold = 0.0003; // forecast edge extern bool Trade_EURUSD = true; extern bool Trade_GBPUSD = true; // Regression equations double ForecastGBP(double eur) { return 0.4754 + 0.7466 * eur; } double ForecastEUR(double gbp) { return -0.4424 + 1.1914 * gbp; } // Track trades per day static datetime lastBarTime = 0; static int tradesToday = 0; // Helpers double GetATR(string sym, int tf, int period) { return iATR(sym, tf, period, 1); } double PipValue(string sym) { return MarketInfo(sym, MODE_TICKVALUE); } int DigitsFor(string sym) { return MarketInfo(sym, MODE_DIGITS); } double PointFor(string sym) { return MarketInfo(sym, MODE_POINT); } void Log(string msg) { Print("[RegressionEA] ", msg); } // Position sizing: 1% risk double CalcLots(string sym, double sl_distance) { double riskAmount = AccountBalance() * 0.01; double pipVal = PipValue(sym); double lotSize = riskAmount / (sl_distance / PointFor(sym) * pipVal); return NormalizeDouble(lotSize, 2); } // Core logic void EvaluateSymbol(string sym) { if(tradesToday >= 3) return; // max trades per day double curr_close = iClose(sym, PERIOD_D1, 1); string other = (sym=="GBPUSD") ? "EURUSD" : "GBPUSD"; double other_close = iClose(other, PERIOD_D1, 1); double forecast = (sym=="GBPUSD") ? ForecastGBP(other_close) : ForecastEUR(other_close); double edge = MathAbs(forecast - curr_close); if(edge < EdgeThreshold) return; double atr = GetATR(sym, PERIOD_D1, ATR_Period); double sl_dist = atr * ATR_Multiplier; double tp_dist = sl_dist * 2.0; int digits = DigitsFor(sym); double price, sl, tp; int type; RefreshRates(); if(forecast > curr_close) { type = OP_BUY; price = NormalizeDouble(Ask, digits); sl = NormalizeDouble(price - sl_dist, digits); tp = NormalizeDouble(price + tp_dist, digits); } else { type = OP_SELL; price = NormalizeDouble(Bid, digits); sl = NormalizeDouble(price + sl_dist, digits); tp = NormalizeDouble(price - tp_dist, digits); } double lots = CalcLots(sym, sl_dist); int ticket = OrderSend(sym, type, lots, price, Slippage, sl, tp, "Regression "+sym, MagicNumber, 0, (type==OP_BUY?clrGreen:clrRed)); if(ticket > 0) { tradesToday++; Log(StringFormat("Trade placed %s ticket=%d lots=%.2f SL=%.5f TP=%.5f", sym, ticket, lots, sl, tp)); } } // EA events int start() { datetime barTime = iTime("EURUSD", PERIOD_D1, 0); if(barTime != lastBarTime) { tradesToday = 0; lastBarTime = barTime; } if(Trade_EURUSD) EvaluateSymbol("EURUSD"); if(Trade_GBPUSD) EvaluateSymbol("GBPUSD"); return(0);
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: James Tolentino Source score (net votes, not local likes): 1 Original post: https://stackoverflow.com/questions/79855789 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I’m building an EA in MQL4 that uses regression equations between GBP/USD and EUR/USD to forecast direction. The regression analysis logic is: GBP/USD forecast = 0.4754 + 0.7466 * EUR/USD EUR/USD forecast = -0.4424 + 1.1914 * GBP/USD The EA compares the forecasted price to the last daily close. If the forecast is higher, it buys; if lower, it sells. Stop loss is set at ATR × 1.5 , and take profit is 2 × SL (risk‑reward 1:2). I’ve added rules for: Max 3 trades per day 1% risk per trade (lot size calculated dynamically) EdgeThreshold filter (forecast must differ from current price by at least 0.0003) The problem: In backtests, optimization shows “results discarded as insignificant.” Sometimes no trades are placed at all, even when conditions look valid. I suspect the edge filter or daily bar detection is blocking trades. What I need help with: Debugging why trades aren’t triggering. Confirming if my lot size calculation for 1% risk is correct. Advice on whether the edge filter should be dynamic (e.g., based on ATR). Any guidance or code corrections would be greatly appreciated. Thanks! //+------------------------------------------------------------------+ //| RegressionForecastEA.mq4 | //| Max 3 trades/day, 1% risk per trade, RR=1:2 | //+------------------------------------------------------------------+ #property strict extern int Slippage = 3; extern int MagicNumber = 220126; extern int ATR_Period = 14; extern double ATR_Multiplier = 1.5; extern double EdgeThreshold = 0.0003; // forecast edge extern bool Trade_EURUSD = true; extern bool Trade_GBPUSD = true; // Regression equations double ForecastGBP(double eur) { return 0.4754 + 0.7466 * eur; } double ForecastEUR(double gbp) { return -0.4424 + 1.1914 * gbp; } // Track trades per day static datetime lastBarTime = 0; static int tradesToday = 0; // Helpers double GetATR(string sym, int tf, int period) { return iATR(sym, tf, period, 1); } double PipValue(string sym) { return MarketInfo(sym, MODE_TICKVALUE); } int DigitsFor(string sym) { return MarketInfo(sym, MODE_DIGITS); } double PointFor(string sym) { return MarketInfo(sym, MODE_POINT); } void Log(string msg) { Print("[RegressionEA] ", msg); } // Position sizing: 1% risk double CalcLots(string sym, double sl_distance) { double riskAmount = AccountBalance() * 0.01; double pipVal = PipValue(sym); double lotSize = riskAmount / (sl_distance / PointFor(sym) * pipVal); return NormalizeDouble(lotSize, 2); } // Core logic void EvaluateSymbol(string sym) { if(tradesToday >= 3) return; // max trades per day double curr_close = iClose(sym, PERIOD_D1, 1); string other = (sym=="GBPUSD") ? "EURUSD" : "GBPUSD"; double other_close = iClose(other, PERIOD_D1, 1); double forecast = (sym=="GBPUSD") ? ForecastGBP(other_close) : ForecastEUR(other_close); double edge = MathAbs(forecast - curr_close); if(edge < EdgeThreshold) return; double atr = GetATR(sym, PERIOD_D1, ATR_Period); double sl_dist = atr * ATR_Multiplier; double tp_dist = sl_dist * 2.0; int digits = DigitsFor(sym); double price, sl, tp; int type; RefreshRates(); if(forecast > curr_close) { type = OP_BUY; price = NormalizeDouble(Ask, digits); sl = NormalizeDouble(price - sl_dist, digits); tp = NormalizeDouble(price + tp_dist, digits); } else { type = OP_SELL; price = NormalizeDouble(Bid, digits); sl = NormalizeDouble(price + sl_dist, digits); tp = NormalizeDouble(price - tp_dist, digits); } double lots = CalcLots(sym, sl_dist); int ticket = OrderSend(sym, type, lots, price, Slippage, sl, tp, "Regression "+sym, MagicNumber, 0, (type==OP_BUY?clrGreen:clrRed)); if(ticket > 0) { tradesToday++; Log(StringFormat("Trade placed %s ticket=%d lots=%.2f SL=%.5f TP=%.5f", sym, ticket, lots, sl, tp)); } } // EA events int start() { datetime barTime = iTime("EURUSD", PERIOD_D1, 0); if(barTime != lastBarTime) { tradesToday = 0; lastBarTime = barTime; } if(Trade_EURUSD) EvaluateSymbol("EURUSD"); if(Trade_GBPUSD) EvaluateSymbol("GBPUSD"); return(0);

Cancel quote

Checking account access…