//+------------------------------------------------------------------+ //| Previous Week High & Low.mq5 | //| © 2025 SYLVESTER AKLAMAVO | //| syssyforex@gmail.com | //+------------------------------------------------------------------+ #property copyright "SYLVESTER AKLAMAVO" #property link "syssyforex@gmail.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 0 #property indicator_plots 0 #property strict // === Editable Inputs === input color HighLineColor = clrRed; input color LowLineColor = clrLime; input int LineWidth = 2; input ENUM_LINE_STYLE LineStyle = STYLE_DASHDOTDOT; // === Object Names === #define HIGH_LINE_NAME "PrevWeekHighLine" #define LOW_LINE_NAME "PrevWeekLowLine" //+------------------------------------------------------------------+ //| Initialization | //+------------------------------------------------------------------+ int OnInit() { EventSetTimer(60); // Check every 60 seconds DrawPrevWeekLines(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Deinitialization | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); ObjectDelete(0, HIGH_LINE_NAME); ObjectDelete(0, LOW_LINE_NAME); } //+------------------------------------------------------------------+ //| Timer Event | //+------------------------------------------------------------------+ void OnTimer() { DrawPrevWeekLines(); } //+------------------------------------------------------------------+ //| Main drawing logic | //+------------------------------------------------------------------+ void DrawPrevWeekLines() { double highs[1], lows[1]; datetime prevWeekTime[1], currWeekTime[1]; if (CopyHigh(_Symbol, PERIOD_W1, 1, 1, highs) <= 0 || CopyLow(_Symbol, PERIOD_W1, 1, 1, lows) <= 0 || CopyTime(_Symbol, PERIOD_W1, 1, 1, prevWeekTime) <= 0 || CopyTime(_Symbol, PERIOD_W1, 0, 1, currWeekTime) <= 0) { Print("❌ Failed to retrieve weekly candle data."); return; } double prev_high = highs[0]; double prev_low = lows[0]; datetime curr_week_start = currWeekTime[0]; datetime curr_week_end = curr_week_start + 7 * 24 * 60 * 60; DrawHorizontalSegment(HIGH_LINE_NAME, curr_week_start, curr_week_end, prev_high, HighLineColor); DrawHorizontalSegment(LOW_LINE_NAME, curr_week_start, curr_week_end, prev_low, LowLineColor); } //+------------------------------------------------------------------+ //| Draw horizontal line segment | //+------------------------------------------------------------------+ void DrawHorizontalSegment(string name, datetime time1, datetime time2, double price, color clr) { ObjectDelete(0, name); // Remove existing object if (!ObjectCreate(0, name, OBJ_TREND, 0, time1, price, time2, price)) { Print("❌ Failed to create line: ", name); return; } ObjectSetInteger(0, name, OBJPROP_COLOR, clr); ObjectSetInteger(0, name, OBJPROP_WIDTH, LineWidth); ObjectSetInteger(0, name, OBJPROP_STYLE, LineStyle); ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, false); ObjectSetInteger(0, name, OBJPROP_RAY_LEFT, false); ObjectSetInteger(0, name, OBJPROP_BACK, true); ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false); } //+------------------------------------------------------------------+ //| Required dummy calculation for indicators | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { return(rates_total); }