Horizontal Vertical Close lines HV Close lines (support&resistance)

1
I need help for the indicator below to do as follows: 1draws yellow horizontal lines on the right from each close of the candlestick for a specific given period, 2. draws white lines from the last closed candlestick to each closed candlestick separately for a given period. When a new candlestick opens, deletes all objects and recalculates the period.

//+------------------------------------------------------------------+
//| HV Close lines.mq4 |
//| AIHalabak |
//| https://www.mql5.com |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 0

// Input parameters
int period = 288; // Period to look back
color yellowLineColor = clrYellow;
color whiteLineColor = clrWhite;

int OnInit()
{
ObjectsDeleteAll(0); // Delete all objects on initialization
return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
ObjectsDeleteAll(0);
}

void OnTick()
{
// Check if a new candlestick has opened
if (iBars > 1 && Time[1] != Time[0])
{
ObjectsDeleteAll(0); // Delete all objects before drawing new ones
DrawHorizontalLines(period, yellowLineColor);
DrawLinesToPreviousCloses(period, whiteLineColor, yellowLineColor);
}
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
if (id == CHARTEVENT_OBJECT_DELETE)
{
ObjectsDeleteAll(0); // Delete all objects if any are manually deleted
DrawHorizontalLines(period, yellowLineColor);
DrawLinesToPreviousCloses(period, whiteLineColor, yellowLineColor);
}
}

// Draws yellow horizontal lines from each close
void DrawHorizontalLines(int count, color yellow)
{
for (int i = 1; i <= count; i++) // Added closing parenthesis to the loop
{
double price = Close;
string objectName = "HL" + IntegerToString(i);
ObjectCreate(0, objectName, OBJ_HLINE, 0, 0, price); // Removed the unnecessary zero
ObjectSetInteger(0, objectName, OBJPROP_COLOR, yellow);
}
}

// Draws white lines from the last close to each previous close
void DrawLinesToPreviousCloses(int count, color white, color yellow)
{
Image

double lastPrice = Close[0];
for (int i = 1; i <= count; i++) // Added closing parenthesis to the loop
{
double price = Close;
string objectName = "Line" + IntegerToString(i);
ObjectCreate(0, objectName, OBJ_TREND, 0, 0, lastPrice, 0, price); // Removed the unnecessary zero
ObjectSetInteger(0, objectName, OBJPROP_COLOR, white);
}
}
Attachments


Who is online

Users browsing this forum: No registered users and 2 guests