using System.Collections.Generic; using TSLab.Script; using TSLab.Script.Handlers; using TSLab.Script.Optimization; using TSLab.Script.Helpers; namespace TSLab.Samples { public class SBERProject5 : IExternalScript { public virtual void Execute(IContext ctx, ISecurity source) { // Торговля. int barsCount = source.Bars.Count; for (int bar = 24; (bar < barsCount-1); bar++) { IPosition Activebuy = source.Positions.GetLastActiveForSignal("Buy"); if (Activebuy == null) { // Если нет активных длинных позиций, выдаем условный ордер на создание новой позиции. source.Positions.BuyIfGreater(bar+1 , 1 ,source.OpenPrices[bar+1]+(source.HighPrices[bar]-source.LowPrices[bar]) , "Buy"); // покупка } else { // Если есть активные длинные позиции, выдаем условный ордер на закрытие позиций. Activebuy.CloseAtStop (bar+1 , source.OpenPrices[bar]-(source.HighPrices[bar]-source.LowPrices[bar]), "Buy Stop"); } IPosition Activeshort = source.Positions.GetLastActiveForSignal("Short"); if (Activeshort == null) { // Если нет активных коротких позиций, выдаем условный ордер на создание новой позиции. source.Positions.SellIfLess(bar+1 , 1 ,source.OpenPrices[bar+1]-(source.HighPrices[bar]-source.LowPrices[bar]) , "Short"); // продажа } else { Activeshort.CloseAtStop (bar+1 , source.OpenPrices[bar+1]+(source.HighPrices[bar]-source.LowPrices[bar]) , "Short Stop"); // Закрытие по стопу } } } } }