Написание скриптов на API
public interface IExternalScript : IExternalScriptBase, IStreamHandler, IHandler, IOneSourceHandler
{
void Execute(IContext ctx, ISecurity sec);
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSLab.Script;
using TSLab.Script.Handlers;
using TSLab.DataSource;
namespace MyLib
{
public class MyScript : IExternalScript
{
public void Execute(IContext ctx, ISecurity sec)
{
// Находим последний сформировавшийся бар для расчетов
var barsCount = sec.Bars.Count;
if (!ctx.IsLastBarUsed)
{
barsCount--;
}
// Торговый цикл
for (int i = ctx.TradeFromBar; i < barsCount; i++)
{
// Тут работа с позициями (sec.Positions)
}
// Если идет процесс оптимизации, то графики рисовать не нужно, это замедляет работу
if (ctx.IsOptimization)
{
return;
}
// Прорисовка графиков
// ctx.First - основная панель
}
}
}Last updated
Was this helpful?