Exit Time by Popov

48919 downloads / 4113 views / Created: 11.08.2015
 Average Rating: 5

Indicator Description

The Exit Time indicator can be used as a Closing Logic Condition together with Bar Closing indicator and other exit filters. It allows you to specify an Exit Time with hours and minutes.

When the current bar Close Time becomes equal to the specified time, the strategy closes the current position at Bar Closing.

The exit time must correspond to the time frame in order to be possible the bar's Close to happen at the specified time.

This indicator is useful if you have a strategy with closing logic conditions, but you want also to close the position at the end of the day. In that case, you can set Exit Time = 24:00 or other hour (Ex. 17:00, 23:30, ...)

Important points:


  • The indicator always uses server time.

  • Prevent trading after the close - if you want to prevent opening of new positions, after the Exit Time close, you have to restrict the entry by using a proper entry filter indicator. For example: Entry Hour, Entry Time...

  • Be aware of the Friday closing. This indicator sets one and the same closing time for all weak days. You have to close your position manually on Friday or by using other means.



Exit Time

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.Custom { public class ExitTime : Indicator { public ExitTime() { IndicatorName = "Exit Time"; PossibleSlots = SlotTypes.CloseFilter; IsDeafultGroupAll = true; IsGeneratable = false; WarningMessage = "The indicator rises a signal when the bar Close time is equal to the specified time." + Environment.NewLine + "The strategy time frame has to allow closing at the specified time."; IndicatorAuthor = "Miroslav Popov"; IndicatorVersion = "1.0"; IndicatorDescription = "Forces an exit at a specified 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 a specified time"}; 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 = "Exit 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 exit time."; IndParam.NumParam[1].Caption = "Exit 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 minutes component of the exit time."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters int hour = (int) IndParam.NumParam[0].Value; int minute = (int) IndParam.NumParam[1].Value; // Calculation const int firstBar = 2; double[] signal = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { DateTime closeTime = Time[bar].AddMinutes((int) Period); if (closeTime.Hour == hour && closeTime.Minute == minute) signal[bar] = 1; } // 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 hour = (int) IndParam.NumParam[0].Value; int minute = (int) IndParam.NumParam[1].Value; string exitTimeText = hour.ToString("D2") + ":" + minute.ToString("D2"); ExitFilterLongDescription = "Exit the market at " + exitTimeText; ExitFilterShortDescription = "Exit the market at " + exitTimeText; } } }
//+--------------------------------------------------------------------+ //| Copyright: (C) Forex Software Ltd. | //| Website: http://forexsb.com/ | //| Support: http://forexsb.com/forum/ | //| License: Proprietary under the following circumstances: | //| | //| This code is a part of Forex Strategy Builder. It is free for | //| use as an integral part of Forex Strategy Builder. | //| One can modify it in order to improve the code or to fit it for | //| personal use. This code or any part of it cannot be used in | //| other applications without a permission. | //| The contact information cannot be changed. | //| | //| NO LIABILITY FOR CONSEQUENTIAL DAMAGES | //| | //| In no event shall the author be liable for any damages whatsoever | //| (including, without limitation, incidental, direct, indirect and | //| consequential damages, damages for loss of business profits, | //| business interruption, loss of business information, or other | //| pecuniary loss) arising out of the use or inability to use this | //| product, even if advised of the possibility of such damages. | //+--------------------------------------------------------------------+ #property copyright "Copyright (C) Forex Software Ltd." #property link "http://forexsb.com" #property version "1.00" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class ExitTime : public Indicator { public: ExitTime(SlotTypes slotType) { SlotType=slotType; IndicatorName="Exit Time"; WarningMessage="The indicator rises a signal when the bar Close time is equal to the specified time."+"\n"+ "The strategy time frame has to allow closing at the specified time."; IsAllowLTF = false; ExecTime = ExecutionTime_AtBarClosing; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = true; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ExitTime::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters int hour=(int) NumParam[0].Value; int minute=(int) NumParam[1].Value; // Calculation const int firstBar=2; double signal[]; ArrayResize(signal,Data.Bars); ArrayInitialize(signal,0); // Calculation of the logic for(int bar=firstBar; bar<Data.Bars; bar++) { datetime closeTime=Data.Time[bar]+Data.Period*60; if(TimeHour(closeTime)==hour && TimeMinute(closeTime)==minute) signal[bar]=1; } // Saving the components Component[0].CompName = "Close out long position"; Component[0].DataType = IndComponentType_ForceCloseLong; Component[0].ShowInDynInfo=true; Component[0].FirstBar=firstBar; ArrayResize(Component[0].Value,Data.Bars); ArrayCopy(Component[0].Value,signal); Component[1].CompName = "Close out short position"; Component[1].DataType = IndComponentType_ForceCloseShort; Component[1].ShowInDynInfo=true; Component[1].FirstBar=firstBar; ArrayResize(Component[1].Value,Data.Bars); ArrayCopy(Component[1].Value,signal); } //+------------------------------------------------------------------+
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 - 2024, Forex Software Ltd.;