Message
Message
namespace NinjaTrader.NinjaScript.Indicators
{
[TypeConverter("NinjaTrader.NinjaScript.Indicators.CustomDrawingToolIndicatorTypeCo
nverter")]
public class PATSToolBar : Indicator
{
private const string assembly = "NinjaTrader.Custom";
//private const string assembly = "Toolbar";
private List<object> toolBarItems;
private bool isToolBarAdded;
private ArrowIconStyleEnum arrowIconStyle =
ArrowIconStyleEnum.ColorFilled;
private NinjaTrader.Gui.Chart.Chart cw; //chartWindow
private System.Windows.Forms.Timer myTimer;
private ATR myATR;
private string path = NinjaTrader.Core.Globals.UserDataDir + @"bin\
Custom\DrawingTools\notes.txt";
private StreamReader sr;
private Style systemMenuStyle =
Application.Current.TryFindResource("SystemMenuStyle") as Style;
private Style mainMenuItem =
Application.Current.TryFindResource("MainMenuItem") as Style;
private Brush textBrush =
Application.Current.FindResource("FontActionBrush") as Brush ?? Brushes.Blue;
private Label atrLabel, lagLabel;
private double lastPrice;
private InputSimulator inputSimulator;
private bool simulatingPanning;
private TimeZoneInfo marketTimeZone;
if (ShowNote)
{
Menu theMenu = new Menu { VerticalAlignment =
VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Bottom,
mainMenuItem, "Note");
topMenuItem.Margin = new Thickness(-4, 0, 0, 0);
NTMenuItem textItem =
createNTMenuItem(NinjaTrader.Gui.Tools.Icons.DrawText, "Note", mainMenuItem, null);
textItem.Click += (o, args) => drawNote("");
topMenuItem.Items.Add(textItem);
if (!File.Exists(path))
{
foreach (string s in new[] { "2EL", "2ES", "F2EL",
"F2ES"})
{
NTMenuItem subItem = createNTMenuItem(null, s,
mainMenuItem, null);
subItem.Click += (o, args) => drawNote(s);
topMenuItem.Items.Add(subItem);
}
}
else
{
try
{
sr = new System.IO.StreamReader(path);
string line;
while ((line = sr.ReadLine()) != null)
{
string trimmed = line.Trim();
if (trimmed.Length == 0) continue;
NTMenuItem subItem =
createNTMenuItem(null, trimmed, mainMenuItem, null);
subItem.Click += (o, args) =>
drawNote(trimmed);
topMenuItem.Items.Add(subItem);
}
sr.Dispose(); sr = null;
}
catch (Exception e)
{
Log("You cannot write and read from the same
file at the same time.", NinjaTrader.Cbi.LogLevel.Error);
}
}
theMenu.Items.Add(topMenuItem);
toolBarItems.Add(theMenu);
}
if (ShowPlotExecutions)
{
Grid icon = new Grid { Height = 16, Width = 16 };
System.Windows.Shapes.Path p = new
System.Windows.Shapes.Path();
p.Fill = textBrush;
p.Data = System.Windows.Media.Geometry.Parse("M 6 1 L 6 15
L 7 15 L 7 1 Z M 6 1 L 10 1 L 10 2 L 6 2 Z M 10 1 L 10 15 L 9 15 L 9 1 Z M 6 15 L
10 15 L 10 14 L 6 14 Z M 2 8 L 5 11 L 2 14 Z M 14 2 L 11 5 L 14 8 Z");
icon.Children.Add(p);
Button b = createButton("Plot Executions", icon, style,
fontFamily);
b.Click += (o, args) =>
System.Windows.Forms.SendKeys.SendWait("^e");
toolBarItems.Add(b);
}
if (ShowDrawnObjects)
{
Button b = createButton("Hide Drawings",
getToggleDrawingsIcon(true), style, fontFamily);
b.Click += (o, args) => {
Button bb = o as Button;
bb.ToolTip = bb.ToolTip == "Hide Drawings" ? "Show
Drawings" : "Hide Drawings";
bb.Content = getToggleDrawingsIcon(bb.ToolTip ==
"Hide Drawings");
foreach (var obj in
cw.ActiveChartControl.ChartObjects)
{
var draw = obj as
NinjaTrader.NinjaScript.DrawingTools.DrawingTool;
if (draw == null || !draw.IsUserDrawn)
continue;
draw.IsVisible = !draw.IsVisible;
}
ForceRefresh();
};
toolBarItems.Add(b);
}
if (ShowRemoveAll)
{
NTMenuItem ntDrawingTools = ((Menu)cw.MainMenu[3]).Items[0]
as NTMenuItem;
foreach (var item in ntDrawingTools.Items)
{
if (item is NTMenuItem && ((NTMenuItem)item).Header !
= null)
{
NTMenuItem mnItem = item as NTMenuItem;
if (mnItem.Header.ToString() == "Remove All
Drawing Objects")
{
Button b = createButton(mnItem.Header,
mnItem.Icon, style, fontFamily);
b.Click += (o, args) =>
mnItem.Command.Execute(o);
toolBarItems.Add(b);
}
}
}
}
if (ShowHelp)
{
Menu helpMenu = new Menu { VerticalAlignment =
VerticalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Bottom,
Style = systemMenuStyle };
NTMenuItem helpMenuItem = createNTMenuItem("?", null,
mainMenuItem, "Help");
helpMenuItem.Margin = new Thickness(-4, 0, 0, 0);
NTMenuItem helpLinkItem = createNTMenuItem(null, "Help",
mainMenuItem, null);
NTMenuItem tipLinkItem = createNTMenuItem(null, "Tip Me ♡",
mainMenuItem, null);
NTMenuItem aboutItem = createNTMenuItem(null, "About",
mainMenuItem, null);
helpMenuItem.Items.Add(helpLinkItem);
helpMenuItem.Items.Add(tipLinkItem);
helpMenuItem.Items.Add(aboutItem);
helpMenu.Items.Add(helpMenuItem);
tipLinkItem.Click += ((o, args) => {
try {
System.Diagnostics.Process.Start("https://paypal.me/faurebastien"); }
catch (System.Exception e)
{ MessageBox.Show(e.Message); }
});
helpLinkItem.Click += ((o, args) => {
try {
System.Diagnostics.Process.Start("https://www.notion.so/bastienfaure/PATS-ToolBar-
57fcbaa98c46477ba7bcd801f4356e60"); }
catch (System.Exception e)
{ MessageBox.Show(e.Message); }
});
aboutItem.Click += (o, args) =>
Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => new
AboutWindow().Show()));
toolBarItems.Add(helpMenu);
}
if (ShowClock)
{
myTimer = new System.Windows.Forms.Timer();
myTimer.Interval = 1000;
myTimer.Enabled = true;
Label clockLabel = createLabel(ShowMarketTimeZone ?
TimeZoneInfo.ConvertTime(Core.Globals.Now, marketTimeZone).ToString() :
Core.Globals.Now.ToString());
toolBarItems.Add(clockLabel);
myTimer.Tick += new EventHandler((o, args) =>
clockLabel.Content = ShowMarketTimeZone ?
TimeZoneInfo.ConvertTime(Core.Globals.Now, marketTimeZone).ToString() :
Core.Globals.Now.ToString());
}
ShowHideToolBar(TabSelected());
cw.MainTabControl.SelectionChanged += TabChangedHandler;
}
#region Properties
[Browsable(false)]
public string Annotation { get; set; }
[Range(1, 1000)]
[Display(Name = "Left Margin", Description = "Empty space before first
drawing button", GroupName = "0. General Settings", Order = 0)]
public int LeftMargin { get; set; }
[RefreshProperties(RefreshProperties.All)]
[Display(Name = "ATR", Description = "Display ATR value", GroupName =
"2. Labels", Order = 1)]
public bool ShowATR { get; set; }
[Range(1, 1000)]
[Display(Name = "ATR Period", Description = "Set ATR period", GroupName
= "2. Labels", Order = 2)]
public int ATRPeriod { get; set; }
[Range(0, 100)]
[Display(Name = "Lag Warning Threshold", Description = "Lag warning
threshold in seconds", GroupName = "2. Labels", Order = 5)]
public double LagWarning
{ get; set; }
[Range(0, 100)]
[Display(Name = "Lag Alert Threshold", Description = "Lag alert threshold
in seconds", GroupName = "2. Labels", Order = 6)]
public double LagAlert
{ get; set; }
if (pd.Name == "SelectedTypes")
{
int i = 1;
foreach (Type type in
Core.Globals.AssemblyRegistry.GetDerivedTypes(typeof(DrawingTools.DrawingTool)))
{
DrawingTools.DrawingTool tool =
type.Assembly.CreateInstance(type.FullName) as DrawingTools.DrawingTool;
if (tool == null || !tool.DisplayOnChartsMenus)
continue;
CustomDrawingToolPropertyDescriptor descriptor
= new CustomDrawingToolPropertyDescriptor(type, tool.Name, i);
properties.Add(descriptor);
i++;
}
continue;
}
properties.Add(pd);
}
return properties;
}
}
}
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator :
NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private PATSToolBar[] cachePATSToolBar;
public PATSToolBar PATSToolBar()
{
return PATSToolBar(Input);
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.PATSToolBar PATSToolBar()
{
return indicator.PATSToolBar(Input);
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy :
NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.PATSToolBar PATSToolBar()
{
return indicator.PATSToolBar(Input);
}
#endregion