can someone help me remove this errors from this code

taylorj

Trader
Jun 27, 2024
2
0
6
34
//+------------------------------------------------------------------+
//| SymmetricalTriangle.mq5 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property strict

// Input parameters
input int lookback = 20; // Lookback period
input double sensitivity = 1.5; // Sensitivity

// Define structure for storing high and low points
struct Triangle {
double highpoint;
double lowpoint;
int startIndex;
int endIndex;
};

// Define array for storing detected triangles
Triangle triangles[];
int state = 0;
double highpoint, lowpoint;
int startIndex, endIndex;

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Delete any graphical objects
ObjectsDeleteAll(0, 0);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// We only need to process on a new bar
static datetime lastTime = 0;
if (lastTime == Time[0])
return;
lastTime = Time[0];

// Loop through bars and detect symmetrical triangles
for (int i = 1; i < Bars - lookback; i++) {
double highestHigh = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, lookback, i));
double lowestLow = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, lookback, i));

if (state == 0) {
highpoint = highestHigh;
lowpoint = lowestLow;
startIndex = i;
state = 1;
}

if (state == 1) {
highpoint = MathMax(highpoint, High);
lowpoint = MathMin(lowpoint, Low);
if (Close < highpoint - (highpoint - lowpoint) / sensitivity) {
state = 2;
endIndex = i;
Triangle triangle;
triangle.highpoint = highpoint;
triangle.lowpoint = lowpoint;
triangle.startIndex = startIndex;
triangle.endIndex = endIndex;
ArrayResize(triangles, ArraySize(triangles) + 1);
triangles[ArraySize(triangles) - 1] = triangle;

// Draw triangle on the chart
DrawTriangle(startIndex, endIndex, highpoint, lowpoint);
}
}

if (state == 2) {
if (Close > lowpoint + (highpoint - lowpoint) / sensitivity) {
state = 0;
}
}
}
}
//+------------------------------------------------------------------+
//| Function to draw the triangle on the chart |
//+------------------------------------------------------------------+
void DrawTriangle(int start, int end, double high, double low) {
string objName = "Triangle_" + IntegerToString(start);
if (!ObjectCreate(0, objName, OBJ_TRIANGLE, 0, Time[start], high, Time[end], low, Time[end], high)) {
Print("Error creating triangle: ", GetLastError());
return;
}
ObjectSetInteger(0, objName, OBJPROP_COLOR, clrRed);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, 2);
}