Код: Выделить всё
function Initialize()
{
IndicatorName = "Trades";
PriceStudy = true;
AddInput("I", Inputs.Candle);
AddSeries("CountBuy", DrawAs.Custom, Color.Green, AxisType.ZeroBased, true, Axes.New);
AddSeries("CountSell", DrawAs.Custom, Color.Red, AxisType.ZeroBased, true, Axes.New);
AddSeries("Buy", DrawAs.Custom, Color.Green);
AddSeries("Sell", DrawAs.Custom, Color.Red);
//Номинация
//1 Лучший частный инвестор на фондовом рынке
//2 Лучший частный инвестор на срочном рынке
//3 Лучший частный инвестор на валютном рынке
AddParameter("Nom", 2);
//Уникальный идентификатор пользователя
//см. ссылку на странице статистики пользователя ?user=XXXXXX, где XXXXXX - уникальный идентификатор
AddParameter("User", 0);
//год проведения конкурса
AddParameter("Year", 2019);
AddGlobalVariable("C", Types.DoubleList); // кол-во
AddGlobalVariable("Price", Types.DoubleList); // цена
AddGlobalVariable("DT", Types.DoubleList); // дата и время
AddGlobalVariable("Type", Types.IntList); // тип
AddGlobalVariable("NeedRead", Types.Boolean, true); // необходимость чтения данных
}
function Evaluate()
{
// evge 05.10.2018 http://alfadirect4.ru
// evge 23.09.2019 добавлен новый параметр Year - год проведения конкурса ЛЧИ
// evge 14.01.2020 добавлено отображение сделок на валютном рынке.
// Считываем параметры сделок из файла File (1 раз) в списки DoubleList
// ФОРМАТ .csv файла: Дата время (ГГГГ-ММ-ДД HH:MM:SS.000);Тикер;Кол-во;Цена
if (C.Count == 0 && NeedRead && User != 0)
{
// Генерируем csv
// В alfadirect4.ru/investor/X_USER.csv из ftp://ftp.moex.com/pub/info/stats_contest/2018/all/X_USER.zip
System.Net.WebClient wc = new System.Net.WebClient();
wc.Encoding = System.Text.Encoding.UTF8;
string result = wc.DownloadString("https://alfadirect4.ru/investor.php?user=" + Convert.ToString(User) + "&year=" + Convert.ToString(Year));
// читаем
System.Net.WebRequest req = System.Net.WebRequest.Create("https://alfadirect4.ru/investor/" + (Year != 2018 ? Convert.ToString(Year) + "/" : "") + Convert.ToString(Nom) + "_" + Convert.ToString(User) + ".csv");
System.Net.WebResponse resp = req.GetResponse();
System.IO.Stream stream = resp.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(stream);
string[] VS = I.VirtualSecurity.Split('=');
string Ticker = VS.Count() > 0 ? VS[0] : "";
string Market = VS.Count() > 1 ? VS[1] : "";
string mM = Market.Substring(Market.Length-3);
string S = "";
while ((S = sr.ReadLine()) != null)
{
string[] Data = S.Split(';');
string TickerData = Data[1].Trim();
string dT = TickerData.Substring(0, 3);
string dM = TickerData.Substring(TickerData.Length-3);
if (Ticker == TickerData || (dT == Ticker && dM == mM ))
if (Data.Count() >= 4)
{
var count = double.Parse(Data[2]);
C.Add(count);
Price.Add(double.Parse(Data[3].Replace(".",",")));
var D = DateTime.ParseExact(Data[0].Substring(0, 19), "yyyy-MM-dd HH:mm:ss", null);
DT.Add(D.ToBinary());
if (count < 0)
Type.Add(-1);
if (count > 0)
Type.Add(1);
}
}
NeedRead = false;
} // C == 0
for (var x = 0; x < C.Count; x++)
{
long b = Convert.ToInt64(DT[x]);
DateTime d = DateTime.FromBinary(b).Date;
TimeSpan t = DateTime.FromBinary(b).TimeOfDay;
if (BarDate(0) == d && BarDate(1) != d && BarTime(0) == AsTime(0,0,0) && BarTime(1) == AsTime(0,0,0))
{
if (Type[x] > 0) { Buy[0] = Price[x]; CountBuy[0] += C[x]; }
if (Type[x] < 0) { Sell[0] = Price[x]; CountSell[0] += C[x]; }
} else
if (BarDate(0) == d && t == BarTime(0))
{
if (Type[x] > 0) { Buy[0] = Price[x]; CountBuy[0] += C[x]; }
if (Type[x] < 0) { Sell[0] = Price[x]; CountSell[0] += C[x]; }
} else
if (
(BarDate(0) == d && t > BarTime(1) && t < BarTime(0))
||
(BarDate(1) == d && BarDate(0) > BarDate(1) && t > BarTime(1) && t > BarTime(0))
)
{
if (Type[x] > 0) { Buy[1] = Price[x]; CountBuy[1] += C[x]; }
if (Type[x] < 0) { Sell[1] = Price[x]; CountSell[1] += C[x]; }
}
}
Buy.DrawArrowUp();
Sell.DrawArrowDown();
CountBuy.DrawHistogram();
CountSell.DrawHistogram();
}