Source » Day of week - 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: Day of week
    /// </summary>
    public class Day_of_week : Indicator
    {
        /// <summary>
        /// The default constructor.
        /// </summary>
        public Day_of_week()
        {
        }

        /// <summary>
        /// Sets the default parameters for the designated slot type.
        /// </summary>
        /// <param name="slotType">The slot type.</param>
        public Day_of_week(SlotTypes slotType)
        {
            sIndicatorName  = "Day of week";
            parameters      = new IndicatorParam();
            component       = new IndicatorComp[] { };
            bIsCalculated   = false;
            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 between the specified days"
            };
            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  = "From";
            parameters.ListParam[1].ItemList = Enum.GetNames(typeof(DayOfWeek));
            parameters.ListParam[1].Index    = 1;
            parameters.ListParam[1].Text     = parameters.ListParam[1].ItemList[parameters.ListParam[1].Index];
            parameters.ListParam[1].Enabled  = true;
            parameters.ListParam[1].ToolTip = "Beginning day of the entry period";

            parameters.ListParam[2].Caption  = "Until";
            parameters.ListParam[2].ItemList = Enum.GetNames(typeof(DayOfWeek));
            parameters.ListParam[2].Index    = 6;
            parameters.ListParam[2].Text     = parameters.ListParam[2].ItemList[parameters.ListParam[2].Index];
            parameters.ListParam[2].Enabled  = true;
            parameters.ListParam[2].ToolTip = "End day of the entry period";
        }

        /// <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
            DayOfWeek dowFromDay  = (DayOfWeek)Enum.GetValues(typeof(DayOfWeek)).GetValue(parameters.ListParam[1].Index);
            DayOfWeek dowUntilDay = (DayOfWeek)Enum.GetValues(typeof(DayOfWeek)).GetValue(parameters.ListParam[2].Index);

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

            // Calculation of the logic.
            for (int iBar = iFirstBar; iBar < Bars; iBar++)
            {
                if (dowFromDay < dowUntilDay)
                    afBars[iBar] = Date[iBar].DayOfWeek >= dowFromDay &&
                                   Date[iBar].DayOfWeek <  dowUntilDay ? 1 : 0;
                else if (dowFromDay > dowUntilDay)
                    afBars[iBar] = Date[iBar].DayOfWeek >= dowFromDay ||
                                   Date[iBar].DayOfWeek <  dowUntilDay ? 1 : 0;
                else
                    afBars[iBar] = 1;
            }

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

            component[0] = new IndicatorComp();
            component[0].CompName      = "Allow long entry";
            component[0].DataType      = IndComponentType.AllowOpenLong;
            component[0].ChartType     = IndChartType.NoChart;
            component[0].ShowInDynInfo = false;
            component[0].FirstBar      = iFirstBar;
            component[0].Value         = afBars;

            component[1] = new IndicatorComp();
            component[1].CompName      = "Allow short entry";
            component[1].DataType      = IndComponentType.AllowOpenShort;
            component[1].ChartType     = IndChartType.NoChart;
            component[1].ShowInDynInfo = false;
            component[1].FirstBar      = iFirstBar;
            component[1].Value         = afBars;

            bIsCalculated = true;
        }
    }
}

Top