Skip to content

Commit

Permalink
1.22
Browse files Browse the repository at this point in the history
1. Added input parameter headings in the MT4 version of the indicator.
2. Improved performance for right-to-left and seamless scrolling modes.
3. Fixed an issue with flickering profiles in the seamless scrolling mode in MT5.
  • Loading branch information
EarnForex authored Jun 14, 2023
1 parent db0b90a commit 951734c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
8 changes: 4 additions & 4 deletions MarketProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Intraday - should be attached to M1-M15 timeframes. M5 is recommended.
// Designed for major currency pairs, but should work also with exotic pairs, CFDs, or commodities.
//
// Version 1.21
// Version 1.22
// Copyright 2010-2023, EarnForex.com
// https://www.earnforex.com/metatrader-indicators/MarketProfile/
// -------------------------------------------------------------------------------
Expand Down Expand Up @@ -582,7 +582,7 @@ protected override void Initialize()

ID = new Intraday[4];

// Check if Intraday User Settings are valid.
// Check if intraday user settings are valid.
IntradaySessionCount = 0;
if (!CheckIntradaySession(EnableIntradaySession1, IntradaySession1StartTime, IntradaySession1EndTime, IntradaySession1ColorScheme))
InitFailed = true;
Expand All @@ -593,7 +593,7 @@ protected override void Initialize()
if (!CheckIntradaySession(EnableIntradaySession4, IntradaySession4StartTime, IntradaySession4EndTime, IntradaySession4ColorScheme))
InitFailed = true;

// Warn user about Intraday mode
// Warn user about Intraday mode.
if (IntradaySessionCount == 0)
{
string alert_text = "Enable at least one intraday session if you want to use Intraday mode.";
Expand Down Expand Up @@ -782,7 +782,7 @@ public override void Calculate(int index)
return;
}

// Calculate rectangle
// Calculate rectangle.
if (Session == session_period.Rectangle) // Everything becomes very simple if rectangle sessions are used.
{
CheckRectangles();
Expand Down
45 changes: 24 additions & 21 deletions MarketProfile.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//+------------------------------------------------------------------+
#property copyright "EarnForex.com"
#property link "https://www.earnforex.com/metatrader-indicators/MarketProfile/"
#property version "1.21"
#property version "1.22"
#property strict

#property description "Displays the Market Profile indicator for intraday, daily, weekly, or monthly trading sessions."
Expand Down Expand Up @@ -107,6 +107,7 @@ enum alert_types // Required to type a parameter of DoAlerts().
};

input group "Main"
input string ____Main = "================";
input session_period Session = Daily;
input datetime StartFromDate = __DATE__; // StartFromDate: lower priority.
input bool StartFromCurrentSession = true; // StartFromCurrentSession: higher priority.
Expand All @@ -116,8 +117,9 @@ input bool EnableDevelopingPOC = false; // Enable Develo
input int ValueAreaPercentage = 70; // ValueAreaPercentage: Percentage of TPO's inside Value Area.

input group "Colors and looks"
input string ____Colors_and_looks = "================";
input color_scheme ColorScheme = Blue_to_Red;
input color SingleColor = clrBlue; // SingleColor: if ColorScheme is set to Single_Color.
input color SingleColor = clrBlue; // SingleColor: if ColorScheme is set to Single Color.
input bool ColorBullBear = false; // ColorBullBear: If true, colors are from bars' direction.
input color MedianColor = clrWhite;
input color ValueAreaSidesColor = clrWhite;
Expand Down Expand Up @@ -151,11 +153,13 @@ input int ProminentMedianWidth = 4;
input bool RightToLeft = false; // RightToLeft: Draw histogram from right to left.

input group "Performance"
input string ____Performance = "================";
input int PointMultiplier = 0; // PointMultiplier: higher value = fewer objects. 0 - adaptive.
input int ThrottleRedraw = 0; // ThrottleRedraw: delay (in seconds) for updating Market Profile.
input bool DisableHistogram = false; // DisableHistogram: do not draw profile, VAH, VAL, and POC still visible.

input group "Alerts"
input string ____Alerts = "================";
input bool AlertNative = false; // AlertNative: issue native pop-up alerts.
input bool AlertEmail = false; // AlertEmail: issue email alerts.
input bool AlertPush = false; // AlertPush: issue push-notification alerts.
Expand All @@ -178,6 +182,7 @@ input int AlertArrowWidthCC = 1; // AlertArrowWi
input int AlertArrowWidthGC = 1; // AlertArrowWidthGC: arrow width for gap crossover alerts.

input group "Intraday settings"
input string ____Intraday_settings = "================";
input bool EnableIntradaySession1 = true;
input string IntradaySession1StartTime = "00:00";
input string IntradaySession1EndTime = "06:00";
Expand All @@ -199,6 +204,7 @@ input string IntradaySession4EndTime = "00:00";
input color_scheme IntradaySession4ColorScheme = Yellow_to_Cyan;

input group "Miscellaneous"
input string ____Miscellaneous = "================";
input sat_sun_solution SaturdaySunday = Saturday_Sunday_Normal_Days;
input bool DisableAlertsOnWrongTimeframes = false; // Disable alerts on wrong timeframes.
input int ProminentMedianPercentage = 101; // Percentage of Median TPOs out of total for a Prominent one.
Expand Down Expand Up @@ -324,7 +330,7 @@ int OnInit()
InitFailed = true; // Soft INIT_FAILED.
}

// Check if Intraday User Settings are valid.
// Check if intraday user settings are valid.
IntradaySessionCount = 0;
if (!CheckIntradaySession(EnableIntradaySession1, IntradaySession1StartTime, IntradaySession1EndTime, IntradaySession1ColorScheme)) return INIT_PARAMETERS_INCORRECT;
if (!CheckIntradaySession(EnableIntradaySession2, IntradaySession2StartTime, IntradaySession2EndTime, IntradaySession2ColorScheme)) return INIT_PARAMETERS_INCORRECT;
Expand All @@ -350,7 +356,7 @@ int OnInit()
// Indicator Name.
IndicatorShortName("MarketProfile " + EnumToString(Session));

// Adaptive point multiplier. Calculate based on number of digits in quote (before plus after the dot).
// Adaptive point multiplier. Calculate based on number of digits in the quote (before plus after the dot).
if (PointMultiplier == 0)
{
double quote;
Expand Down Expand Up @@ -393,7 +399,7 @@ int OnInit()
// To clean up potential leftovers when applying a chart template.
ObjectCleanup();

// Check if user wants Session mode as Rectangle or if it is a right-to-left session, or if rays should be constantly monitored, or seamless scrolling is on.
// Enable timer if user wants Session mode as Rectangle or if it is a right-to-left session, or if rays should be constantly monitored, or seamless scrolling is on.
if ((Session == Rectangle) || (RightToLeft) || (HideRaysFromInvisibleSessions) || (SeamlessScrollingMode))
{
EventSetMillisecondTimer(500);
Expand Down Expand Up @@ -490,7 +496,7 @@ int OnCalculate(const int rates_total,
if ((int)TimeLocal() - Timer < ThrottleRedraw) return rates_total;
}

// Calculate rectangle
// Calculate rectangle.
if (Session == Rectangle) // Everything becomes very simple if rectangle sessions are used.
{
CheckRectangles();
Expand All @@ -507,8 +513,8 @@ int OnCalculate(const int rates_total,
}

// Get start and end bar numbers of the given session.
int sessionend = FindSessionEndByDate(StartDate);
int sessionstart = FindSessionStart(sessionend);
int sessionend = FindSessionEndByDate(StartDate); // Finding the session's right-most bar using the date of the previous session or starting date.
int sessionstart = FindSessionStart(sessionend); // Finding the session's left-most bar using its end (right-most) bar.

if (sessionstart == -1)
{
Expand Down Expand Up @@ -1561,11 +1567,10 @@ bool ProcessSession(const int sessionstart, const int sessionend, const int i, C
return true;
}

//+------------------------------------------------------------------+
//| A cycle through intraday sessions for a given day with necessary |
//| checks. |
//| Returns true on success, false - on failure. |
//+------------------------------------------------------------------+
//+--------------------------------------------------------------------------+
//| A cycle through intraday sessions for a given day with necessary checks. |
//| Returns true on success, false - on failure. |
//+--------------------------------------------------------------------------+
bool ProcessIntradaySession(int sessionstart, int sessionend, int i)
{
// 'remember_*' vars point at day start and day end throughout this function.
Expand Down Expand Up @@ -1642,7 +1647,7 @@ bool ProcessIntradaySession(int sessionstart, int sessionend, int i)
}
}

Max_number_of_bars_in_a_session = Max_number_of_bars_in_a_session / (PeriodSeconds() / 60);
Max_number_of_bars_in_a_session = Max_number_of_bars_in_a_session / (PeriodSeconds() / 60); // Convert minutes to bars.

// If it is the updating stage, we need to recalculate only those intraday sessions that include the current bar.
int hour, minute, time;
Expand Down Expand Up @@ -2387,14 +2392,13 @@ void OnTimer()
// This what goes below works for RightToLeft mode and for seamless scrolling mode, but only after the first run has been finished.

static datetime prev_converted_time = 0;

datetime converted_time = 0;

int dummy_subwindow;
double dummy_price;
ChartXYToTimePrice(0, (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS), 0, dummy_subwindow, converted_time, dummy_price);

if (converted_time == prev_converted_time) return; // Do not call RedrawLastSession() if the screen hasn't been scrolled.
converted_time = prev_converted_time;
prev_converted_time = converted_time;

if (SeamlessScrollingMode)
{
Expand Down Expand Up @@ -2872,10 +2876,9 @@ void RedrawLastSession()
if ((ShowValueAreaRays != None) || (ShowMedianRays != None) || ((HideRaysFromInvisibleSessions) && (SinglePrintRays))) CheckRays();
}

//+------------------------------------------------------------------+
//| Go through all prices on all N session bars from 1st to kth bar, |
//| where k = 1..N. |
//+------------------------------------------------------------------+
//+----------------------------------------------------------------------------------+
//| Go through all prices on all N session bars from 1st to kth bar, where k = 1..N. |
//+----------------------------------------------------------------------------------+
void CalculateDevelopingPOC(int sessionstart, int sessionend, CRectangleMP* rectangle = NULL)
{
// Cycle through all possible end bars to calculate the Developing POC.
Expand Down
46 changes: 21 additions & 25 deletions MarketProfile.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//+------------------------------------------------------------------+
#property copyright "EarnForex.com"
#property link "https://www.earnforex.com/metatrader-indicators/MarketProfile/"
#property version "1.21"
#property version "1.22"

#property description "Displays the Market Profile indicator for intraday, daily, weekly, or monthly trading sessions."
#property description "Daily - should be attached to M5-M30 timeframes. M30 is recommended."
Expand Down Expand Up @@ -116,7 +116,7 @@ input int ValueAreaPercentage = 70; // ValueAreaPerc

input group "Colors and looks"
input color_scheme ColorScheme = Blue_to_Red;
input color SingleColor = clrBlue; // SingleColor: if ColorScheme is set to Single_Color.
input color SingleColor = clrBlue; // SingleColor: if ColorScheme is set to Single Color.
input bool ColorBullBear = false; // ColorBullBear: If true, colors are from bars' direction.
input color MedianColor = clrWhite;
input color ValueAreaSidesColor = clrWhite;
Expand Down Expand Up @@ -229,7 +229,6 @@ int IDEndHours[4];
int IDEndMinutes[4];
int IDEndTime[4]; // Stores IDEndHours x 60 + IDEndMinutes for comparison purposes.
color_scheme IDColorScheme[4];
bool IntradayCheckPassed = false;
int IntradaySessionCount = 0;
int _SessionsToCount;
int IntradayCrossSessionDefined = -1; // For special case used only with Ignore_Saturday_Sunday on Monday.
Expand Down Expand Up @@ -323,7 +322,7 @@ int OnInit()
InitFailed = true; // Soft INIT_FAILED.
}

// Check if Intraday User Settings are valid.
// Check if intraday user settings are valid.
IntradaySessionCount = 0;
if (!CheckIntradaySession(EnableIntradaySession1, IntradaySession1StartTime, IntradaySession1EndTime, IntradaySession1ColorScheme)) return INIT_PARAMETERS_INCORRECT;
if (!CheckIntradaySession(EnableIntradaySession2, IntradaySession2StartTime, IntradaySession2EndTime, IntradaySession2ColorScheme)) return INIT_PARAMETERS_INCORRECT;
Expand All @@ -350,7 +349,7 @@ int OnInit()
// Indicator Name.
IndicatorSetString(INDICATOR_SHORTNAME, "MarketProfile " + EnumToString(Session));

// Adaptive point multiplier. Calculate based on number of digits in quote (before plus after the dot).
// Adaptive point multiplier. Calculate based on number of digits in the quote (before plus after the dot).
if (PointMultiplier == 0)
{
double quote;
Expand Down Expand Up @@ -505,7 +504,7 @@ int OnCalculate(const int rates_total,
if ((int)TimeLocal() - Timer < ThrottleRedraw) return rates_total;
}

// Calculate rectangle
// Calculate rectangle.
if (Session == Rectangle) // Everything becomes very simple if rectangle sessions are used.
{
CheckRectangles(High, Low, Time, rates_total);
Expand All @@ -528,8 +527,8 @@ int OnCalculate(const int rates_total,
}

// Get start and end bar numbers of the given session.
int sessionend = FindSessionEndByDate(Time, StartDate, rates_total);
int sessionstart = FindSessionStart(Time, sessionend, rates_total);
int sessionend = FindSessionEndByDate(Time, StartDate, rates_total); // Finding the session's right-most bar using the date of the previous session or starting date.
int sessionstart = FindSessionStart(Time, sessionend, rates_total); // Finding the session's left-most bar using its end (right-most) bar.

if (sessionstart == -1)
{
Expand Down Expand Up @@ -1591,11 +1590,10 @@ bool ProcessSession(const int sessionstart, const int sessionend, const int i, c
return true;
}

//+------------------------------------------------------------------+
//| A cycle through intraday sessions for a given day with necessary |
//| checks. |
//| Returns true on success, false - on failure. |
//+------------------------------------------------------------------+
//+--------------------------------------------------------------------------+
//| A cycle through intraday sessions for a given day with necessary checks. |
//| Returns true on success, false - on failure. |
//+--------------------------------------------------------------------------+
bool ProcessIntradaySession(int sessionstart, int sessionend, const int i, const double& High[], const double& Low[], const datetime& Time[], const int rates_total)
{
// 'remember_*' vars point at day start and day end throughout this function.
Expand Down Expand Up @@ -1672,7 +1670,7 @@ bool ProcessIntradaySession(int sessionstart, int sessionend, const int i, const
}
}

Max_number_of_bars_in_a_session = Max_number_of_bars_in_a_session / (PeriodSeconds() / 60);
Max_number_of_bars_in_a_session = Max_number_of_bars_in_a_session / (PeriodSeconds() / 60); // Convert minutes to bars.

// If it is the updating stage, we need to recalculate only those intraday sessions that include the current bar.
int hour, minute, time;
Expand Down Expand Up @@ -2511,6 +2509,12 @@ void OnTimer()
static datetime prev_converted_time = 0;
datetime converted_time = 0;

int dummy_subwindow;
double dummy_price;
ChartXYToTimePrice(0, (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS), 0, dummy_subwindow, converted_time, dummy_price);
if (converted_time == prev_converted_time) return; // Do not call RedrawLastSession() if the screen hasn't been scrolled.
prev_converted_time = converted_time;

if (SeamlessScrollingMode)
{
ObjectCleanup(); // Delete everything to make sure there are no leftover sessions behind the screen.
Expand All @@ -2525,13 +2529,6 @@ void OnTimer()
}
}

int dummy_subwindow;
double dummy_price;
ChartXYToTimePrice(0, (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS), 0, dummy_subwindow, converted_time, dummy_price);

if (converted_time == prev_converted_time) return; // Do not call RedrawLastSession() if the screen hasn't been scrolled.
converted_time = prev_converted_time;

// Check right-most time - did it change?
RedrawLastSession(High, Low, Time, rates_total);

Expand Down Expand Up @@ -3006,10 +3003,9 @@ void RedrawLastSession(const double& High[], const double& Low[], const datetime
if ((ShowValueAreaRays != None) || (ShowMedianRays != None) || ((HideRaysFromInvisibleSessions) && (SinglePrintRays))) CheckRays();
}

//+------------------------------------------------------------------+
//| Go through all prices on all N session bars from 1st to kth bar, |
//| where k = 1..N. |
//+------------------------------------------------------------------+
//+----------------------------------------------------------------------------------+
//| Go through all prices on all N session bars from 1st to kth bar, where k = 1..N. |
//+----------------------------------------------------------------------------------+
void CalculateDevelopingPOC(const int sessionstart, const int sessionend, const double& High[], const double& Low[], CRectangleMP* rectangle = NULL)
{
// Cycle through all possible end bars to calculate the Developing POC.
Expand Down

0 comments on commit 951734c

Please sign in to comment.