retesere20

--nt dynamic property example

Jun 11th, 2019
314
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
  26. {
  27. public class BasicModifyPropertyAttribute : Indicator
  28. {
  29. private bool disableTestProperty;
  30.  
  31. protected override void OnStateChange()
  32. {
  33. if (State == State.SetDefaults)
  34. {
  35. Description = @"Example of how to dynamically change the read-only attribute for properties.";
  36. Name = "BasicModifyPropertyAttribute";
  37. Calculate = Calculate.OnBarClose;
  38. IsOverlay = false;
  39. DisplayInDataBox = true;
  40. DrawOnPricePanel = true;
  41. DrawHorizontalGridLines = true;
  42. DrawVerticalGridLines = true;
  43. PaintPriceMarkers = true;
  44. ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
  45. IsSuspendedWhileInactive = true;
  46.  
  47. DisableTestProperty = false;
  48. }
  49. }
  50.  
  51. protected override void OnBarUpdate()
  52. {
  53. //Add your custom indicator logic here.
  54. }
  55.  
  56. [RefreshProperties(RefreshProperties.All)]
  57. [Display(Name = "DisableTestProperty", GroupName = "1. Settings", Order = 0)]
  58. public bool DisableTestProperty
  59. {
  60. get { return disableTestProperty; }
  61. set
  62. {
  63. disableTestProperty = value;
  64.  
  65. BrowsableAttribute theDescriptorBrowsableAttribute = TypeDescriptor.GetProperties(this.GetType())["TestProperty"].Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
  66. System.Reflection.FieldInfo isBrowsable = theDescriptorBrowsableAttribute.GetType().GetField("Browsable", System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  67. isBrowsable.SetValue(theDescriptorBrowsableAttribute, value);
  68. }
  69. }
  70.  
  71. [ReadOnly(false)]
  72. [Browsable(true)]
  73. [Display(Name = "TestProperty", GroupName = "1. Settings", Order = 1)]
  74. public string TestProperty { get; set; }
  75. }
  76. }
RAW Paste Data