Advanced Day of Week Entry Time by Naya
55 downloads / 34 views / Created: 08.06.2025 Average Rating: 0
Indicator Description
Advanced Day of Week Entry Time is an advanced filter used to control entry signals based on specific day and time conditions. It supports multiple datetime filtering modes, allowing precise customization of when entries are allowed.
Available Logic:
Enter the market between the specified days and times
Parameters:
1. DateTime Mode:
* Daily time filter (applies a time range filter within each selected day)
* Absolute datetime match (checks for an exact day and time range)
* Everyday ignores time filtering (entire week is allowed without time restriction)
* Everyday uses time filtering (entire week is filtered by time range only)
* Weekly session (applies time filter only on the first and last day of the period)
2. Day Range:
* From day (inclusive): Selectable from Sunday to Saturday or "Everyday"
* To day (exclusive): Selectable from Sunday to Saturday or "Everyday"
3. Time Range:
* From hour and minute (inclusive)
* To hour and minute (exclusive)
Logic Behavior based on DateTime Mode:
* Daily time filter: Allows entry if the current bar’s time falls within the defined time range on allowed days.
* Absolute datetime match: Allows entry only when both day and time match exactly, handling day overlaps accurately.
* Everyday ignores time filtering: Allows entry every day regardless of time.
* Everyday uses time filtering: Allows entry every day but only within the defined time range.
* Weekly session: Allows entry from the defined time on the first day up to the end time on the last day of the selected range.
Use Case:
Ideal for strategies requiring precise control over entry windows based on trading sessions, news cycles, or institutional market activity hours.
Available Logic:
Enter the market between the specified days and times
Parameters:
1. DateTime Mode:
* Daily time filter (applies a time range filter within each selected day)
* Absolute datetime match (checks for an exact day and time range)
* Everyday ignores time filtering (entire week is allowed without time restriction)
* Everyday uses time filtering (entire week is filtered by time range only)
* Weekly session (applies time filter only on the first and last day of the period)
2. Day Range:
* From day (inclusive): Selectable from Sunday to Saturday or "Everyday"
* To day (exclusive): Selectable from Sunday to Saturday or "Everyday"
3. Time Range:
* From hour and minute (inclusive)
* To hour and minute (exclusive)
Logic Behavior based on DateTime Mode:
* Daily time filter: Allows entry if the current bar’s time falls within the defined time range on allowed days.
* Absolute datetime match: Allows entry only when both day and time match exactly, handling day overlaps accurately.
* Everyday ignores time filtering: Allows entry every day regardless of time.
* Everyday uses time filtering: Allows entry every day but only within the defined time range.
* Weekly session: Allows entry from the defined time on the first day up to the end time on the last day of the selected range.
Use Case:
Ideal for strategies requiring precise control over entry windows based on trading sessions, news cycles, or institutional market activity hours.
Comments
//==============================================================
// Forex Strategy Builder
// Copyright © Miroslav Popov. All rights reserved.
//==============================================================
// THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE.
//==============================================================
using System;
using ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
public class AdvancedDayOfWeekEntryTime : Indicator
{
public AdvancedDayOfWeekEntryTime()
{
IndicatorName = "Advanced Day of Week Entry Time";
PossibleSlots = SlotTypes.OpenFilter;
IsDeafultGroupAll = true;
IsGeneratable = false;
IndicatorAuthor = "NAYA,+237674724684";
IndicatorVersion = "2.0";
IndicatorDescription = "Advanced time and day filter with multiple datetime handling modes for precise entry control.";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
IndParam.IsAllowLTF = false;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
IndParam.ListParam[0].ItemList = new[]
{
"Enter the market between the specified days and times"
};
IndParam.ListParam[0].Index = 0;
IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
IndParam.ListParam[0].Enabled = true;
IndParam.ListParam[0].ToolTip = "Indicator's logic.";
// DateTime Mode
IndParam.ListParam[1].Caption = "DateTime Mode";
IndParam.ListParam[1].ItemList = new[]
{
"Daily time filter (time range within each day)",
"Absolute datetime match (exact from-to combination)",
"Everyday ignores time filtering",
"Everyday uses time filtering",
"Weekly session (time only on first/last day)"
};
IndParam.ListParam[1].Index = 0;
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "Determines how datetime filtering is applied.";
// From Day
IndParam.ListParam[2].Caption = "From day (incl.)";
IndParam.ListParam[2].ItemList = new[]
{
"Everyday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
IndParam.ListParam[2].Index = 0;
IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
IndParam.ListParam[2].Enabled = true;
IndParam.ListParam[2].ToolTip = "Starting day for the entry period.";
// To Day
IndParam.ListParam[3].Caption = "To day (excl.)";
IndParam.ListParam[3].ItemList = new[]
{
"Everyday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
IndParam.ListParam[3].Index = 0;
IndParam.ListParam[3].Text = IndParam.ListParam[3].ItemList[IndParam.ListParam[3].Index];
IndParam.ListParam[3].Enabled = true;
IndParam.ListParam[3].ToolTip = "Ending day for the entry period.";
// The NumericUpDown parameters for time
IndParam.NumParam[0].Caption = "From hour (incl.)";
IndParam.NumParam[0].Value = 0;
IndParam.NumParam[0].Min = 0;
IndParam.NumParam[0].Max = 23;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "Starting hour for the entry period.";
IndParam.NumParam[1].Caption = "From minute (incl.)";
IndParam.NumParam[1].Value = 0;
IndParam.NumParam[1].Min = 0;
IndParam.NumParam[1].Max = 59;
IndParam.NumParam[1].Enabled = true;
IndParam.NumParam[1].ToolTip = "Starting minute for the entry period.";
IndParam.NumParam[2].Caption = "To hour (excl.)";
IndParam.NumParam[2].Value = 24;
IndParam.NumParam[2].Min = 0;
IndParam.NumParam[2].Max = 24;
IndParam.NumParam[2].Enabled = true;
IndParam.NumParam[2].ToolTip = "Ending hour for the entry period.";
IndParam.NumParam[3].Caption = "To minute (excl.)";
IndParam.NumParam[3].Value = 0;
IndParam.NumParam[3].Min = 0;
IndParam.NumParam[3].Max = 59;
IndParam.NumParam[3].Enabled = true;
IndParam.NumParam[3].ToolTip = "Ending minute for the entry period.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
// Reading the parameters
var logicType = IndParam.ListParam[0].Index;
var dateTimeMode = IndParam.ListParam[1].Index;
var fromDayIndex = IndParam.ListParam[2].Index;
var toDayIndex = IndParam.ListParam[3].Index;
var fromHour = (int)IndParam.NumParam[0].Value;
var fromMin = (int)IndParam.NumParam[1].Value;
var toHour = (int)IndParam.NumParam[2].Value;
var toMin = (int)IndParam.NumParam[3].Value;
// Convert day indices to DayOfWeek (0=Everyday, 1=Sunday=0, 2=Monday=1, etc.)
DayOfWeek? fromDay = fromDayIndex == 0 ? (DayOfWeek?)null : (DayOfWeek)(fromDayIndex - 1);
DayOfWeek? toDay = toDayIndex == 0 ? (DayOfWeek?)null : (DayOfWeek)(toDayIndex - 1);
var fromTime = new TimeSpan(fromHour, fromMin, 0);
var toTime = new TimeSpan(toHour, toMin, 0);
// Calculation
int firstBar = 2;
var signal = new double[Bars];
for (int bar = firstBar; bar < Bars; bar++)
{
DateTime currentTime = Time[bar];
TimeSpan currentTimeOfDay = currentTime.TimeOfDay;
DayOfWeek currentDayOfWeek = currentTime.DayOfWeek;
bool isInRange = false;
switch (dateTimeMode)
{
case 0: // Daily time filter
isInRange = IsInDailyTimeFilter(currentTime, currentDayOfWeek, currentTimeOfDay,
fromDay, toDay, fromTime, toTime);
break;
case 1: // Absolute datetime match
isInRange = IsInAbsoluteMatch(currentTime, currentDayOfWeek, currentTimeOfDay,
fromDay, toDay, fromTime, toTime);
break;
case 2: // Everyday ignores time
isInRange = IsInEverydayMode(currentTime, currentDayOfWeek, currentTimeOfDay,
fromDay, toDay, fromTime, toTime, false);
break;
case 3: // Everyday uses time
isInRange = IsInEverydayMode(currentTime, currentDayOfWeek, currentTimeOfDay,
fromDay, toDay, fromTime, toTime, true);
break;
case 4: // Weekly session
isInRange = IsInWeeklySession(currentTime, currentDayOfWeek, currentTimeOfDay,
fromDay, toDay, fromTime, toTime);
break;
}
signal[bar] = isInRange ? 1 : 0;
}
// Saving the components
Component = new IndicatorComp[4];
Component[0] = new IndicatorComp
{
CompName = "Is long entry allowed",
DataType = logicType == 0 ? IndComponentType.AllowOpenLong : IndComponentType.ForceCloseLong,
ChartType = IndChartType.NoChart,
ShowInDynInfo = false,
FirstBar = firstBar,
Value = signal
};
Component[1] = new IndicatorComp
{
CompName = "Is short entry allowed",
DataType = logicType == 0 ? IndComponentType.AllowOpenShort : IndComponentType.ForceCloseShort,
ChartType = IndChartType.NoChart,
ShowInDynInfo = false,
FirstBar = firstBar,
Value = signal
};
// Additional components for visualization
Component[2] = new IndicatorComp
{
CompName = "Time Filter Active",
DataType = IndComponentType.IndicatorValue,
ChartType = IndChartType.NoChart,
ShowInDynInfo = false,
FirstBar = firstBar,
Value = signal
};
Component[3] = new IndicatorComp
{
CompName = "Visualization",
DataType = IndComponentType.Other,
ChartType = IndChartType.NoChart,
ShowInDynInfo = false,
FirstBar = firstBar,
Value = signal
};
}
private bool IsInDailyTimeFilter(DateTime currentTime, DayOfWeek currentDayOfWeek, TimeSpan currentTimeOfDay,
DayOfWeek? fromDay, DayOfWeek? toDay, TimeSpan fromTime, TimeSpan toTime)
{
// Check if we're in the day range
if (fromDay == null && toDay == null)
{
// Both days are "Everyday" - check time only
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
if (fromDay == null || toDay == null)
{
// One day is "Everyday" - check time only
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
// Check if we're in the specified day range
bool isInDayRange = IsDayInRange(currentDayOfWeek, fromDay.Value, toDay.Value);
if (!isInDayRange)
return false;
// Apply time filter within the day
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
private bool IsInAbsoluteMatch(DateTime currentTime, DayOfWeek currentDayOfWeek, TimeSpan currentTimeOfDay,
DayOfWeek? fromDay, DayOfWeek? toDay, TimeSpan fromTime, TimeSpan toTime)
{
// If both days are "Everyday", treat as time-only filter
if (fromDay == null && toDay == null)
{
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
// If one day is "Everyday", treat as time-only filter
if (fromDay == null || toDay == null)
{
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
// For same day, check exact time range
if (fromDay.Value == toDay.Value)
{
return (currentDayOfWeek == fromDay.Value) && IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
// For different days, check boundaries precisely
if (currentDayOfWeek == fromDay.Value)
{
return currentTimeOfDay >= fromTime;
}
else if (currentDayOfWeek == toDay.Value)
{
return currentTimeOfDay < toTime;
}
else
{
return IsDayInRange(currentDayOfWeek, fromDay.Value, toDay.Value);
}
}
private bool IsInEverydayMode(DateTime currentTime, DayOfWeek currentDayOfWeek, TimeSpan currentTimeOfDay,
DayOfWeek? fromDay, DayOfWeek? toDay, TimeSpan fromTime, TimeSpan toTime, bool useTimeFilter)
{
// If both days are "Everyday"
if (fromDay == null && toDay == null)
{
if (useTimeFilter)
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
else
return true;
}
// If one day is "Everyday"
if (fromDay == null || toDay == null)
{
if (useTimeFilter)
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
else
return true;
}
// If specific days are set, use standard logic
bool isInDayRange = IsDayInRange(currentDayOfWeek, fromDay.Value, toDay.Value);
if (!isInDayRange)
return false;
if (useTimeFilter)
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
else
return true;
}
private bool IsInWeeklySession(DateTime currentTime, DayOfWeek currentDayOfWeek, TimeSpan currentTimeOfDay,
DayOfWeek? fromDay, DayOfWeek? toDay, TimeSpan fromTime, TimeSpan toTime)
{
// If both days are "Everyday", treat as time-only filter
if (fromDay == null && toDay == null)
{
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
// If one day is "Everyday", treat as time-only filter
if (fromDay == null || toDay == null)
{
return IsTimeInRange(currentTimeOfDay, fromTime, toTime);
}
// Check if we're in the day range
bool isInDayRange = IsDayInRange(currentDayOfWeek, fromDay.Value, toDay.Value);
if (!isInDayRange)
return false;
// For first day of range, check start time
if (currentDayOfWeek == fromDay.Value)
{
return currentTimeOfDay >= fromTime;
}
// For last day of range, check end time
else if (currentDayOfWeek == toDay.Value)
{
return currentTimeOfDay < toTime;
}
// For days in between, all times are valid
else
{
return true;
}
}
private bool IsTimeInRange(TimeSpan currentTime, TimeSpan fromTime, TimeSpan toTime)
{
if (fromTime < toTime)
{
// Normal time range (e.g., 09:00 to 17:00)
return currentTime >= fromTime && currentTime < toTime;
}
else if (fromTime > toTime)
{
// Overnight time range (e.g., 22:00 to 06:00)
return currentTime >= fromTime || currentTime < toTime;
}
else
{
// Same time - allow all day
return true;
}
}
private bool IsDayInRange(DayOfWeek currentDay, DayOfWeek fromDay, DayOfWeek toDay)
{
if (fromDay == toDay)
{
return currentDay == fromDay;
}
else if (fromDay < toDay)
{
// Normal week range (e.g., Monday to Friday)
return currentDay >= fromDay && currentDay <= toDay;
}
else
{
// Weekend-spanning range (e.g., Friday to Monday)
return currentDay >= fromDay || currentDay <= toDay;
}
}
public override void SetDescription()
{
var logicType = IndParam.ListParam[0].Index;
var dateTimeMode = IndParam.ListParam[1].Index;
var fromDayIndex = IndParam.ListParam[2].Index;
var toDayIndex = IndParam.ListParam[3].Index;
var fromHour = (int)IndParam.NumParam[0].Value;
var fromMin = (int)IndParam.NumParam[1].Value;
var toHour = (int)IndParam.NumParam[2].Value;
var toMin = (int)IndParam.NumParam[3].Value;
string fromDayStr = IndParam.ListParam[2].ItemList[fromDayIndex];
string toDayStr = IndParam.ListParam[3].ItemList[toDayIndex];
string fromTimeStr = fromHour.ToString("00") + ":" + fromMin.ToString("00");
string toTimeStr = toHour.ToString("00") + ":" + toMin.ToString("00");
string action = logicType == 0 ? "entry" : "exit";
string modeDescription = "";
switch (dateTimeMode)
{
case 0: modeDescription = " (daily time filter)"; break;
case 1: modeDescription = " (absolute datetime match)"; break;
case 2: modeDescription = " (everyday ignores time)"; break;
case 3: modeDescription = " (everyday uses time)"; break;
case 4: modeDescription = " (weekly session)"; break;
}
string description;
if (fromDayIndex == 0 && toDayIndex == 0)
{
if (dateTimeMode == 2) // Everyday ignores time
{
description = "{action} is allowed every day{modeDescription}";
}
else
{
description = "{action} time is between {fromTimeStr} (incl.) and {toTimeStr} (excl.) every day{modeDescription}";
}
}
else
{
description = "{action} is allowed from {fromDayStr} {fromTimeStr} (incl.) to {toDayStr} {toTimeStr} (excl.){modeDescription}";
}
if (logicType == 0)
{
EntryFilterLongDescription = description;
EntryFilterShortDescription = description;
}
else
{
ExitFilterLongDescription = description;
ExitFilterShortDescription = description;
}
}
public override string ToString()
{
var logicType = IndParam.ListParam[0].Index;
var dateTimeMode = IndParam.ListParam[1].Index;
var fromDayIndex = IndParam.ListParam[2].Index;
var toDayIndex = IndParam.ListParam[3].Index;
var fromHour = (int)IndParam.NumParam[0].Value;
var fromMin = (int)IndParam.NumParam[1].Value;
var toHour = (int)IndParam.NumParam[2].Value;
var toMin = (int)IndParam.NumParam[3].Value;
string fromDayStr = IndParam.ListParam[2].ItemList[fromDayIndex];
string toDayStr = IndParam.ListParam[3].ItemList[toDayIndex];
string fromTimeStr = fromHour.ToString("00") + ":" + fromMin.ToString("00");
string toTimeStr = toHour.ToString("00") + ":" + toMin.ToString("00");
string modeAbbr = "";
switch (dateTimeMode)
{
case 0: modeAbbr = "[DTF]"; break;
case 1: modeAbbr = "[ABS]"; break;
case 2: modeAbbr = "[ENT]"; break;
case 3: modeAbbr = "[EWT]"; break;
case 4: modeAbbr = "[WKS]"; break;
}
string action = logicType == 0 ? "Entry" : "Exit";
if (fromDayIndex == 0 && toDayIndex == 0)
{
if (dateTimeMode == 2)
{
return "{action} Time Filter {modeAbbr} (All Days)";
}
else
{
return "{action} Time Filter {modeAbbr} (Daily {fromTimeStr}-{toTimeStr})";
}
}
else
{
return "{action} Time Filter {modeAbbr} ({fromDayStr} {fromTimeStr}-{toDayStr} {toTimeStr})";
}
}
}
}
//+------------------------------------------------------------------+ //| AdvancedDayOfWeekEntryTime.mqh | //| Copyright 2024, NAYA +237674724684 | //| https://www.example.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2024, NAYA +237674724684" #property link "https://www.example.com" #property version "2.0" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| Enumeration for DateTime modes | //+------------------------------------------------------------------+ enum ENUM_DATETIME_MODE { MODE_DAILY, // Daily time filter MODE_ABSOLUTE, // Absolute datetime match MODE_EVERYDAY_NOTIME, // Everyday ignores time MODE_EVERYDAY_TIME, // Everyday uses time MODE_WEEKLY_SESSION // Weekly session }; //+------------------------------------------------------------------+ //| Enumeration for days of week | //+------------------------------------------------------------------+ enum ENUM_DAY_OF_WEEK { DAY_EVERYDAY, // Everyday DAY_SUNDAY, // Sunday DAY_MONDAY, // Monday DAY_TUESDAY, // Tuesday DAY_WEDNESDAY, // Wednesday DAY_THURSDAY, // Thursday DAY_FRIDAY, // Friday DAY_SATURDAY // Saturday }; //+------------------------------------------------------------------+ //| Class AdvancedDayOfWeekEntryTime | //+------------------------------------------------------------------+ class AdvancedDayOfWeekEntryTime : public Indicator { public: AdvancedDayOfWeekEntryTime(SlotTypes slotType); virtual void Calculate(DataSet &dataSet); private: bool IsInDailyTimeFilter(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime); bool IsInAbsoluteMatch(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime); bool IsInEverydayMode(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime, bool useTimeFilter); bool IsInWeeklySession(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime); bool IsTimeInRange(int currentTime, int fromTime, int toTime); bool IsDayInRange(int currentDay, int fromDay, int toDay); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ void AdvancedDayOfWeekEntryTime::AdvancedDayOfWeekEntryTime(SlotTypes slotType) { SlotType = slotType; IndicatorName = "Advanced Day of Week Entry Time"; WarningMessage = "Advanced time and day filter for precise entry control with multiple datetime handling modes."; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = true; } //+------------------------------------------------------------------+ //| Calculate method | //+------------------------------------------------------------------+ void AdvancedDayOfWeekEntryTime::Calculate(DataSet &dataSet) { Data = GetPointer(dataSet); // Reading parameters int dateTimeMode = ListParam[1].Index; int fromDayIndex = ListParam[2].Index; int toDayIndex = ListParam[3].Index; int fromHour = (int)NumParam[0].Value; int fromMin = (int)NumParam[1].Value; int toHour = (int)NumParam[2].Value; int toMin = (int)NumParam[3].Value; // Convert day indices to DayOfWeek (0=Everyday=-1, 1=Sunday=0, 2=Monday=1, etc.) int fromDay = (fromDayIndex == 0) ? -1 : (fromDayIndex - 1); int toDay = (toDayIndex == 0) ? -1 : (toDayIndex - 1); // Create time spans in minutes int fromTime = fromHour * 60 + fromMin; int toTime = toHour * 60 + toMin; const int firstBar = 2; double signal[]; ArrayResize(signal, Data.Bars); ArrayInitialize(signal, 0); for(int bar = firstBar; bar < Data.Bars; bar++) { MqlDateTime mqlTime; TimeToStruct(Data.Time[bar], mqlTime); int currentTime = mqlTime.hour * 60 + mqlTime.min; int currentDay = mqlTime.day_of_week; // 0=Sunday, 1=Monday, ..., 6=Saturday bool isInRange = false; switch(dateTimeMode) { case 0: // Daily time filter isInRange = IsInDailyTimeFilter(mqlTime, fromDay, toDay, fromTime, toTime, currentTime); break; case 1: // Absolute datetime match isInRange = IsInAbsoluteMatch(mqlTime, fromDay, toDay, fromTime, toTime, currentTime); break; case 2: // Everyday ignores time isInRange = IsInEverydayMode(mqlTime, fromDay, toDay, fromTime, toTime, currentTime, false); break; case 3: // Everyday uses time isInRange = IsInEverydayMode(mqlTime, fromDay, toDay, fromTime, toTime, currentTime, true); break; case 4: // Weekly session isInRange = IsInWeeklySession(mqlTime, fromDay, toDay, fromTime, toTime, currentTime); break; } signal[bar] = isInRange ? 1 : 0; } // Set components ArrayResize(Component, 2); Component[0].CompName = "Is long entry allowed"; Component[0].DataType = IndComponentType_AllowOpenLong; Component[0].ShowInDynInfo = false; Component[0].FirstBar = firstBar; ArrayResize(Component[0].Value, Data.Bars); ArrayCopy(Component[0].Value, signal); Component[1].CompName = "Is short entry allowed"; Component[1].DataType = IndComponentType_AllowOpenShort; Component[1].ShowInDynInfo = false; Component[1].FirstBar = firstBar; ArrayResize(Component[1].Value, Data.Bars); ArrayCopy(Component[1].Value, signal); } //+------------------------------------------------------------------+ //| Daily Time Filter | //+------------------------------------------------------------------+ bool AdvancedDayOfWeekEntryTime::IsInDailyTimeFilter(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime) { // Check if we're in the day range if(fromDay == -1 && toDay == -1) { // Both days are "Everyday" - check time only return IsTimeInRange(currentTime, fromTime, toTime); } if(fromDay == -1 || toDay == -1) { // One day is "Everyday" - check time only return IsTimeInRange(currentTime, fromTime, toTime); } // Check if we're in the specified day range bool isInDayRange = IsDayInRange(mqlTime.day_of_week, fromDay, toDay); if(!isInDayRange) return false; // Apply time filter within the day return IsTimeInRange(currentTime, fromTime, toTime); } //+------------------------------------------------------------------+ //| Absolute DateTime Match | //+------------------------------------------------------------------+ bool AdvancedDayOfWeekEntryTime::IsInAbsoluteMatch(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime) { // If both days are "Everyday", treat as time-only filter if(fromDay == -1 && toDay == -1) { return IsTimeInRange(currentTime, fromTime, toTime); } // If one day is "Everyday", treat as time-only filter if(fromDay == -1 || toDay == -1) { return IsTimeInRange(currentTime, fromTime, toTime); } // For same day, check exact time range if(fromDay == toDay) { return (mqlTime.day_of_week == fromDay) && IsTimeInRange(currentTime, fromTime, toTime); } // For different days, check boundaries precisely if(mqlTime.day_of_week == fromDay) { return currentTime >= fromTime; } else if(mqlTime.day_of_week == toDay) { return currentTime < toTime; } else { return IsDayInRange(mqlTime.day_of_week, fromDay, toDay); } } //+------------------------------------------------------------------+ //| Everyday Mode | //+------------------------------------------------------------------+ bool AdvancedDayOfWeekEntryTime::IsInEverydayMode(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime, bool useTimeFilter) { // If both days are "Everyday" if(fromDay == -1 && toDay == -1) { if(useTimeFilter) return IsTimeInRange(currentTime, fromTime, toTime); else return true; } // If one day is "Everyday" if(fromDay == -1 || toDay == -1) { if(useTimeFilter) return IsTimeInRange(currentTime, fromTime, toTime); else return true; } // If specific days are set, use standard logic bool isInDayRange = IsDayInRange(mqlTime.day_of_week, fromDay, toDay); if(!isInDayRange) return false; if(useTimeFilter) return IsTimeInRange(currentTime, fromTime, toTime); else return true; } //+------------------------------------------------------------------+ //| Weekly Session | //+------------------------------------------------------------------+ bool AdvancedDayOfWeekEntryTime::IsInWeeklySession(MqlDateTime &mqlTime, int fromDay, int toDay, int fromTime, int toTime, int currentTime) { // If both days are "Everyday", treat as time-only filter if(fromDay == -1 && toDay == -1) { return IsTimeInRange(currentTime, fromTime, toTime); } // If one day is "Everyday", treat as time-only filter if(fromDay == -1 || toDay == -1) { return IsTimeInRange(currentTime, fromTime, toTime); } // Check if we're in the day range bool isInDayRange = IsDayInRange(mqlTime.day_of_week, fromDay, toDay); if(!isInDayRange) return false; // For first day of range, check start time if(mqlTime.day_of_week == fromDay) { return currentTime >= fromTime; } // For last day of range, check end time else if(mqlTime.day_of_week == toDay) { return currentTime < toTime; } // For days in between, all times are valid else { return true; } } //+------------------------------------------------------------------+ //| Check if time is in range | //+------------------------------------------------------------------+ bool AdvancedDayOfWeekEntryTime::IsTimeInRange(int currentTime, int fromTime, int toTime) { if(fromTime < toTime) { // Normal time range (e.g., 09:00 to 17:00) return currentTime >= fromTime && currentTime < toTime; } else if(fromTime > toTime) { // Overnight time range (e.g., 22:00 to 06:00) return currentTime >= fromTime || currentTime < toTime; } else { // Same time - allow all day return true; } } //+------------------------------------------------------------------+ //| Check if day is in range | //+------------------------------------------------------------------+ bool AdvancedDayOfWeekEntryTime::IsDayInRange(int currentDay, int fromDay, int toDay) { if(fromDay == toDay) { return currentDay == fromDay; } else if(fromDay < toDay) { // Normal week range (e.g., Monday to Friday) return currentDay >= fromDay && currentDay <= toDay; } else { // Weekend-spanning range (e.g., Friday to Monday) return currentDay >= fromDay || currentDay <= toDay; } } //+------------------------------------------------------------------+
Risk warning: Forex, spread bets and CFD are leveraged products. They may not be suitable for you as they carry a high degree of risk to your capital and you can lose more than your initial investment. You should ensure you understand all of the risks.
Copyright © 2006 - 2025, Forex Software Ltd.;
Copyright © 2006 - 2025, Forex Software Ltd.;