Source » Entry 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: Entry Hour
    /// </summary>
    public class Entry_Hour : Indicator
    {
        /// <summary>
        /// The default constructor.
        /// </summary>
        public Entry_Hour()
        {
        }

        /// <summary>
        /// Sets the default parameters for the designated slot type.
        /// </summary>
        /// <param name="slotType">The slot type.</param>
        public Entry_Hour(SlotTypes slotType)
        {
            sIndicatorName  = "Entry Hour";
            parameters      = new IndicatorParam();
            component       = new IndicatorComp[] { };
            bIsCalculated   = false;
            timeExecution   = TimeExecution.Opening;
            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[]
            {
                "Enter the market at 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[] { "Open" };
            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  = "The execution price of all entry orders";

            // The NumericUpDown parameters.
            parameters.NumParam[0].Caption = "Entry hour";
            parameters.NumParam[0].Value   = 0;
            parameters.NumParam[0].Min     = 0;
            parameters.NumParam[0].Max     = 23;
            parameters.NumParam[0].Enabled = true;
            parameters.NumParam[0].ToolTip = "The position's opening 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 iEntryHour = (int)parameters.NumParam[0].Value;
            TimeSpan tsEntryHour = new TimeSpan(iEntryHour, 0, 0);

            if (iEntryHour == 0)
                timeExecution = TimeExecution.Opening;

            // Calculation
            int iFirstBar = 1;
            float[] afBars = new float[Bars];

            // Calculation of the logic.
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                afBars[iBar] = Date[iBar].TimeOfDay == tsEntryHour ? Open[iBar] : 0f;
            }

            // Saving the components
            component = new IndicatorComp[1];

            component[0] = new IndicatorComp();
            component[0].CompName      = "Entry hour";
            component[0].DataType      = IndComponentType.OpenPrice;
            component[0].ChartType     = IndChartType.NoChart;
            component[0].ShowInDynInfo = false;
            component[0].FirstBar      = iFirstBar;
            component[0].Value         = afBars;

            bIsCalculated = true;
        }
    }
}

Top