public void zSaveChart()
{
if(!zIsRealTime()) return; // Only save chart for real time trades
if(ChartControl == null) // Strategy is not attached to a chart
{
if(File.Exists(strategyPath + "\\image.png"))
return; // Default image already saved to strategy directory
else
{
string path = NinjaTrader.Core.Globals.UserDataDir + "\\bin\\Custom\\Strategies\\image.png";
if(File.Exists(path))
{
File.Copy(path,strategyPath + "\\image.png");
}
}
}
else
{
if (0 == Interlocked.Exchange(ref threadLock, 1)) //0 indicates that the method is not in use.
{
try
{
this.ChartControl.Dispatcher.InvokeAsync(() =>
{
NinjaTrader.Gui.Chart.Chart chart = Window.GetWindow(this.ChartControl) as NinjaTrader.Gui.Chart.Chart;
RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
System.Windows.Media.Imaging.BitmapFrame outputFrame = BitmapFrame.Create(screenCapture);
if (screenCapture != null)
{
try
{
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(outputFrame);
using (Stream stream = File.Create(string.Format(@"{0}\{1}", strategyPath, "image.png"))) png.Save(stream);
NinjaTrader.Code.Output.Process("Screenshot saved to " + strategyPath, PrintTo.OutputTab1);
}
catch (IOException)
{
NinjaTrader.Code.Output.Process("ScreenshotTakerExample: Could not take screenshot", PrintTo.OutputTab1);
}
}
});
}
catch (Exception ex)
{
NinjaTrader.Code.Output.Process("Could not save screenshot " + ex, PrintTo.OutputTab1);
}
Interlocked.Exchange(ref threadLock, 0); //Release the lock
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Saving image of minimized chart of running strategy
Collapse
X
-
Saving image of minimized chart of running strategy
I am trying to save the image of the chart in which my strategy is running. The code below works perfectly for saving the image of the currently displayed chart but I would like to save the image of a chart that is not in the forefront. I have several different strategies running and would like my strategy to save the current chart it is attached too, even if it is minimized. I assumed that using "this.ChartContol" would select the current chart that the strategy was attached too but it doesn't.
PHP Code:Tags: None
-
Hello cutzpr,
Thank you for your note.
There is no supported method for taking a screen shot of a minimized chart however I will submit a feature request for this.
I have attached a sample using a different approach and if the chart is minimized the saved imagine will be a chart window with no data displayed.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by trilliantrader, Yesterday, 03:01 PM
|
3 responses
30 views
0 likes
|
Last Post Today, 08:28 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
4 responses
26 views
0 likes
|
Last Post Today, 08:19 AM | ||
Started by Brevo, Today, 01:45 AM
|
1 response
14 views
0 likes
|
Last Post Today, 08:14 AM | ||
Started by rjbtrade1, 11-30-2023, 04:38 PM
|
2 responses
74 views
0 likes
|
Last Post
by DavidHP
Today, 08:12 AM
|
||
Started by suroot, 04-10-2017, 02:18 AM
|
5 responses
3,022 views
0 likes
|
Last Post Today, 08:11 AM |
Comment