проверил сжатые свечки - есть нюанс:
последняя свеча не участвует в сжатии по методу № 3.
// ******************************************************************
using System;
using System.IO; // для работы с файлами
using System.Collections.Generic;
using System.Linq;
using System.Net; // для ConnectionAvailable()
using System.Net.NetworkInformation; // для ConnectionAvailable()
using TSLab.DataSource;
using TSLab.Script;
using TSLab.Script.Handlers;
using TSLab.Script.Helpers;
using TSLab.Script.Optimization;
using TSLab.Script.Realtime;
namespace TSLab.Samples
{
public class zzz_20121030_Compress : IExternalScript
{
public OptimProperty sdvig_back = new OptimProperty(2, 1, 100, 1);
public void Execute(IContext ctx, ISecurity sec_01)
{
IList<double> Line_Up_15 = new List<double>(1);
IList<double> Line_Dn_15 = new List<double>(1);
#region вычислим сдвиг от начала стандартной 15-минутки
int New_TF = 15;
double shift = 0;
for (int sc = sec_01.Bars.Count-1; (0<sc); sc--)
{
double ost_del = Math.IEEERemainder((double)sec_01.Bars[sc].Date.Minute, (double)New_TF);
if (ost_del==0)
{
shift = (sec_01.Bars.Count-1) - sc;
//shift = (sec_01.Bars.Count-1) - sc;
break;
}
}
#endregion
// сжимаем минутки в 15-мин. со сдвигом
ISecurity sec_TF = sec_01.CompressTo(new Interval(15, DataIntervals.MINUTE), (int) shift);
#region покажем данные "последней-sdvig" свечи после сжатия
int last_bar = sec_TF.Bars.Count - 1;
int tst_bar = last_bar - sdvig_back;
ctx.Log("********************************************************",0);
ctx.Log("Shift=" + shift , 0);
ctx.Log("last_bar=" + last_bar , 0);
ctx.Log("sdvig_back=" + sdvig_back , 0);
ctx.Log("tst_bar=" + tst_bar , 0);
ctx.Log("Time=" + sec_TF.Bars[tst_bar].Date , 0);
ctx.Log("Open=" + sec_TF.OpenPrices[tst_bar] , 0);
ctx.Log("High=" + sec_TF.HighPrices[tst_bar] , 0);
ctx.Log("Low=" + sec_TF.LowPrices[tst_bar] , 0);
ctx.Log("Close=" + sec_TF.ClosePrices[tst_bar] , 0);
ctx.Log("********************************************************",0);
#endregion
#region обрисовываем интересующую нас сжатую свечу
double Time_TF_Start = ((sec_TF.Bars[tst_bar ].Date.DayOfYear*100 + sec_TF.Bars[tst_bar ].Date.Hour) * 100 + sec_TF.Bars[tst_bar ].Date.Minute) * 100 + sec_TF.Bars[tst_bar ].Date.Second;
double Time_TF_Finish = ((sec_TF.Bars[tst_bar+1].Date.DayOfYear*100 + sec_TF.Bars[tst_bar+1].Date.Hour) * 100 + sec_TF.Bars[tst_bar+1].Date.Minute) * 100 + sec_TF.Bars[tst_bar+1].Date.Second;
for (int i = 0; (i < sec_01.Bars.Count); i++)
{
int ind = i;
double Time_01 = ((sec_01.Bars[ ind ].Date.DayOfYear*100 + sec_01.Bars[ ind ].Date.Hour) * 100 + sec_01.Bars[ ind ].Date.Minute) * 100 + sec_01.Bars[ ind ].Date.Second;
if ( (Time_TF_Start <= Time_01) && (Time_01 < Time_TF_Finish) )
{
Line_Up_15.Add( sec_TF.HighPrices[tst_bar] );
Line_Dn_15.Add( sec_TF.LowPrices[tst_bar] );
}
else
{
Line_Up_15.Add(0);
Line_Dn_15.Add(0);
}
}
IPane mainPane = ctx.First;
mainPane.AddList(string.Format("LU-15"), Line_Up_15, ListStyles.LINE_BW_POINTS, 0xFF00FF, LineStyles.SOLID, PaneSides.RIGHT);
mainPane.AddList(string.Format("LD-15"), Line_Dn_15, ListStyles.LINE_BW_POINTS, 0xFF00FF, LineStyles.SOLID, PaneSides.RIGHT);
#endregion
} // Execute
} // конец скрипта
} // TSLab.Samples
// ******************************************************************
Attachments
qwe.JPG (237 downloads)
Отредактировано yan (Thu Nov 01 2012 09:40 PM)