diff --git a/Indicators/MyIndicators/Session_Analysis_Pro.mq5 b/Indicators/MyIndicators/Session_Analysis_Pro.mq5 index 0dacc02..1c664dd 100644 --- a/Indicators/MyIndicators/Session_Analysis_Pro.mq5 +++ b/Indicators/MyIndicators/Session_Analysis_Pro.mq5 @@ -3,131 +3,271 @@ //| Copyright 2025, xxxxxxxx| //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "4.00" // Scaled to support 3 independent markets -#property description "Draws boxes and analytics for up to 3 independent markets, each with Pre, Core, and Post sessions." -#property description "Supports Standard and Heikin Ashi price sources. Times are based on broker's server time." +#property version "6.00" // REFACTOR: Integrated custom VWAP engine for session-based VWAP +#property description "Draws boxes, analytics, and session-based VWAP via high-performance buffers." #property indicator_chart_window -#property indicator_plots 0 +// 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 +//--- Include Engines --- +#include // For Boxes, Mean, LinReg +#include // For VWAP calculations -//--- Custom Enum for Price Source, including Heikin Ashi --- -enum ENUM_APPLIED_PRICE_HA_ALL +//--- 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 { -//--- Heikin Ashi Prices (negative values for easy identification) - PRICE_HA_CLOSE = -1, PRICE_HA_OPEN = -2, PRICE_HA_HIGH = -3, PRICE_HA_LOW = -4, - PRICE_HA_MEDIAN = -5, PRICE_HA_TYPICAL = -6, PRICE_HA_WEIGHTED = -7, -//--- Standard Prices (using built-in ENUM_APPLIED_PRICE values) - PRICE_CLOSE_STD = PRICE_CLOSE, PRICE_OPEN_STD = PRICE_OPEN, PRICE_HIGH_STD = PRICE_HIGH, - PRICE_LOW_STD = PRICE_LOW, PRICE_MEDIAN_STD = PRICE_MEDIAN, PRICE_TYPICAL_STD = PRICE_TYPICAL, - PRICE_WEIGHTED_STD= PRICE_WEIGHTED + 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 ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; -input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; // Price for Mean and LinReg +input bool InpFillBoxes = false; +input ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; +input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // For VWAP +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_Start = "08:00"; input string InpM1_PreMarket_End = "09:30"; -input color InpM1_PreMarket_Color = clrSlateBlue; +input color InpM1_PreMarket_Color = C'25,25,112'; input bool InpM1_PreMarket_VWAP = true; -input bool InpM1_PreMarket_Mean = true; -input bool InpM1_PreMarket_LinReg = 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 color InpM1_Core_Color = C'70,130,180'; 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 string InpM1_PostMarket_End = "17:30"; +input color InpM1_PostMarket_Color = C'106,90,205'; input bool InpM1_PostMarket_VWAP = true; -input bool InpM1_PostMarket_Mean = true; -input bool InpM1_PostMarket_LinReg = 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 = true; +input bool InpM2_Enable = false; input group "M2 Pre-Market Session" input bool InpM2_PreMarket_Enable = true; -input string InpM2_PreMarket_Start = "04:00"; -input string InpM2_PreMarket_End = "07:00"; -input color InpM2_PreMarket_Color = clrIndianRed; +input string InpM2_PreMarket_Start = "07:00"; +input string InpM2_PreMarket_End = "08:00"; +input color InpM2_PreMarket_Color = clrLightCoral; input bool InpM2_PreMarket_VWAP = true; -input bool InpM2_PreMarket_Mean = true; -input bool InpM2_PreMarket_LinReg = 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 = "07:00"; -input string InpM2_Core_End = "15:30"; +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 = "15:30"; -input string InpM2_PostMarket_End = "16:15"; -input color InpM2_PostMarket_Color = clrIndianRed; +input string InpM2_PostMarket_Start = "16:30"; +input string InpM2_PostMarket_End = "17:30"; +input color InpM2_PostMarket_Color = clrFireBrick; input bool InpM2_PostMarket_VWAP = true; -input bool InpM2_PostMarket_Mean = true; -input bool InpM2_PostMarket_LinReg = 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 = true; +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 color InpM3_PreMarket_Color = clrMediumSeaGreen; input bool InpM3_PreMarket_VWAP = true; -input bool InpM3_PreMarket_Mean = true; -input bool InpM3_PreMarket_LinReg = 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 string InpM3_Core_End = "15:00"; 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 string InpM3_PostMarket_Start = "15:00"; +input string InpM3_PostMarket_End = "16:00"; +input color InpM3_PostMarket_Color = clrDarkGreen; input bool InpM3_PostMarket_VWAP = true; -input bool InpM3_PostMarket_Mean = true; -input bool InpM3_PostMarket_LinReg = 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_ANALYZERS 9 -CSessionAnalyzer *g_analyzers[TOTAL_ANALYZERS]; +#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 < TOTAL_ANALYZERS; i++) - g_analyzers[i] = NULL; + for(int i=0; i 0) g_last_bar_time = time[rates_total - 1]; - ENUM_APPLIED_PRICE price_type; - if(InpSourcePrice <= PRICE_HA_CLOSE) - price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); - else - price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; - - for(int i = 0; i < TOTAL_ANALYZERS; i++) +// --- Object Drawing Logic (Boxes, etc.) --- + for(int i=0; i