AdvanceExitTime by Naya

685 downloads / 328 views / Created: 30.05.2025
 Average Rating: 0

Indicator Description

Advance Exit Time Indicator

Description:
The Advance Exit Time indicator is designed to generate periodic exit signals at customizable intervals, starting from a specified anchor time. This powerful tool helps traders implement disciplined, time-based exit strategies for systematic position management.

Key Features:
- Anchor Time setting (hours and minutes) determines the starting point for periodic exits
- Adjustable Exit Period (in minutes) controls the frequency of exit signals
- Handles time calculations seamlessly, including midnight transitions
- Works effectively across various timeframes, with optimal performance on smaller timeframes

Use Cases:
1. Systematic profit-taking by closing trades at regular intervals
2. Session-based trading strategies with timed exits
3. Automated trading systems requiring scheduled position closures
4. Reducing emotional decision-making with predefined exit times

How It Works:
The indicator calculates exit points by measuring time intervals from the user-defined anchor time. For example, with an anchor time of 00:00 and a 60-minute period, exit signals will occur at the top of every hour (1:00, 2:00, etc.). The calculation properly accounts for daily time rollovers.

Benefits:
- Enforces trading discipline through structured exit rules
- Provides flexibility for different trading styles and timeframes
- Removes emotional bias from exit decisions
- Complements various trading strategies with reliable timing

Ideal For:
- Day traders and scalpers
- Systematic trading approaches
- Traders using time-based strategies
- Automated trading systems

Coded with the help Deepseek AI.

Comments

//============================================================== // 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.Custom { public class AdvanceExitTime : Indicator { public AdvanceExitTime() { IndicatorName = "Advance Exit Time"; PossibleSlots = SlotTypes.CloseFilter; IsDeafultGroupAll = true; IsGeneratable = false; WarningMessage = "The indicator generates exit signals at periodic intervals starting from the specified anchor time." + Environment.NewLine + "The strategy time frame should allow closing at the specified times."; IndicatorAuthor = "NAYA +237674724684"; IndicatorVersion = "1.0"; IndicatorDescription = "Generates periodic exit signals starting from a specified anchor time."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; IndParam.IsAllowLTF = false; // The ComboBox parameters 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[IndParam.ListParam[0].Index]; IndParam.ListParam[0].Enabled = true; IndParam.ListParam[0].ToolTip = "Indicator's logic."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Anchor hour"; IndParam.NumParam[0].Value = 0; IndParam.NumParam[0].Min = 0; IndParam.NumParam[0].Max = 23; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The hour component of the anchor time."; IndParam.NumParam[1].Caption = "Anchor minute"; IndParam.NumParam[1].Value = 0; IndParam.NumParam[1].Min = 0; IndParam.NumParam[1].Max = 59; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "The minute component of the anchor time."; IndParam.NumParam[2].Caption = "Exit period (minutes)"; IndParam.NumParam[2].Value = 60; IndParam.NumParam[2].Min = 1; IndParam.NumParam[2].Max = 1440; IndParam.NumParam[2].Enabled = true; IndParam.NumParam[2].ToolTip = "The interval between exit signals in minutes."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters int anchorHour = (int)IndParam.NumParam[0].Value; int anchorMinute = (int)IndParam.NumParam[1].Value; int exitPeriod = (int)IndParam.NumParam[2].Value; // Calculation const int firstBar = 2; double[] signal = new double[Bars]; // Calculate total minutes from anchor time int anchorTotalMinutes = anchorHour * 60 + anchorMinute; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { 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; } // Saving the components 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() { int anchorHour = (int)IndParam.NumParam[0].Value; int anchorMinute = (int)IndParam.NumParam[1].Value; int exitPeriod = (int)IndParam.NumParam[2].Value; string anchorTimeText = anchorHour.ToString("D2") + ":" + anchorMinute.ToString("D2"); ExitFilterLongDescription = "Exit the market every {exitPeriod} minutes starting from {anchorTimeText}"; ExitFilterShortDescription = "Exit the market every {exitPeriod} minutes starting from {anchorTimeText}"; } public override string ToString() { int anchorHour = (int)IndParam.NumParam[0].Value; int anchorMinute = (int)IndParam.NumParam[1].Value; int exitPeriod = (int)IndParam.NumParam[2].Value; string anchorTimeText = anchorHour.ToString("D2") + ":" + anchorMinute.ToString("D2"); return "{IndicatorName} ({anchorTimeText}, {exitPeriod} min)"; } } }
#property copyright "Copyright (C) 2025 NAYA +237674724684" #property link "NAYA +237674724684" #property version "1.00" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class AdvanceExitTime : public Indicator { public: AdvanceExitTime(SlotTypes slotType); virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void AdvanceExitTime::AdvanceExitTime(SlotTypes slotType) { SlotType = slotType; IndicatorName = "Advance Exit Time"; IsAllowLTF = false; ExecTime = ExecutionTime_AtBarClosing; WarningMessage = "The indicator generates exit signals at periodic intervals starting from the specified anchor time."; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void AdvanceExitTime::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); int anchorHour = (int)NumParam[0].Value; int anchorMinute = (int)NumParam[1].Value; int exitPeriod = (int)NumParam[2].Value; const int firstBar=1; double signal[]; ArrayResize(signal,Data.Bars); ArrayInitialize(signal,0); // Calculate total minutes from anchor time int anchorTotalMinutes = anchorHour * 60 + anchorMinute; for(int bar=firstBar; bar<Data.Bars; bar++) { MqlDateTime mqlTime; TimeToStruct(Data.Time[bar], mqlTime); int closeTotalMinutes = mqlTime.hour * 60 + mqlTime.min; // Calculate minutes since anchor time (with wrap-around at midnight) 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[0].Value, Data.Bars); ArrayCopy(Component[0].Value,signal); Component[0].DataType = IndComponentType_ForceCloseLong; Component[0].CompName = "Close out long position"; Component[0].FirstBar = firstBar; ArrayResize(Component[1].Value,Data.Bars); ArrayCopy(Component[1].Value,signal); Component[1].DataType = IndComponentType_ForceCloseShort; Component[1].CompName = "Close out short position"; Component[1].FirstBar = firstBar; } //+------------------------------------------------------------------+
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.;