-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyScreenTaker.cs
151 lines (131 loc) · 4.49 KB
/
MyScreenTaker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
/////////////////////////
using System.IO;
using System.Windows.Media.Imaging;
/////////////////////////
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Core;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class MyScreenTaker : Indicator
{
NinjaTrader.Gui.Chart.Chart chart;
bool takeShot = true;
BitmapFrame outputFrame;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MyScreenTaker";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
Dispatcher.BeginInvoke(new Action(() =>
{
chart = Window.GetWindow(ChartControl) as Chart;
}));
}
}
protected override void OnBarUpdate()
{
Dispatcher.BeginInvoke(new Action(() =>
{
if (chart != null && takeShot == true)
{
RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
outputFrame = BitmapFrame.Create(screenCapture);
if (screenCapture != null)
{
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(outputFrame);
using (Stream stream = File.Create(string.Format(@"{0}\{1}", Core.Globals.UserDataDir, "MyScreenshot.png")))
png.Save(stream);
Print("Screenshot saved to " + Core.Globals.UserDataDir);
takeShot = false;
}
}
}));
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MyScreenTaker[] cacheMyScreenTaker;
public MyScreenTaker MyScreenTaker()
{
return MyScreenTaker(Input);
}
public MyScreenTaker MyScreenTaker(ISeries<double> input)
{
if (cacheMyScreenTaker != null)
for (int idx = 0; idx < cacheMyScreenTaker.Length; idx++)
if (cacheMyScreenTaker[idx] != null && cacheMyScreenTaker[idx].EqualsInput(input))
return cacheMyScreenTaker[idx];
return CacheIndicator<MyScreenTaker>(new MyScreenTaker(), input, ref cacheMyScreenTaker);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MyScreenTaker MyScreenTaker()
{
return indicator.MyScreenTaker(Input);
}
public Indicators.MyScreenTaker MyScreenTaker(ISeries<double> input )
{
return indicator.MyScreenTaker(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MyScreenTaker MyScreenTaker()
{
return indicator.MyScreenTaker(Input);
}
public Indicators.MyScreenTaker MyScreenTaker(ISeries<double> input )
{
return indicator.MyScreenTaker(input);
}
}
}
#endregion