Source » Long or Short - source code

// Forex Strategy Builder
// Copyright (c) 2006 - 2008 Miroslav Popov - All rights reserved!
// http://forexsb.com
// info(a)forexsb.com
//
// Last changed on: 2007-09-20

using System;
using System.Drawing;

namespace Forex_Strategy_Builder
{
    /// <summary>
    /// Indicator: Long or Short
    /// </summary>
    public class Long_or_Short : Indicator
    {
        /// <summary>
        /// The default constructor.
        /// </summary>
        public Long_or_Short()
        {
        }

        /// <summary>
        /// Sets the default parameters for the designated slot type.
        /// </summary>
        /// <param name="slotType">The slot type.</param>
        public Long_or_Short(SlotTypes slotType)
        {
            sIndicatorName  = "Long or Short";
            parameters      = new IndicatorParam();
            component       = new IndicatorComp[] { };
            bSeparatedChart = false;
            bIsCalculated   = false;

            typeOfIndicator = TypeOfIndicator.Additional;

            // 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[]
            {
                "Open long positions only",
                "Open short positions only",
            };
            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 = "Logic of application of the indicator";

        }

        /// <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

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

            component[0] = new IndicatorComp();
            component[0].ChartType = IndChartType.NoChart;
            component[0].FirstBar = 0;
            component[0].Value = new float[Bars];
            component[0].DataType = IndComponentType.AllowOpenLong;
            component[0].CompName = "Allows long positions opening";

            component[1] = new IndicatorComp();
            component[1].ChartType = IndChartType.NoChart;
            component[1].FirstBar = 0;
            component[1].Value = new float[Bars];
            component[1].DataType = IndComponentType.AllowOpenShort;
            component[1].CompName = "Allows short positions opening";

            // Calculation of the logic.
            switch (parameters.ListParam[0].Text)
            {
                case "Open long positions only":
                    for (int i = 0; i < Bars; i++)
                    {
                        component[0].Value[i] = 1F;
                        component[1].Value[i] = 0F;
                    }
                    break;

                case "Open short positions only":
                    for (int i = 0; i < Bars; i++)
                    {
                        component[0].Value[i] = 0F;
                        component[1].Value[i] = 1F;
                    }
                    break;

                default:
                    break;
            }

            bIsCalculated = true;
        }
    }
}

Top