Move current time/bar of the chart in code
Move current time/bar of the chart in code
29 Oct 2024, 23:10
Hello,
Is there a way to bring the current time/ current bar to the middle of the chart in code?
Whatever I do with ScrollXTo, pictures are always
I'm trying to take chartshots in code.. Manually you can move where the timer of the bar is but that's not the idea to move it manually..
The idea is to have some blank space on the right side…
public void TakeChartShots(Symbol symbol)
{
try
{
var basePath = "ChartShots";
var dateFolder = DateTime.Now.ToString("dd_MM_yyyy");
var timeFolder = DateTime.Now.ToString("HH_mm");
var symbolFolder = Path.Combine(basePath, symbol.Name);
var closingFolder = Path.Combine(symbolFolder, "closing");
var dateFolderPath = Path.Combine(closingFolder, dateFolder);
var timeFolderPath = Path.Combine(dateFolderPath, timeFolder);
Directory.CreateDirectory(timeFolderPath);
var timeFrames = new[] { TimeFrame.Hour, TimeFrame.Hour4, TimeFrame.Daily };
var newChartFrame = tms.ChartManager.AddChartFrame(symbol.Name, timeFrames[0]);
newChartFrame.Detach();
newChartFrame.ChartContainer.DetachedWindow.Width = 1920;
newChartFrame.ChartContainer.DetachedWindow.Height = 1080;
var chart = newChartFrame.Chart;
Thread.Sleep(5000);
foreach (var timeFrame in timeFrames)
{
var chartshot = newChartFrame.Chart.TakeChartshot();
if (chartshot != null)
{
var fileName = $"chartshot_{timeFrame}.png";
var filePath = Path.Combine(timeFolderPath, fileName);
File.WriteAllBytes(filePath, chartshot);
}
newChartFrame.TimeFrame = timeFrame;
Thread.Sleep(5000);
}
newChartFrame.ChartContainer.Close();
}
catch (Exception ex)
{
tms.Print($"[Error] Exception in TakeChartShots: {ex.Message}");
}
}
Replies
TommyFFX
30 Oct 2024, 16:16
( Updated at: 31 Oct 2024, 08:31 )
RE: Move current time/bar of the chart in code
PanagiotisCharalampous said:
Hi there,
There is no ScrollXto in your code. Can you share the full source code please?
Best regards,
Panagiotis
using cAlgo.API;
using cAlgo.API.Internals;
using System;
using System.IO;
namespace cAlgo.Plugins
{
[Plugin(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ChartShotPluginExample : Plugin
{
private ChartFrame newChartFrame;
protected override void OnStart()
{
Positions.Closed += OnPositionClosed;
}
public void OnPositionClosed(PositionClosedEventArgs args)
{
TakeChartShots(args.Position.Symbol);
}
public void TakeChartShots(Symbol symbol)
{
try
{
newChartFrame = ChartManager.AddChartFrame(symbol.Name, TimeFrame.Hour);
newChartFrame.Detach();
newChartFrame.ChartContainer.DetachedWindow.Width = 1920;
newChartFrame.ChartContainer.DetachedWindow.Height = 1080;
var chart = newChartFrame.Chart;
chart.ScrollXTo(Server.Time.AddDays(10));
Timer.Start(TimeSpan.FromSeconds(5));
}
catch (Exception ex)
{
Print($"[Error] Exception in TakeChartShots: {ex.Message}");
}
}
protected override void OnTimer()
{
if (newChartFrame != null)
{
ChartShot(newChartFrame.Chart);
newChartFrame.ChartContainer.Close();
}
}
protected void ChartShot(Chart chart)
{
var basePath = "ChartShots";
Directory.CreateDirectory(basePath);
var fileName = $"chartshot_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png";
var filePath = Path.Combine(basePath, fileName);
var chartshot = chart.TakeChartshot();
if (chartshot != null)
File.WriteAllBytes(filePath, chartshot);
Timer.Stop();
}
}
}
I'm working on a large plugin Project, I minimized the code plugin to resolve my problem.
So we can not scroll to the future ?
Having some blank space on the right side like in this picture..
Thanks in advance..
Can we not move this in code ?
@TommyFFX
TommyFFX
31 Oct 2024, 10:04
( Updated at: 31 Oct 2024, 12:22 )
RE: RE: Move current time/bar of the chart in code
Even templates won't remember the positon..
I guess we are always fixed to the extreme right side right ?
And only have a manual ability to repeatedly adjust it..
Otherwise
Any solutions are welcome
Thanks
TommyFFX
TommyFFX said:
PanagiotisCharalampous said:
Hi there,
There is no ScrollXto in your code. Can you share the full source code please?
Best regards,
Panagiotis
using cAlgo.API;using cAlgo.API.Internals;
using System;
using System.IO;
namespace cAlgo.Plugins
{
[Plugin(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ChartShotPluginExample : Plugin
{
private ChartFrame newChartFrame;
protected override void OnStart()
{
Positions.Closed += OnPositionClosed;
}
public void OnPositionClosed(PositionClosedEventArgs args)
{
TakeChartShots(args.Position.Symbol);
}
public void TakeChartShots(Symbol symbol)
{
try
{
newChartFrame = ChartManager.AddChartFrame(symbol.Name, TimeFrame.Hour);
newChartFrame.Detach();
newChartFrame.ChartContainer.DetachedWindow.Width = 1920;
newChartFrame.ChartContainer.DetachedWindow.Height = 1080;
var chart = newChartFrame.Chart;
chart.ScrollXTo(Server.Time.AddDays(10));
Timer.Start(TimeSpan.FromSeconds(5));
}
catch (Exception ex)
{
Print($"[Error] Exception in TakeChartShots: {ex.Message}");
}
}
protected override void OnTimer()
{
if (newChartFrame != null)
{
ChartShot(newChartFrame.Chart);
newChartFrame.ChartContainer.Close();
}
}
protected void ChartShot(Chart chart)
{
var basePath = "ChartShots";
Directory.CreateDirectory(basePath);
var fileName = $"chartshot_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png";
var filePath = Path.Combine(basePath, fileName);
var chartshot = chart.TakeChartshot();
if (chartshot != null)
File.WriteAllBytes(filePath, chartshot);
Timer.Stop();
}
}
}
I'm working on a large plugin Project, I minimized the code plugin to resolve my problem.
So we can not scroll to the future ?
Having some blank space on the right side like in this picture..
Thanks in advance..
Can we not move this in code ?
@TommyFFX
PanagiotisCharalampous
31 Oct 2024, 12:36
Hi there,
Unfortunately it is not possible to use ScrollXTo() to move the chart to the future.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
30 Oct 2024, 09:54
Hi there,
There is no ScrollXto in your code. Can you share the full source code please?
Best regards,
Panagiotis
@PanagiotisCharalampous