I see the issue - the errors are coming from trying to access price arrays (High[], Low[], Close[], Open[]) and the Time[] array directly, which isn't how MQL5 works. In MQL5, we need to use the iHigh(), iLow(), iClose(), iOpen(), and iTime() functions to access these values. Let me provide a corrected version that will compile properly in MetaEditor.
Here's the corrected version of the Expert Advisor:
//+------------------------------------------------------------------+
//| ICT Unicorn Strategy (MT5 Expert Advisor) |
//+------------------------------------------------------------------+
#property strict
#property version "1.00"
#property description "ICT Unicorn Strategy - MT5 Expert Advisor"
// Input Parameters
input int len = 10; // Swings
input bool iBull = true; // Bull
input color colBl = clrGreen; // Bull Color
input bool iBear = true; // Bear
input color colBr = clrRed; // Bear Color
input bool combine = false; // Combine Bull and Bear
// Position Sizing
input double riskAmount = 1000; // Risk Amount USD
input double maxPositionSize = 1000; // Max Position Size
// Targets
input double risk = 1.0; // Risk/Reward
input double reward = 2.0; // Reward
double rr = reward / risk;
input bool trail = false; // Trailing Stop
input int lenS = 5; // Trailing Stop Length
input bool showTargets = true; // Show Target Areas
input color colRisk = clrGray; // Risk Color
input color colReward = clrBlue; // Reward Color
// Global Variables
int swingHighCount = 0, swingLowCount = 0;
double swingHigh[], swingLow[];
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
ArraySetAsSeries(swingHigh, true);
ArraySetAsSeries(swingLow, true);
ArrayResize(swingHigh, len);
ArrayResize(swingLow, len);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, "FVG_");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int n = Bars - 1;
double atr = iATR(_Symbol, _Period, 14, 0);
// Detect Swings
DetectSwings();
// Bull and Bear Logic
if (iBear)
{
for (int i = swingHighCount - 1; i >= 2; i--)
{
double Cy = swingHigh[i];
double Ay = swingHigh[i - 1];
double By = swingHigh[i - 2];
if (iClose(_Symbol, _Period, 1) < By && Cy > Ay)
{
double y = iHigh(_Symbol, _Period, n - i);
double z = iLow(_Symbol, _Period, n - i);
// FVG Detection
for (int j = 0; j < n - i; j++)
{
double fvgT = iLow(_Symbol, _Period, n - j - 2);
double fvgB = iHigh(_Symbol, _Period, n - j);
if (fvgB < fvgT && fvgT - fvgB > atr * 0.05)
{
// Draw FVG Box
string name = "FVG_Bear_" + IntegerToString(n - j);
DrawFVGBox(name, iTime(_Symbol, _Period, n - j - 2), fvgT,
iTime(_Symbol, _Period, n - j), fvgB, colBr);
// Calculate Targets
double entryPrice = iClose(_Symbol, _Period, 0);
double stopLoss = Cy;
double targetPrice = z - (Cy - z) * rr;
double positionSize = CalculatePositionSize(entryPrice, stopLoss);
if (positionSize > 0)
OpenTrade(ORDER_TYPE_SELL, positionSize, entryPrice, stopLoss, targetPrice, "Bear Unicorn");
break;
}
}
}
}
}
if (iBull)
{
for (int i = swingLowCount - 1; i >= 2; i--)
{
double Cy = swingLow[i];
double Ay = swingLow[i - 1];
double By = swingLow[i - 2];
if (iClose(_Symbol, _Period, 1) > By && Cy < Ay)
{
double y = iHigh(_Symbol, _Period, n - i);
double z = iLow(_Symbol, _Period, n - i);
// FVG Detection
for (int j = 0; j < n - i; j++)
{
double fvgB = iHigh(_Symbol, _Period, n - j - 2);
double fvgT = iLow(_Symbol, _Period, n - j);
if (fvgB < fvgT && fvgT - fvgB > atr * 0.05)
{
// Draw FVG Box
string name = "FVG_Bull_" + IntegerToString(n - j);
DrawFVGBox(name, iTime(_Symbol, _Period, n - j - 2), fvgT,
iTime(_Symbol, _Period, n - j), fvgB, colBl);
// Calculate Targets
double entryPrice = iClose(_Symbol, _Period, 0);
double stopLoss = Cy;
double targetPrice = y + (y - Cy) * rr;
double positionSize = CalculatePositionSize(entryPrice, stopLoss);
if (positionSize > 0)
OpenTrade(ORDER_TYPE_BUY, positionSize, entryPrice, stopLoss, targetPrice, "Bull Unicorn");
break;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Detect Swings (Simplified ZigZag) |
//+------------------------------------------------------------------+
void DetectSwings()
{
swingHighCount = 0;
swingLowCount = 0;
for (int i = len; i < Bars; i++)
{
bool isHigh = true, isLow = true;
for (int j = 1; j <= len; j++)
{
if (iHigh(_Symbol, _Period, i) < iHigh(_Symbol, _Period, i - j)) isHigh = false;
if (iHigh(_Symbol, _Period, i) < iHigh(_Symbol, _Period, i + j)) isHigh = false;
if (iLow(_Symbol, _Period, i) > iLow(_Symbol, _Period, i - j)) isLow = false;
if (iLow(_Symbol, _Period, i) > iLow(_Symbol, _Period, i + j)) isLow = false;
}
if (isHigh)
{
swingHigh[swingHighCount] = iHigh(_Symbol, _Period, i);
swingHighCount++;
}
if (isLow)
{
swingLow[swingLowCount] = iLow(_Symbol, _Period, i);
swingLowCount++;
}
}
}
//+------------------------------------------------------------------+
//| Draw FVG Box |
//+------------------------------------------------------------------+
void DrawFVGBox(string name, datetime t1, double p1, datetime t2, double p2, color clr)
{
ObjectCreate(0, name, OBJ_RECTANGLE, 0, t1, p1, t2, p2);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_BACK, true);
ObjectSetInteger(0, name, OBJPROP_FILL, true);
ObjectSetInteger(0, name, OBJPROP_FILLCOLOR, clr);
ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, name, OBJPROP_TRANSPARENCY, 75);
}
//+------------------------------------------------------------------+
//| Calculate Position Size |
//+------------------------------------------------------------------+
double CalculatePositionSize(double entryPrice, double stopLoss)
{
double slDistance = MathAbs(entryPrice - stopLoss);
double posSize = slDistance > 0 ? riskAmount / slDistance : 0;
return MathMin(posSize, maxPositionSize);
}
//+------------------------------------------------------------------+
//| Open Trade |
//+------------------------------------------------------------------+
void OpenTrade(ENUM_ORDER_TYPE type, double volume, double entryPrice, double stopLoss, double takeProfit, string comment)
{
MqlTradeRequest request = {0};
MqlTradeResult result = {0};
request.action = TRADE_ACTION_DEAL;
request.symbol = _Symbol;
request.volume = NormalizeDouble(volume, 2);
request.type = type;
request.price = (type == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
request.sl = stopLoss;
request.tp = takeProfit;
request.deviation = 5;
request.magic = 0;
request.comment = comment;
OrderSend(request, result);
if (result.retcode != TRADE_RETCODE_DONE)
{
Print("Trade failed. Error: ", result.retcode);
}
}