//+------------------------------------------------------------------+ //| Session_Analysis_Pro.mq5| //| Copyright 2025, xxxxxxxx| //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" #property version "6.50" // Added History Limit to reduce template size #property description "Draws boxes, analytics, and session-based VWAP via high-performance buffers." #property indicator_chart_window // Buffers: M1(Pre A/B, Core A/B, Post A/B, Full A/B) = 8. Total for 3 markets = 24 #property indicator_buffers 24 #property indicator_plots 24 //--- Include Engines --- #include // For Boxes, Mean, LinReg #include // For VWAP calculations //--- Plot Properties for VWAP lines (Market 1) --- #property indicator_type1 DRAW_LINE #property indicator_label1 "M1 Pre VWAP" #property indicator_type2 DRAW_LINE #property indicator_label2 "" #property indicator_type3 DRAW_LINE #property indicator_label3 "M1 Core VWAP" #property indicator_type4 DRAW_LINE #property indicator_label4 "" #property indicator_type5 DRAW_LINE #property indicator_label5 "M1 Post VWAP" #property indicator_type6 DRAW_LINE #property indicator_label6 "" #property indicator_type7 DRAW_LINE #property indicator_label7 "M1 Full VWAP" #property indicator_type8 DRAW_LINE #property indicator_label8 "" //--- Plot Properties for VWAP lines (Market 2) --- #property indicator_type9 DRAW_LINE #property indicator_label9 "M2 Pre VWAP" #property indicator_type10 DRAW_LINE #property indicator_label10 "" #property indicator_type11 DRAW_LINE #property indicator_label11 "M2 Core VWAP" #property indicator_type12 DRAW_LINE #property indicator_label12 "" #property indicator_type13 DRAW_LINE #property indicator_label13 "M2 Post VWAP" #property indicator_type14 DRAW_LINE #property indicator_label14 "" #property indicator_type15 DRAW_LINE #property indicator_label15 "M2 Full VWAP" #property indicator_type16 DRAW_LINE #property indicator_label16 "" //--- Plot Properties for VWAP lines (Market 3) --- #property indicator_type17 DRAW_LINE #property indicator_label17 "M3 Pre VWAP" #property indicator_type18 DRAW_LINE #property indicator_label18 "" #property indicator_type19 DRAW_LINE #property indicator_label19 "M3 Core VWAP" #property indicator_type20 DRAW_LINE #property indicator_label20 "" #property indicator_type21 DRAW_LINE #property indicator_label21 "M3 Post VWAP" #property indicator_type22 DRAW_LINE #property indicator_label22 "" #property indicator_type23 DRAW_LINE #property indicator_label23 "M3 Full VWAP" #property indicator_type24 DRAW_LINE #property indicator_label24 "" //--- Enum for selecting the candle source for calculation --- enum ENUM_CANDLE_SOURCE { CANDLE_STANDARD, // Use standard OHLC data CANDLE_HEIKIN_ASHI // Use Heikin Ashi smoothed data }; //--- Input Parameters --- input group "Global Settings" input bool InpFillBoxes = false; input int InpMaxHistoryDays = 5; // Limit object history (0 = All) input ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // For VWAP and other analytics input ENUM_APPLIED_PRICE InpSourcePrice = PRICE_TYPICAL; // For Mean/LinReg //--- Market 1 Settings --- input group "Market 1 Settings (e.g., NYSE)" input bool InpM1_Enable = true; input group "M1 Pre-Market Session" input bool InpM1_PreMarket_Enable = true; input string InpM1_PreMarket_Start = "06:30"; input string InpM1_PreMarket_End = "09:30"; input color InpM1_PreMarket_Color = clrSlateBlue; input bool InpM1_PreMarket_VWAP = true; input bool InpM1_PreMarket_Mean = false; input bool InpM1_PreMarket_LinReg = false; input group "M1 Core Trading Session" input bool InpM1_Core_Enable = true; input string InpM1_Core_Start = "09:30"; input string InpM1_Core_End = "16:00"; input color InpM1_Core_Color = clrSlateBlue; input bool InpM1_Core_VWAP = true; input bool InpM1_Core_Mean = true; input bool InpM1_Core_LinReg = true; input group "M1 Post-Market Session" input bool InpM1_PostMarket_Enable = true; input string InpM1_PostMarket_Start = "16:00"; input string InpM1_PostMarket_End = "20:00"; input color InpM1_PostMarket_Color = clrSlateBlue; input bool InpM1_PostMarket_VWAP = true; input bool InpM1_PostMarket_Mean = false; input bool InpM1_PostMarket_LinReg = false; input group "M1 Full Day Analysis" input bool InpM1_FullDay_Enable = false; input color InpM1_FullDay_Color = clrGray; input bool InpM1_FullDay_VWAP = true; input bool InpM1_FullDay_Mean = false; input bool InpM1_FullDay_LinReg = false; //--- Market 2 Settings --- input group "Market 2 Settings (e.g., LSE)" input bool InpM2_Enable = false; input group "M2 Pre-Market Session" input bool InpM2_PreMarket_Enable = true; input string InpM2_PreMarket_Start = "05:00"; input string InpM2_PreMarket_End = "08:00"; input color InpM2_PreMarket_Color = clrIndianRed; input bool InpM2_PreMarket_VWAP = true; input bool InpM2_PreMarket_Mean = false; input bool InpM2_PreMarket_LinReg = false; input group "M2 Core Trading Session" input bool InpM2_Core_Enable = true; input string InpM2_Core_Start = "08:00"; input string InpM2_Core_End = "16:30"; input color InpM2_Core_Color = clrIndianRed; input bool InpM2_Core_VWAP = true; input bool InpM2_Core_Mean = true; input bool InpM2_Core_LinReg = true; input group "M2 Post-Market Session" input bool InpM2_PostMarket_Enable = true; input string InpM2_PostMarket_Start = "16:30"; input string InpM2_PostMarket_End = "17:15"; input color InpM2_PostMarket_Color = clrIndianRed; input bool InpM2_PostMarket_VWAP = true; input bool InpM2_PostMarket_Mean = false; input bool InpM2_PostMarket_LinReg = false; input group "M2 Full Day Analysis" input bool InpM2_FullDay_Enable = false; input color InpM2_FullDay_Color = clrGray; input bool InpM2_FullDay_VWAP = true; input bool InpM2_FullDay_Mean = false; input bool InpM2_FullDay_LinReg = false; //--- Market 3 Settings --- input group "Market 3 Settings (e.g., TSE)" input bool InpM3_Enable = false; input group "M3 Pre-Market Session" input bool InpM3_PreMarket_Enable = true; input string InpM3_PreMarket_Start = "08:00"; input string InpM3_PreMarket_End = "09:00"; input color InpM3_PreMarket_Color = clrSeaGreen; input bool InpM3_PreMarket_VWAP = true; input bool InpM3_PreMarket_Mean = false; input bool InpM3_PreMarket_LinReg = false; input group "M3 Core Trading Session" input bool InpM3_Core_Enable = true; input string InpM3_Core_Start = "09:00"; input string InpM3_Core_End = "11:30"; input color InpM3_Core_Color = clrSeaGreen; input bool InpM3_Core_VWAP = true; input bool InpM3_Core_Mean = true; input bool InpM3_Core_LinReg = true; input group "M3 Post-Market Session" input bool InpM3_PostMarket_Enable = true; input string InpM3_PostMarket_Start = "12:30"; input string InpM3_PostMarket_End = "15:30"; input color InpM3_PostMarket_Color = clrSeaGreen; input bool InpM3_PostMarket_VWAP = true; input bool InpM3_PostMarket_Mean = false; input bool InpM3_PostMarket_LinReg = false; input group "M3 Full Day Analysis" input bool InpM3_FullDay_Enable = false; input color InpM3_FullDay_Color = clrGray; input bool InpM3_FullDay_VWAP = true; input bool InpM3_FullDay_Mean = false; input bool InpM3_FullDay_LinReg = false; //--- Indicator Buffers for VWAP --- double BufferM1_Pre_A[], BufferM1_Pre_B[]; double BufferM1_Core_A[], BufferM1_Core_B[]; double BufferM1_Post_A[], BufferM1_Post_B[]; double BufferM1_Full_A[], BufferM1_Full_B[]; double BufferM2_Pre_A[], BufferM2_Pre_B[]; double BufferM2_Core_A[], BufferM2_Core_B[]; double BufferM2_Post_A[], BufferM2_Post_B[]; double BufferM2_Full_A[], BufferM2_Full_B[]; double BufferM3_Pre_A[], BufferM3_Pre_B[]; double BufferM3_Core_A[], BufferM3_Core_B[]; double BufferM3_Post_A[], BufferM3_Post_B[]; double BufferM3_Full_A[], BufferM3_Full_B[]; //--- Global Variables --- #define TOTAL_SESSIONS 12 CSessionAnalyzer *g_box_analyzers[TOTAL_SESSIONS]; CVWAPCalculator *g_vwap_calculators[TOTAL_SESSIONS]; datetime g_last_bar_time; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { g_last_bar_time = 0; for(int i=0; i 0 && time[rates_total - 1] == g_last_bar_time && Bars(_Symbol, _Period) == rates_total) return(rates_total); if(rates_total > 0) g_last_bar_time = time[rates_total - 1]; // --- Clear VWAP buffers --- // Note: We clear them every new bar because we force full recalc for VWAP too ArrayInitialize(BufferM1_Pre_A, EMPTY_VALUE); ArrayInitialize(BufferM1_Pre_B, EMPTY_VALUE); ArrayInitialize(BufferM1_Core_A, EMPTY_VALUE); ArrayInitialize(BufferM1_Core_B, EMPTY_VALUE); ArrayInitialize(BufferM1_Post_A, EMPTY_VALUE); ArrayInitialize(BufferM1_Post_B, EMPTY_VALUE); ArrayInitialize(BufferM1_Full_A, EMPTY_VALUE); ArrayInitialize(BufferM1_Full_B, EMPTY_VALUE); ArrayInitialize(BufferM2_Pre_A, EMPTY_VALUE); ArrayInitialize(BufferM2_Pre_B, EMPTY_VALUE); ArrayInitialize(BufferM2_Core_A, EMPTY_VALUE); ArrayInitialize(BufferM2_Core_B, EMPTY_VALUE); ArrayInitialize(BufferM2_Post_A, EMPTY_VALUE); ArrayInitialize(BufferM2_Post_B, EMPTY_VALUE); ArrayInitialize(BufferM2_Full_A, EMPTY_VALUE); ArrayInitialize(BufferM2_Full_B, EMPTY_VALUE); ArrayInitialize(BufferM3_Pre_A, EMPTY_VALUE); ArrayInitialize(BufferM3_Pre_B, EMPTY_VALUE); ArrayInitialize(BufferM3_Core_A, EMPTY_VALUE); ArrayInitialize(BufferM3_Core_B, EMPTY_VALUE); ArrayInitialize(BufferM3_Post_A, EMPTY_VALUE); ArrayInitialize(BufferM3_Post_B, EMPTY_VALUE); ArrayInitialize(BufferM3_Full_A, EMPTY_VALUE); ArrayInitialize(BufferM3_Full_B, EMPTY_VALUE); // --- Object Drawing Logic (Boxes, etc.) --- // Pass 0 as prev_calculated to force full update (but optimized inside to skip drawing old boxes) for(int i=0; i