Название блока Profit_N_close_Position. Закладка New Category.
Блок получает прибыль за n последнюю сделку, где n - № сделки с конца, например для последней сделки необходимо ввести 1 , для предпоследней сделки 2 и т.д. На выходе блок выдает прибыль/убыток в рублях. Блок необходимо подключать к источнику данных.
Code:
using System;
using TSLab.Script;
using TSLab.Script.Handlers;
using System.Linq;
using TSLab.Script.Realtime;
using System.Collections.Generic;

namespace test
{
    [HandlerName("Profit_N_close_Position")]
    [HandlerCategory("NewCategory")]
    public class LastPosition : IOneSourceHandler, IDoubleReturns, IValuesHandler, ISecurityInputs
    {
        [HandlerParameter(true, "", NotOptimized = true)]
        public int Number { get; set; }

        public double Execute(ISecurity source, int barNum)
        {
            var list = source.Positions.Where(pos => !pos.IsActive && pos.EntryBarNum < barNum)
            .OrderBy(pos => pos.ExitBar.Date).ToArray();
            if (list.Length < 1)
                return 0;
            else if ((list.Length - Number) < 0 || Number<0)
                return 0;
            else
                return list[list.Length - Number].Profit();
        }
    }
}


Attachments
Profit_N_close_Position.rar (155 downloads)



Отредактировано romic (Fri Oct 28 2011 05:32 PM)