Forex Documentation

Forex Strategy Builder and Forex Strategy Trader

Trailing Stop - Source Code

// Traling Stop Indicator
// Last changed on 2010-04-11
// Part of Forex Strategy Builder & Forex Strategy Trader
// Website http://forexsb.com/
// Copyright (c) 2006 - 2010 Miroslav Popov - All rights reserved.
// This code or any part of it cannot be used in other applications without a permission.
 
namespace Forex_Strategy_Builder
{
    /// <summary>
    /// Traling Stop Indicator
    /// The implimentation of logic is in Market.AnalyseClose(int iBar)
    /// </summary>
	public class Trailing_Stop : Indicator
	{
        /// <summary>
        /// Sets the default indicator parameters for the designated slot type
        /// </summary>
        public Trailing_Stop(SlotTypes slotType)
        {
            // General properties
            IndicatorName     = "Trailing Stop";
            PossibleSlots     = SlotTypes.Close;
            WarningMessage    = "The Trailing Stop indicator trails once per bar." +
                " It means that the indicator doesn't move the position's SL at every new top / bottom, as in the real trade, but only when a new bar begins." +
                " The Stop Loss remains constant during the whole bar.";
 
            // Setting up the indicator parameters
            IndParam = new IndicatorParam();
            IndParam.IndicatorName = IndicatorName;
            IndParam.SlotType      = slotType;
            IndParam.IndicatorType = TypeOfIndicator.Additional;
 
            // The ComboBox parameters
            IndParam.ListParam[0].Caption  = "Logic";
            IndParam.ListParam[0].ItemList = new string[]
            {
                "Exit at the Trailing Stop level",
            };
            IndParam.ListParam[0].Index   = 0;
            IndParam.ListParam[0].Text    = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
            IndParam.ListParam[0].Enabled = true;
            IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";
 
            // The NumericUpDown parameters
            IndParam.NumParam[0].Caption = "Trailing Stop";
            IndParam.NumParam[0].Value   = 20;
            IndParam.NumParam[0].Min     = 5;
            IndParam.NumParam[0].Max     = 5000;
            IndParam.NumParam[0].Enabled = true;
            IndParam.NumParam[0].ToolTip = "The Trailing Stop value (in pips).";
 
            return;
        }
 
        /// <summary>
        /// Calculates the indicator's components
        /// </summary>
        public override void Calculate(SlotTypes slotType)
        {
            // Saving the components
            Component = new IndicatorComp[1];
 
			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 double[Bars];
 
            return;
		}
 
        /// <summary>
        /// Sets the indicator logic description
        /// </summary>
        public override void SetDescription(SlotTypes slotType)
        {
            int iStopLoss = (int)IndParam.NumParam[0].Value;
 
            ExitPointLongDescription  = "at the " + ToString() + " level";
            ExitPointShortDescription = "at the " + ToString() + " level";
 
            return;
        }
 
        /// <summary>
        /// Indicator to string
        /// </summary>
        public override string ToString()
        {
            string sString = IndicatorName + " (" +
                IndParam.NumParam[0].ValueToString + ")"; // Trailing Stop
 
            return sString;
        }
	}
}
 
indicators/source/trailing_stop.txt · Last modified: 2011/07/23 02:51 (external edit)