Source » Traling Stop - 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-06-12

using System;
using System.Drawing;

namespace Forex_Strategy_Builder
{
    /// <summary>
    /// indicator: Traling Stop
    /// The implimentation of logic is in Market.AnalyseClose(int iBar)
    /// </summary>
    public class Trailing_Stop : Indicator
    {
        /// <summary>
        /// The default constructor.
        /// </summary>
        public Trailing_Stop()
        {
        }

        /// <summary>
        /// Sets the default parameters for the designated slot type.
        /// </summary>
        /// <param name="slotType">The slot type.</param>
        public Trailing_Stop(SlotTypes slotType)
        {
            sIndicatorName  = "Trailing Stop";
            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[]
            {
                "Exit at the Trailing Stop level",
            };
            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";

            // The NumericUpDown parameters.
            parameters.NumParam[0].Caption = "Trailing Stop";
            parameters.NumParam[0].Value   = -20;
            parameters.NumParam[0].Min     = -2000;
            parameters.NumParam[0].Max     = -5;
            parameters.NumParam[0].Enabled = true;
            parameters.NumParam[0].ToolTip = "The Trailing Stop value (in pips)";
        }

        /// <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].CompName      = "Trailing Stop for the transferred position";
            component[0].DataType      = IndComponentType.Other;
            component[0].ShowInDynInfo = false;
            component[0].FirstBar      = 1;
            component[0].Value         = new float[Data.Bars];

            component[1]               = new IndicatorComp();
            component[1].CompName      = "Trailing Stop for the new Order";
            component[1].DataType      = IndComponentType.Other;
            component[1].ShowInDynInfo = false;
            component[1].FirstBar      = 1;
            component[1].Value         = new float[Data.Bars];

            bIsCalculated = true;
        }
    }
}

Top