retesere20

sample nt button indi

Mar 1st, 2020 (edited)
134
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #region Using declarations
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Xml.Serialization;
  13. using NinjaTrader.Cbi;
  14. using NinjaTrader.Gui;
  15. using NinjaTrader.Gui.Chart;
  16. using NinjaTrader.Gui.SuperDom;
  17. using NinjaTrader.Gui.Tools;
  18. using NinjaTrader.Data;
  19. using NinjaTrader.NinjaScript;
  20. using NinjaTrader.Core.FloatingPoint;
  21. using NinjaTrader.NinjaScript.DrawingTools;
  22. #endregion
  23.  
  24. //This namespace holds Indicators in this folder and is required. Do not change it.
  25. namespace NinjaTrader.NinjaScript.Indicators.customs
  26. {
  27. public class SampleButton_Indicator: Indicator
  28. {
  29. protected override void OnStateChange()
  30. {
  31. if (State == State.SetDefaults)
  32. {
  33. Description = @"Enter the description for your new custom Indicator here.";
  34. Name = "SampleButton_Indicator";
  35. Calculate = Calculate.OnEachTick;
  36. IsOverlay = false;
  37. DisplayInDataBox = true;
  38. DrawOnPricePanel = true;
  39. DrawHorizontalGridLines = true;
  40. DrawVerticalGridLines = true;
  41. PaintPriceMarkers = true;
  42. ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
  43. //Disable this property if your indicator requires custom values that cumulate with each new market data event.
  44. //See Help Guide for additional information.
  45. IsSuspendedWhileInactive = true;
  46. //
  47. AddPlot(Brushes.Orange, "a1");
  48. }
  49. else if (State == State.Configure)
  50. {
  51. }
  52. else if (State == State.DataLoaded)
  53. {
  54. }
  55. }
  56.  
  57. bool flag;
  58. protected override void OnBarUpdate()
  59. {
  60. try
  61. {
  62. if (!flag)
  63. {
  64. flag = true;
  65. ChartControl.Dispatcher.InvokeAsync(() =>
  66. {
  67. initialize_createGrid();
  68. });
  69. }
  70. }
  71. catch(Exception e)
  72. {
  73. Print(e.ToString());
  74. }
  75. }
  76.  
  77.  
  78.  
  79.  
  80. private System.Windows.Controls.Grid myGrid;
  81. private void initialize_createGrid()
  82. {
  83. try
  84. {
  85. myGrid = new System.Windows.Controls.Grid
  86. {
  87. Name = "MyCustomGrdaid32" + DateTime.Now.ToString("Hms"),
  88. HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
  89. VerticalAlignment = System.Windows.VerticalAlignment.Top
  90. };
  91. int i = -1;
  92.  
  93. System.Windows.Controls.ColumnDefinition column1 = new System.Windows.Controls.ColumnDefinition();
  94. myGrid.ColumnDefinitions.Add(column1);
  95. System.Windows.Controls.ColumnDefinition column2 = new System.Windows.Controls.ColumnDefinition();
  96. myGrid.ColumnDefinitions.Add(column2);
  97. //
  98.  
  99. // ======= WPF TEXTBOX
  100. Brush br = DateTime.Now.Second % 2 == 1 ? Brushes.Green : Brushes.Red;
  101. var newControl = new System.Windows.Controls.TextBox { Name = "asd", Text ="WPF textbox", Width = 100, Background = Brushes.Yellow };
  102. myGrid.Children.Add(newControl);
  103. i++;
  104. System.Windows.Controls.Grid.SetColumn((UIElement)newControl, i);
  105. //################
  106.  
  107. if (!this.UserControlCollection.Contains(myGrid))
  108. {
  109. this.UserControlCollection.Add(myGrid);
  110. }
  111. }
  112. catch (Exception e)
  113. {
  114. Print(e.ToString());
  115. }
  116. }
  117.  
  118. }
  119. }
RAW Paste Data