Exit Interval by Popov

4126 downloads / 4369 views / Created: 31.07.2013
 Average Rating: 0

Indicator Description

Request: indicator to close at a specified interval, like every 15 minutes, or every hour.

Indicator: Exit Interval
How to Use: in Closing slots, add Bar Closing. Then, add Exit Interval.

Parameters:

Interval Period -- set to every 5 minutes, 15 minutes, 30 minutes, 1 hour, or 4 hours
-- it will change the options so it's always higher than your current time frame

Offset -- move the interval forward this number of bars
Since it's Bar Closing, by default, it sends the close signal at the end of the bar before your target periodicity. This way, the signal comes fairly close to the target time, not after market closes.
Ex: 15 minutes current time frame, Interval Period = 1 hour
Expected: It will send the close signal on the bar at 1:45, 2:45, 3:45 (not 2:00, 3:00, 4:00). This is so that the order will be sent very close to the target time. In the example, the end of bar 1:45 would be 1:59:59.

If you really want it on the 2:00 bar, then set offset to 1.
If you want a 4-hour interval like 1:00, 5:00, 9:00:
- figure out how many bars offset your desired time
(ex: want to adjust by 1 hour, which has 12 bars with current time frame = 5)
- enter in Offset parameter

Forum link Exit Interval

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 System.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { /// /// Exit Interval indicator /// to exit at some interval of the hour (ex, every 15 minutes) /// public class ExitInterval : Indicator { public ExitInterval() { IndicatorName = "Exit Interval"; PossibleSlots = SlotTypes.CloseFilter; IndicatorAuthor = "Krog"; IndicatorVersion = "2.0"; IndicatorDescription = "A custom indicator for FSB and FST."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; IndParam.IndicatorType = TypeOfIndicator.DateTime; IndParam.ExecutionTime = ExecutionTime.AtBarClosing; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "Exit the market at the specified interval." }; 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.ListParam[1].Caption = "Interval Period"; IndParam.ListParam[1].ItemList = new string[] { "5 Minutes", "10 Minutes", "15 Minutes", "30 Minutes", "1 Hour", "2 Hours", "3 Hours", "4 Hours", "8 Hours", "12 Hours" }; IndParam.ListParam[1].Index = 9; IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index]; IndParam.ListParam[1].Enabled = true; IndParam.ListParam[1].ToolTip = "Choose interval in bars at which to exit.\nIf lower than your data time frame it will do nothing."; IndParam.NumParam[1].Caption = "Offset"; IndParam.NumParam[1].Value = 0; IndParam.NumParam[1].Min = 0; IndParam.NumParam[1].Max = 500; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "Offset the interval by this many bars.\nTry to choose a number of bars below the interval."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters TimeSpan ts = new TimeSpan(); switch (IndParam.ListParam[1].Text) { case "5 Minutes": ts = TimeSpan.FromMinutes (5); break; case "10 Minutes": ts = TimeSpan.FromMinutes (10); break; case "15 Minutes": ts = TimeSpan.FromMinutes (15); break; case "30 Minutes": ts = TimeSpan.FromMinutes (30); break; case "1 Hour": ts = TimeSpan.FromHours (1); break; case "2 Hours": ts = TimeSpan.FromHours (2); break; case "3 Hours": ts = TimeSpan.FromHours (3); break; case "4 Hours": ts = TimeSpan.FromHours (4); break; case "8 Hours": ts = TimeSpan.FromHours (8); break; case "12 Hours": ts = TimeSpan.FromHours (12); break; default: // if nothing works, then return to fail silently, used for start up return; } // if time frame is lower than interval, then return and do nothing if (ts.TotalMinutes <= (int)Period) { return; } double dOffset = IndParam.NumParam[1].Value * (double)Period; // Calculation double[] adBars = new double[Bars]; int iFirstBar = 10; DateTime dtStart = new DateTime (Time[0].Year, Time[0].Month, Time[0].Day, 0, 0, 0); // init so it's one bar back before target time, since indicator executes at Bar Closing dtStart = dtStart.AddMinutes(-(double)Period); // increment by number of bars to offset dtStart = dtStart.AddMinutes(dOffset); // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { if((Time[iBar]-dtStart).Ticks % ts.Ticks == 0) adBars[iBar] = 1; else adBars[iBar] = 0; } // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp(); Component[0].CompName = "Force Exit"; Component[0].DataType = IndComponentType.ForceClose; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = true; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; } public override void SetDescription() { string sInterval = IndParam.ListParam[1].Text; string sOffset = IndParam.NumParam[1].Value.ToString(); ExitFilterLongDescription = "at the interval of " + sInterval + " with offset of " + sOffset + " bars"; ExitFilterShortDescription = "at the interval of " + sInterval + " with offset of " + sOffset + " bars"; return; } public override string ToString() { string sInterval = IndParam.ListParam[1].Text; string sOffset = IndParam.NumParam[1].Value.ToString(); return IndicatorName + " (" + sInterval + ", " + // Interval "off=" + sOffset + ")"; // Offset } } }
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.;