Шаг 1 – попробуйте найти ответ:
База знаний: > API программы
Есть ли в API 2.0 возможность создавать свои модели свечей, как в API 1.2 в классе TSlab.Script.Bar ?
Автор Alexey TSLab, Изменено Alexey TSLab на 08 October 2018 19:05
|
|
Для этих целей можно использовать TSLab.DataSource.DataBar
Пример, в виде блока [HandlerCategory(HandlerCategories.TradeMath)] [HelperName("Multiply (CB) by", Language = Constants.En)] [HelperName("Умножить (ЦБ) на", Language = Constants.Ru)] [InputsCount(1)] [Input(0, TemplateTypes.SECURITY, Name = Constants.SecuritySource)] [OutputsCount(1)] [OutputType(TemplateTypes.SECURITY)] [Description("Кубик преобразует бары на входе в синтетический инструмент (все цены исходных баров умножаются на заданный коэффициент).")] [HelperDescription("Handler converts bars of an input to a synthetic security (all prices of incoming bars are multiplied by a given coefficient). ", Constants.En)] public class SecMultiply : IBar2BarHandler { /// <summary> /// \~english Every bar of input is multiplied by this coefficient ( Mult*x ) /// \~russian Каждый бар входной серии умножается на указанный коэффициент ( Mult*x ) /// </summary> [HelperName("Multiply", Constants.En)] [HelperName("Множитель", Constants.Ru)] [Description("Каждый бар входной серии умножается на указанный коэффициент ( Mult*x )")] [HelperDescription("Every bar of input is multiplied by this coefficient ( Mult*x )", Constants.En)] [HandlerParameter(true, "10")] public double Coef { get; set; } public ISecurity Execute(ISecurity source) { var bars = source.Bars.Select( bar => { var babar = bar as IBar; var nbar = babar == null ? new DataBar() : new BidAskBar { Ask = Math.Ceiling(babar.Ask * Coef), Bid = Math.Ceiling(babar.Bid * Coef), AskQty = babar.AskQty, BidQty = babar.BidQty, StepPrice = babar.StepPrice, Volatility = babar.Volatility, TheoreticalPrice = babar.TheoreticalPrice, }; nbar.Date = bar.Date; nbar.Open = Math.Ceiling(bar.Open * Coef); nbar.High = Math.Ceiling(bar.High * Coef); nbar.Low = Math.Ceiling(bar.Low * Coef); nbar.Close = Math.Ceiling(bar.Close * Coef); nbar.Volume = bar.Volume; nbar.Interest = bar.Interest; return nbar; }); return source.CloneAndReplaceBars(bars); } } | |
|