Source »
Exit Hour - source code
// Forex Strategy Builder
// Copyright (c) 2006 - 2008 Miroslav Popov - All rights reserved!
// http://forexsb.com
// info(a)forexsb.com
//
// Last changed on: 2006-09-01
using System;
using System.Drawing;
namespace Forex_Strategy_Builder
{
/// <summary>
/// indicator: Exit Hour
/// </summary>
public class Exit_Hour : Indicator
{
/// <summary>
/// The default constructor.
/// </summary>
public Exit_Hour()
{
}
/// <summary>
/// Sets the default parameters for the designated slot type.
/// </summary>
/// <param name="slotType">The slot type.</param>
public Exit_Hour(SlotTypes slotType)
{
sIndicatorName = "Exit Hour";
parameters = new IndicatorParam();
component = new IndicatorComp[] { };
bIsCalculated = false;
timeExecution = TimeExecution.Closing;
typeOfIndicator = TypeOfIndicator.DateTime;
// The indicator name.
parameters.IndicatorName = sIndicatorName;
// The slot type.
parameters.SlotType = slotType;
// The ComboBox parameters.
parameters.ListParam[0].Caption = "Logic";
parameters.ListParam[0].ItemList = new string[]
{
"Exit the market before the specified hour"
};
parameters.ListParam[0].Index = 0;
parameters.ListParam[0].Text = parameters.ListParam[0].ItemList[parameters.ListParam[0].Index];
parameters.ListParam[0].Enabled = true;
parameters.ListParam[0].ToolTip = "Indicators' logic";
parameters.ListParam[1].Caption = "Base price";
parameters.ListParam[1].ItemList = new string[] { "Close" };
parameters.ListParam[1].Index = 0;
parameters.ListParam[1].Text = parameters.ListParam[1].ItemList[parameters.ListParam[1].Index];
parameters.ListParam[1].Enabled = true;
parameters.ListParam[1].ToolTip = "Exit price of the position";
// The NumericUpDown parameters.
parameters.NumParam[0].Caption = "Exit hour";
parameters.NumParam[0].Value = 0;
parameters.NumParam[0].Min = 0;
parameters.NumParam[0].Max = 24;
parameters.NumParam[0].Enabled = true;
parameters.NumParam[0].ToolTip = "The position's closing hour";
}
/// <summary>
/// Calculates the indicator's components.
/// </summary>
/// <param name="slotType">The slot type.</param>
public override void Calculate(SlotTypes slotType)
{
if (parameters.SlotType == SlotTypes.NotDefined) return;
// Reading the parameters
int iExitHour = (int)parameters.NumParam[0].Value;
TimeSpan tsExitHour = new TimeSpan(iExitHour, 0, 0);
// Calculation
int iFirstBar = 1;
float[] afBars = new float[Bars];
// Calculation of the logic.
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
if (Date[iBar - 1].DayOfYear == Date[iBar].DayOfYear &&
Date[iBar - 1].TimeOfDay < tsExitHour &&
Date[iBar].TimeOfDay >= tsExitHour)
afBars[iBar - 1] = Close[iBar - 1];
else if (Date[iBar - 1].DayOfYear != Date[iBar].DayOfYear &&
Date[iBar - 1].TimeOfDay < tsExitHour )
afBars[iBar - 1] = Close[iBar - 1];
else
afBars[iBar] = 0;
}
// Saving the components
component = new IndicatorComp[1];
component[0] = new IndicatorComp();
component[0].CompName = "Exit hour";
component[0].DataType = IndComponentType.ClosePrice;
component[0].ChartType = IndChartType.NoChart;
component[0].ShowInDynInfo = false;
component[0].FirstBar = iFirstBar;
component[0].Value = afBars;
bIsCalculated = true;
}
}
}
Top