AdvancedExitTimeSteps by Naya
176 downloads / 167 views / Created: 31.05.2025 Average Rating: 0
Indicator Description
Advanced Exit Time Steps is a technical indicator designed to automatically close trading positions at regular time intervals. It works by generating exit signals at fixed periods (like every 30, 60, or 120 minutes) starting from a user-defined anchor time.
Key Features:
- Lets traders set a specific starting time (anchor time) with hour and minute precision
- Allows configuration of exit intervals in steps from 30 minutes up to 24 hours
- Works as a close filter in trading strategies
- Forces position exits at each scheduled interval
- Helps maintain trading discipline through systematic exits
Practical Uses:
- Taking profits at regular intervals
- Managing risk by closing positions before major market events
- Aligning exits with specific trading sessions
- Avoiding overnight exposure
- Creating time-based exit rules for systematic strategies
Created with the help of DeepSeek AI and Claude AI
Key Features:
- Lets traders set a specific starting time (anchor time) with hour and minute precision
- Allows configuration of exit intervals in steps from 30 minutes up to 24 hours
- Works as a close filter in trading strategies
- Forces position exits at each scheduled interval
- Helps maintain trading discipline through systematic exits
Practical Uses:
- Taking profits at regular intervals
- Managing risk by closing positions before major market events
- Aligning exits with specific trading sessions
- Avoiding overnight exposure
- Creating time-based exit rules for systematic strategies
Created with the help of DeepSeek AI and Claude AI
using System;
using System.Collections.Generic;
using ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Custom
{
public class AdvancedExitTimeSteps : Indicator
{
public AdvancedExitTimeSteps()
{
IndicatorName = "Advanced Exit Time Steps";
PossibleSlots = SlotTypes.CloseFilter;
IsDeafultGroupAll = true;
IsGeneratable = false;
WarningMessage = "The indicator generates exit signals at periodic intervals starting from the specified anchor time." +
Environment.NewLine +
"Ensure the strategy time frame allows closing at these specific times.";
IndicatorAuthor = "NAYA +237674724684";
IndicatorVersion = "1.21";
IndicatorDescription = "Generates periodic exit signals based on specified time steps from an anchor time using bar close time.";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
IndParam.IsAllowLTF = false;
IndParam.ExecutionTime = ExecutionTime.AtBarClosing;
// Logic Parameter
IndParam.ListParam[0].Caption = "Logic";
IndParam.ListParam[0].ItemList = new[] { "Exit the market at periodic intervals" };
IndParam.ListParam[0].Index = 0;
IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[0];
IndParam.ListParam[0].Enabled = true;
IndParam.ListParam[0].ToolTip = "Defines the core behavior of the indicator.";
// Anchor Hour
IndParam.ListParam[1].Caption = "Anchor Hour";
var hours = new List();
for (int i = 0; i <= 23; i++)
hours.Add(i.ToString());
IndParam.ListParam[1].ItemList = hours.ToArray();
IndParam.ListParam[1].Index = 0;
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[0];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "The hour component (0-23) of the anchor time.";
// Anchor Minute
IndParam.ListParam[2].Caption = "Anchor Minute";
var minutes = new List();
for (int i = 0; i <= 45; i += 15)
minutes.Add(i.ToString());
IndParam.ListParam[2].ItemList = minutes.ToArray();
IndParam.ListParam[2].Index = 0;
IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[0];
IndParam.ListParam[2].Enabled = true;
IndParam.ListParam[2].ToolTip = "The minute component (0, 15, 30, 45) of the anchor time.";
// Exit Period
IndParam.ListParam[3].Caption = "Exit Period (minutes)";
var periods = new List();
for (int i = 15; i <= 1440; i += 15)
periods.Add(i.ToString());
IndParam.ListParam[3].ItemList = periods.ToArray();
IndParam.ListParam[3].Index = 0;
IndParam.ListParam[3].Text = IndParam.ListParam[3].ItemList[0];
IndParam.ListParam[3].Enabled = true;
IndParam.ListParam[3].ToolTip = "The interval (in minutes) between exit signals, starting from the anchor time. (15 to 1440 in steps of 15)";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
int anchorHour = int.TryParse(IndParam.ListParam[1].Text, out anchorHour) ? anchorHour : 0;
int anchorMinute = int.TryParse(IndParam.ListParam[2].Text, out anchorMinute) ? anchorMinute : 0;
int exitPeriod = int.TryParse(IndParam.ListParam[3].Text, out exitPeriod) ? Math.Max(15, exitPeriod) : 15;
const int firstBar = 2;
double[] signal = new double[Bars];
int anchorTotalMinutes = anchorHour * 60 + anchorMinute;
for (int bar = firstBar; bar < Bars; bar++)
{
// Use bar close time (same as AdvanceExitTime)
DateTime closeTime = Time[bar].AddMinutes((int)Period);
int closeTotalMinutes = closeTime.Hour * 60 + closeTime.Minute;
// Calculate minutes since anchor time
int minutesSinceAnchor = (closeTotalMinutes - anchorTotalMinutes + 1440) % 1440;
// Check if current time is a multiple of exitPeriod from anchor time
signal[bar] = (minutesSinceAnchor % exitPeriod == 0) ? 1 : 0;
}
Component = new IndicatorComp[2];
Component[0] = new IndicatorComp
{
CompName = "Close out long position",
DataType = IndComponentType.ForceCloseLong,
ChartType = IndChartType.NoChart,
ShowInDynInfo = true,
FirstBar = firstBar,
Value = signal
};
Component[1] = new IndicatorComp
{
CompName = "Close out short position",
DataType = IndComponentType.ForceCloseShort,
ChartType = IndChartType.NoChart,
ShowInDynInfo = true,
FirstBar = firstBar,
Value = signal
};
}
public override void SetDescription()
{
string anchorHourText = IndParam.ListParam[1].Text.PadLeft(2, '0');
string anchorMinuteText = IndParam.ListParam[2].Text.PadLeft(2, '0');
string exitPeriodText = IndParam.ListParam[3].Text;
string description = "Exit the market every {exitPeriodText} minutes starting from {anchorHourText}:{anchorMinuteText}";
ExitFilterLongDescription = description;
ExitFilterShortDescription = description;
}
public override string ToString()
{
string anchorHourText = IndParam.ListParam[1].Text.PadLeft(2, '0');
string anchorMinuteText = IndParam.ListParam[2].Text.PadLeft(2, '0');
string exitPeriodText = IndParam.ListParam[3].Text;
return "{IndicatorName} ({anchorHourText}:{anchorMinuteText}, {exitPeriodText} min)";
}
}
}
//+------------------------------------------------------------------+ //| AdvancedExitTimeSteps.mqh | //| Copyright (C) 2025 NAYA +237674724684 | //| NAYA +237674724684 | //+------------------------------------------------------------------+ #property copyright "Copyright (C) 2025 NAYA +237674724684" #property link "NAYA +237674724684" #property version "1.21" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| Class AdvancedExitTimeSteps | //+------------------------------------------------------------------+ class AdvancedExitTimeSteps : public Indicator { public: AdvancedExitTimeSteps(SlotTypes slotType); virtual void Calculate(DataSet &dataSet); virtual string ToString(); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ void AdvancedExitTimeSteps::AdvancedExitTimeSteps(SlotTypes slotType) { SlotType = slotType; IndicatorName = "Advanced Exit Time Steps"; IsAllowLTF = false; ExecTime = ExecutionTime_AtBarClosing; WarningMessage = "The indicator generates exit signals at periodic intervals starting from the specified anchor time. Ensure the strategy time frame allows closing at these specific times."; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = true; } //+------------------------------------------------------------------+ //| Calculate indicator values | //+------------------------------------------------------------------+ void AdvancedExitTimeSteps::Calculate(DataSet &dataSet) { Data = GetPointer(dataSet); if(ArraySize(ListParam) < 4) { PrintFormat("%s Error: ListParam array size is %d, expected at least 4.", IndicatorName, ArraySize(ListParam)); return; } string anchorHourText = ListParam[1].Text; string anchorMinuteText = ListParam[2].Text; string exitPeriodText = ListParam[3].Text; int anchorHour = (int)StringToInteger(anchorHourText); int anchorMinute = (int)StringToInteger(anchorMinuteText); int exitPeriod = (int)StringToInteger(exitPeriodText); anchorHour = MathMax(0, MathMin(23, anchorHour)); anchorMinute = MathMax(0, MathMin(59, anchorMinute)); exitPeriod = MathMax(15, MathMin(1440, exitPeriod)); if (exitPeriod <= 0) { PrintFormat("%s Error: Exit Period must be greater than 0. Using default value of 15.", IndicatorName); exitPeriod = 15; } const int firstBar = 2; double signal[]; ArrayResize(signal, Data.Bars); ArrayInitialize(signal, 0); int anchorTotalMinutes = anchorHour * 60 + anchorMinute; for(int bar = firstBar; bar < Data.Bars; bar++) { // Calculate bar close time (similar to C# version) datetime closeTime = Data.Time[bar] + Data.Period * 60; MqlDateTime mqlCloseTime; TimeToStruct(closeTime, mqlCloseTime); int closeTotalMinutes = mqlCloseTime.hour * 60 + mqlCloseTime.min; // Calculate minutes since anchor time int minutesSinceAnchor = (closeTotalMinutes - anchorTotalMinutes + 1440) % 1440; // Check if current time is a multiple of exitPeriod from anchor time signal[bar] = (minutesSinceAnchor % exitPeriod == 0) ? 1 : 0; } ArrayResize(Component, 2); Component[0].DataType = IndComponentType_ForceCloseLong; Component[0].CompName = "Close out long position"; Component[0].FirstBar = firstBar; ArrayResize(Component[0].Value, Data.Bars); ArrayCopy(Component[0].Value, signal); Component[1].DataType = IndComponentType_ForceCloseShort; Component[1].CompName = "Close out short position"; Component[1].FirstBar = firstBar; ArrayResize(Component[1].Value, Data.Bars); ArrayCopy(Component[1].Value, signal); } //+------------------------------------------------------------------+ //| Returns string representation of the indicator | //+------------------------------------------------------------------+ string AdvancedExitTimeSteps::ToString() { if(ArraySize(ListParam) < 4) return IndicatorName; string anchorHourText = ListParam[1].Text; string anchorMinuteText = ListParam[2].Text; string exitPeriodText = ListParam[3].Text; string anchorTimeFullText = StringFormat("%02d:%02d", (int)StringToInteger(anchorHourText), (int)StringToInteger(anchorMinuteText)); return StringFormat("%s (%s, %s min)", IndicatorName, anchorTimeFullText, exitPeriodText); } //+------------------------------------------------------------------+
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.;