The issue is with unbalanced braces and incomplete code. Let me help you fix the specific error. In the code you provided, there's an unbalanced brace at line 222. The solution is to properly close all code blocks.
For the complete working code, I recommend using my previous response but making sure to add these closing braces at the end of the file:
mql5 Copy code
// ... (previous code remains the same)
ObjectCreate(0, hiName, OBJ_TREND, 0, obTime, highVal,
iTime(_Symbol, 0, idx - LineLength), highVal);
ObjectSetInteger(0, hiName, OBJPROP_COLOR, BullLineColor);
ObjectSetInteger(0, hiName, OBJPROP_STYLE, lineStyle);
ObjectSetInteger(0, hiName, OBJPROP_WIDTH, LinesWidth);
// --- create TRADE SETUP ----------------------------------
if(TradeDirection == "Long Only" || TradeDirection == "Both")
{
double entry = highVal, sl = lowVal, qty, tp;
CalculateTrade(entry, sl, qty, tp);
if(qty > 0)
{
int s = ArraySize(pendingLongs);
ArrayResize(pendingLongs, s + 1);
pendingLongs[s].entry = entry;
pendingLongs[s].sl = sl;
pendingLongs[s].tp = tp;
pendingLongs[s].qty = qty;
pendingLongs[s].direction = 1;
pendingLongs[s].obTime = obTime;
pendingLongs[s].active = true;
}
}
}
// remove fractal
ArrayRemove(fractalHighs, i, 1);
ArrayRemove(fractalHighTimes, i, 1);
}
}
//+------------------------------------------------------------------+
//| Check for trade entries |
//+------------------------------------------------------------------+
void CheckPendingTrades()
{
// Process pending longs
for(int i = ArraySize(pendingLongs) - 1; i >= 0; i--)
{
if(!pendingLongs[i].active)
{
ArrayRemove(pendingLongs, i, 1);
continue;
}
// Cancel if TP hit before entry
if(iHigh(_Symbol, 0, 0) >= pendingLongs[i].tp)
{
pendingLongs[i].active = false;
ArrayRemove(pendingLongs, i, 1);
continue;
}
// Check for entry
if(iLow(_Symbol, 0, 0) <= pendingLongs[i].entry)
{
string cmt = "OB_Long_" + IntegerToString((int)pendingLongs[i].obTime);
trade.BuyLimit(pendingLongs[i].qty, pendingLongs[i].entry, _Symbol,
pendingLongs[i].sl, pendingLongs[i].tp, 0, 0, cmt);
pendingLongs[i].active = false;
ArrayRemove(pendingLongs, i, 1);
}
}
// Process pending shorts
for(int i = ArraySize(pendingShorts) - 1; i >= 0; i--)
{
if(!pendingShorts[i].active)
{
ArrayRemove(pendingShorts, i, 1);
continue;
}
// Cancel if TP hit before entry
if(iLow(_Symbol, 0, 0) <= pendingShorts[i].tp)
{
pendingShorts[i].active = false;
ArrayRemove(pendingShorts, i, 1);
continue;
}
// Check for entry
if(iHigh(_Symbol, 0, 0) >= pendingShorts[i].entry)
{
string cmt = "OB_Short_" + IntegerToString((int)pendingShorts[i].obTime);
trade.SellLimit(pendingShorts[i].qty, pendingShorts[i].entry, _Symbol,
pendingShorts[i].sl, pendingShorts[i].tp, 0, 0, cmt);
pendingShorts[i].active = false;
ArrayRemove(pendingShorts, i, 1);
}
}
}
//+------------------------------------------------------------------+
//| Calculate position size and take profit |
//+------------------------------------------------------------------+
void CalculateTrade(double entryPrice, double stopLossPrice,
double &qty, double &takeProfit)
{
qty = 0;
takeProfit = 0;
double riskPerPoint = MathAbs(entryPrice - stopLossPrice);
if(riskPerPoint <= 0) return;
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double pointValue = tickValue / tickSize;
double rawLots = RiskPerTrade / (riskPerPoint * pointValue);
double step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double maxLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
qty = MathFloor(rawLots / step) * step;
if(qty < minLot) qty = minLot;
if(qty > maxLot) qty = maxLot;
int dir = (entryPrice > stopLossPrice) ? 1 : -1;
takeProfit = entryPrice + dir * riskPerPoint * RiskRewardRatio;
}
//+------------------------------------------------------------------+
//| Manage open trades (placeholder for future implementation) |
//+------------------------------------------------------------------+
void ManageOpenTrades()
{
// Add your trade management logic here
}
//+------------------------------------------------------------------+
This should now compile without any errors. The key fixes were: