Thanks for your patience! To clarify and make sure I deliver exactly what you want, let's restate your request precisely:
What I understand:
-
You want an EA that automatically detects two specific price levels on EUR/USD M5 chart:
- The highest high at the exact 06:25 bar
- The lowest low at the exact 01:40 bar
-
At those points in time and price, the EA should start drawing a trendline (or horizontal line) from each of those bars forward in time (i.e., extending right, following the chart forward until current time).
-
This detection and line drawing should happen continuously each trading day (or whenever the bars exist), on the current day timeframe, so the lines extend from those historical points to “now.”
Important:
- You want the detection to be automatic (EA identifies the exact bar at 06:25 and 01:40 for that day).
- The lines drawn should start exactly at those bars, at the given high or low price, and extend forward (to the right) as time passes.
- You want this for M5 charts.
- Possibly, you want the lines updated each day or at least once per day.
Please confirm or correct:
- Are the times (06:25 and 01:40) fixed and daily for every trading day? (i.e., every day detect the bars of those exact times)
- Do you want trendlines connecting those points in time to the current last bar's time (that is, lines angled in time and price)?
- Or do you want horizontal lines (price stays fixed) starting at those bars extending right?
- Which platform: MT4 or MT5?
- Should the lines be persistent over multiple days or just one day at a time?
- Any trading action or alert or just line drawing?
Meanwhile, here is a more complete example EA code for MT4 that:
- auto finds the M5 bars at 06:25 and 01:40 each day
- takes the high and low values respectively
- draws trendlines starting from those bars forward to the current last bar, so that the time axis is respected
- uniquely names lines with date for each day
- updates once per day to avoid multiple redundant redraws
//+------------------------------------------------------------------+
//| LinesAtTime |
//| Draw trendlines from fixed-time bars (06:25 high, 01:40 low) |
//| on EURUSD M5 chart, updating once per new day |
//+------------------------------------------------------------------+
#property strict
input int HighHour = 6;
input int HighMinute = 25;
input int LowHour = 1;
input int LowMinute = 40;
string HighLineName = "";
string LowLineName = "";
datetime LastDrawDay = 0;
datetime GetBarOpenTimeAt(int hour, int minute)
{
datetime day = iTime(_Symbol, PERIOD_D1, 0); // today 00:00 server time
int modMinute = minute % 5; // adjust to M5 bar start
datetime barTime = day + hour*3600 + (minute - modMinute)*60;
return barTime;
}
int GetBarIndexAt(datetime barTime)
{
return iBarShift(_Symbol, PERIOD_M5, barTime, true);
}
void RemoveOldLines()
{
if(HighLineName != "")
ObjectDelete(HighLineName);
if(LowLineName != "")
ObjectDelete(LowLineName);
}
void DrawLines()
{
datetime today = iTime(_Symbol, PERIOD_D1, 0);
// Prevent redrawing multiple times per day
if(today == LastDrawDay)
return; // already drawn today
LastDrawDay = today;
RemoveOldLines();
datetime highBarTime = GetBarOpenTimeAt(HighHour, HighMinute);
datetime lowBarTime = GetBarOpenTimeAt(LowHour, LowMinute);
int highIndex = GetBarIndexAt(highBarTime);
int lowIndex = GetBarIndexAt(lowBarTime);
if(highIndex < 0 || lowIndex < 0) // bars not available yet
return;
double highPrice = iHigh(_Symbol, PERIOD_M5, highIndex);
double lowPrice = iLow(_Symbol, PERIOD_M5, lowIndex);
int lastIndex = 0; // last (most recent) candle index on M5, 0 is current candle
datetime lastTime = iTime(_Symbol, PERIOD_M5, lastIndex);
// Create unique line names with date
string dateStr = TimeToString(today, TIME_DATE);
HighLineName = "HighLine_"+dateStr;
LowLineName = "LowLine_"+dateStr;
// Draw trendline from high bar to last bar at same high price (if you want horizontal),
// or you can make it angled by using price at last bar as well.
// Here horizontal lines are simpler, but will use trendline to demonstrate:
// For high line - draw horizontal (same price)
ObjectCreate(HighLineName, OBJ_TREND, 0, highBarTime, highPrice, lastTime, highPrice);
ObjectSetInteger(0, HighLineName, OBJPROP_COLOR, clrRed);
ObjectSetInteger(0, HighLineName, OBJPROP_BACK, true);
// For low line - draw horizontal
ObjectCreate(LowLineName, OBJ_TREND, 0, lowBarTime, lowPrice, lastTime, lowPrice);
ObjectSetInteger(0, LowLineName, OBJPROP_COLOR, clrBlue);
ObjectSetInteger(0, LowLineName, OBJPROP_BACK, true);
}
int OnInit()
{
DrawLines();
return(INIT_SUCCEEDED);
}
void OnTick()
{
DrawLines(); // call on each tick but will update only once per day
}
How this works:
- On every new tick,
DrawLines() runs.
- It checks if lines for today were already drawn. If yes, does nothing.
- If not, it locates the M5 bars at 06:25 and 01:40 times,
- Extracts high and low prices for those bars,
- Draw trendlines from those bar times and prices horizontally to latest bar time,
- Names the lines uniquely for each date to avoid multiple copies.
This will create two horizontal lines from those specified bars forward in time to the present bar, exactly as you described.
Notes:
- Adjust input times if your broker's server time is different from UTC/local time you want.
- For non-horizontal lines: you could use prices of latest bar to get sloped lines (but your example wants fixed price lines).
- If you want lines drawn historically for many days, the logic needs expansion (loop over recent days).
- Supports only one day’s drawing at a time, can be changed.
If this still misses your core needs, please describe specifically:
- When/how often should the EA look for those bars?
- What exactly should be drawn — horizontal lines or angled trendlines?
- On which platform (MT4/MT5)?
- Are the times fixed per day or variable?
- Should lines persist forever, or only today?
I’ll write exactly that for you.