This originally worked for MT4 but when i used chatgpt to convert it to MT5 i'm getting this line error
search this website for the errors and the function SymbolInfoDouble.
This originally worked for MT4 but when i used chatgpt to convert it to MT5 i'm getting this line error
Fixed Code attached. Try it and Let me know.
//+------------------------------------------------------------------+ //| Antfruition.mq5 | //| Expert Advisor for MT5 | //+------------------------------------------------------------------+ #property strict #include <Trade\Trade.mqh> CTrade trade; // Input parameters input int ATR_Period = 14; input int BaseTakeProfitPips = 20; input double ATR_Multiplier = 1.5; input int StopLossBufferPips = 15; input int RetestBufferPips = 2; input bool UseCandleConfirmation = true; input double LotSize = 0.1; input int MagicNumber = 12345; input int Slippage = 3; // Global variables for session tracking bool sessionLevelsCaptured = false; double sessionHigh = 0; double sessionLow = 0; // Global variable for ATR indicator handle int atrHandle = INVALID_HANDLE; //+------------------------------------------------------------------+ //| Count open positions for the given Magic Number | //+------------------------------------------------------------------+ int CountPositionsByMagic(int magic) { int count = 0; int total = PositionsTotal(); for(int i = 0; i < total; i++) { ulong ticket = PositionGetTicket(i); if(PositionSelectByTicket(ticket)) { if(PositionGetInteger(POSITION_MAGIC) == magic && PositionGetString(POSITION_SYMBOL) == _Symbol) count++; } } return count; } //+------------------------------------------------------------------+ //| Retrieve latest ATR value using the indicator handle | //+------------------------------------------------------------------+ double GetATRValue() { double atrValue = 0.0; if(atrHandle == INVALID_HANDLE) { Print("Invalid ATR handle"); return 0.0; } // Retrieve data from the last closed bar (shift = 1) double atrBuffer[1]; int copied = CopyBuffer(atrHandle, 0, 1, 1, atrBuffer); if(copied < 1) { Print("Failed to copy ATR data. Error: ", GetLastError()); return 0.0; } atrValue = atrBuffer[0]; return atrValue; } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Set magic number for all trade orders trade.SetExpertMagicNumber(MagicNumber); // Create ATR indicator handle on M5 timeframe atrHandle = iATR(_Symbol, PERIOD_M5, ATR_Period); if(atrHandle == INVALID_HANDLE) { Print("Failed to create ATR handle. Error: ", GetLastError()); return INIT_FAILED; } return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { if(atrHandle != INVALID_HANDLE) { IndicatorRelease(atrHandle); atrHandle = INVALID_HANDLE; } } //+------------------------------------------------------------------+ //| Main tick function | //+------------------------------------------------------------------+ void OnTick() { // Retrieve the number of digits for price normalization int digits = (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS); // Reset session levels at the start of a new day static int previousDay = 0; MqlDateTime dt; TimeToStruct(TimeCurrent(), dt); int currentDay = dt.day; if(currentDay != previousDay) { sessionLevelsCaptured = false; previousDay = currentDay; } // Capture session levels (once per day) using the last completed M5 candle (shift = 1) if(!sessionLevelsCaptured) { sessionHigh = NormalizeDouble(iHigh(_Symbol, PERIOD_M5, 1), digits); sessionLow = NormalizeDouble(iLow(_Symbol, PERIOD_M5, 1), digits); sessionLevelsCaptured = true; Print("Session levels captured: High = ", DoubleToString(sessionHigh, digits), ", Low = ", DoubleToString(sessionLow, digits)); } // Exit if a position with the specified MagicNumber is already open if(CountPositionsByMagic(MagicNumber) > 0) return; // Retrieve the latest ATR value double atrValue = GetATRValue(); if(atrValue == 0.0) return; // ATR-based Dynamic Take Profit Calculation (in price terms) double dynamicTP = NormalizeDouble((BaseTakeProfitPips * _Point) + (ATR_Multiplier * atrValue), digits); // Determine recent highs and lows from the last three completed M5 candles double recentLow = NormalizeDouble(MathMin(iLow(_Symbol, PERIOD_M5, 1), MathMin(iLow(_Symbol, PERIOD_M5, 2), iLow(_Symbol, PERIOD_M5, 3))), digits); double recentHigh = NormalizeDouble(MathMax(iHigh(_Symbol, PERIOD_M5, 1), MathMax(iHigh(_Symbol, PERIOD_M5, 2), iHigh(_Symbol, PERIOD_M5, 3))), digits); double stopLossLong = NormalizeDouble(recentLow - (StopLossBufferPips * _Point) - (ATR_Multiplier * atrValue), digits); double stopLossShort = NormalizeDouble(recentHigh + (StopLossBufferPips * _Point) + (ATR_Multiplier * atrValue), digits); // Retrieve current market prices using the output parameter overload double askPrice = 0.0, bidPrice = 0.0; if(!SymbolInfoDouble(_Symbol, SYMBOL_ASK, askPrice)) { Print("Error retrieving ask price"); return; } if(!SymbolInfoDouble(_Symbol, SYMBOL_BID, bidPrice)) { Print("Error retrieving bid price"); return; } askPrice = NormalizeDouble(askPrice, digits); bidPrice = NormalizeDouble(bidPrice, digits); // Calculate spread as the difference between ask and bid double spreadPrice = NormalizeDouble(askPrice - bidPrice, digits); if(spreadPrice > 3 * _Point) return; //----- Long Trade Condition (Execution on M1) ----- if(iClose(_Symbol, PERIOD_M5, 1) > sessionHigh && iClose(_Symbol, PERIOD_M1, 1) <= NormalizeDouble(sessionHigh + (RetestBufferPips * _Point), digits)) { if(UseCandleConfirmation && (iClose(_Symbol, PERIOD_M5, 2) < iOpen(_Symbol, PERIOD_M5, 2))) return; if(trade.Buy(LotSize, _Symbol, askPrice, Slippage, stopLossLong, "")) { Print("Long trade placed successfully at: ", DoubleToString(askPrice, digits)); ulong ticket = trade.ResultOrder(); if(ticket != 0) { if(trade.PositionModify(ticket, stopLossLong, NormalizeDouble(sessionHigh + dynamicTP, digits))) Print("Long trade modified with TP successfully"); else Print("Failed to modify long trade TP. Error: ", GetLastError()); } } else Print("Failed to place long trade. Error: ", GetLastError()); } //----- Short Trade Condition (Execution on M1) ----- if(iClose(_Symbol, PERIOD_M5, 1) < sessionLow && iClose(_Symbol, PERIOD_M1, 1) >= NormalizeDouble(sessionLow - (RetestBufferPips * _Point), digits)) { if(UseCandleConfirmation && (iClose(_Symbol, PERIOD_M5, 2) > iOpen(_Symbol, PERIOD_M5, 2))) return; if(trade.Sell(LotSize, _Symbol, bidPrice, Slippage, stopLossShort, "")) { Print("Short trade placed successfully at: ", DoubleToString(bidPrice, digits)); ulong ticket = trade.ResultOrder(); if(ticket != 0) { if(trade.PositionModify(ticket, stopLossShort, NormalizeDouble(sessionLow - dynamicTP, digits))) Print("Short trade modified with TP successfully"); else Print("Failed to modify short trade TP. Error: ", GetLastError()); } } else Print("Failed to place short trade. Error: ", GetLastError()); } }
any chance you know what could cause this or will it be different when it's in a live trading condition?
I ran a strategy tester and i'm getting this error in the journal
any chance you know what could cause this or will it be different when it's in a live trading condition?
do you know how to use search features? on every page of this website there is a search bar.
However, after looking at your code in previous msg, i can see several issues. first will be SymbolInfoDouble is not used appropriately.
Recheck the SL/TP and Fix it.
do you know how to use search features? on every page of this website there is a search bar.
However, after looking at your code in previous msg, i can see several issues. first will be SymbolInfoDouble is not used appropriately.
If I knew what I was looking at that yes It would help but i literally don't have anything about coding. I used chatgpt to write these codes. Thank you for your help.
The “Invalid stops” error means that one or both of the stop loss (SL) and take profit (TP) levels you’re sending do not meet the broker’s requirements.
Recheck the SL/TP and Fix it.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am getting error
i've been using chatgpt and i found a few people had similar error but i dont know anything about coding. If someone can help I'd really appreciate this