retesere20

nt8-debugger-drawtimings-alternative-approach

Aug 16th, 2019
116
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void draw(string additionalText)
  2. {
  3. //stop();
  4. string txt_ =
  5. string.Format(NSB_.Name + "| {0} (cycle: {1}): {2} [seconds of total: {3} from period {4}]{5}", funcName_, count, diffAmount.ToString("0.#######"), totalDiffAmount.ToString("0.#######"), totalGone.ToString("0.#######"), (additionalText == "" ? "" : " (" + additionalText.ToString() + ")"));
  6.  
  7. NinjaTrader.NinjaScript.DrawingTools.Draw.TextFixed(NSB_, "stopWatch_" + NSB_.Name + funcName_,
  8. txt_,
  9. TextPosition.TopLeft,
  10. Brushes.Gray,
  11. font_,
  12. Brushes.Transparent,
  13. Brushes.Transparent, 0
  14. ).YPixelOffset = -(int)(font_.Size * offset_ + font_.Size * 4 * (DebugNumber_ - 1));
  15.  
  16. // drawTextFixed_Render_static(txt_, 50, 50, Brushes.Yellow, this);
  17. //print_(DateTime.Now.ToString() + " ____" + txt_);
  18. (NSB_ as NinjaTrader.Gui.NinjaScript.IndicatorRenderBase).ForceRefresh();
  19. /*
  20. if (!stopWatchTextAll.ContainsKey(NSB_.Name))
  21. stopWatchTextAll[NSB_.Name] = new Dictionary<string, string>();
  22.  
  23. stopWatchTextAll[NSB_.Name][funcName_] = txt_;
  24. drawThem(NSB_, offset_, DebugNumber_);
  25. */
  26. }
  27.  
  28. private static Dictionary<string, Dictionary<string, string>> stopWatchTextAll = new Dictionary<string, Dictionary<string, string>>();
  29.  
  30. /*
  31. private static void drawThem(NinjaTrader.NinjaScript.NinjaScriptBase NSB_, int offset_, int offsetDebugNumber)
  32. {
  33. string finalStr = "";
  34. foreach (var kvp1 in stopWatchTextAll)
  35. {
  36. string nsb_name = kvp1.Key;
  37. foreach (var kvp2 in stopWatchTextAll[nsb_name])
  38. {
  39. string func_name_ = kvp2.Key;
  40. finalStr += stopWatchTextAll[nsb_name][func_name_] + nl;
  41. }
  42. }
  43.  
  44. NinjaTrader.NinjaScript.DrawingTools.Draw.TextFixed(NSB_, "stopWatch_" + NSB_.Name,
  45. finalStr,
  46. TextPosition.BottomLeft,
  47. Brushes.Gray,
  48. font_,
  49. Brushes.Transparent,
  50. Brushes.Transparent, 0
  51. ).YPixelOffset = (int)(font_.Size * offset_ + font_.Size * 4 * (offsetDebugNumber - 1));
  52.  
  53. // drawTextFixed_Render_static(txt_, 50, 50, Brushes.Yellow, this);
  54. print_(DateTime.Now.ToString() + " ____" + finalStr);
  55. (NSB_ as NinjaTrader.Gui.NinjaScript.IndicatorRenderBase).ForceRefresh();
  56. }
  57. */
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /*
  70. public static void drawTextFixed_Render_static(object obj, int barX, int barY, Brush BrushCol, object indi_strat)
  71. {
  72. NinjaTrader.NinjaScript.Indicators.Indicator indi = null;
  73. NinjaTrader.NinjaScript.Strategies.Strategy strat = null;
  74.  
  75. ChartBars chartBars = null;
  76. Bars bars = null;
  77. ChartControl chartControl = null;
  78. SharpDX.Direct2D1.RenderTarget renderTarget = null;
  79. NinjaTrader.Gui.Chart.ChartScale chartScale = null;
  80.  
  81. if (indi_strat is NinjaTrader.NinjaScript.Indicators.Indicator)
  82. {
  83. indi = indi_strat as NinjaTrader.NinjaScript.Indicators.Indicator;
  84. chartBars = indi.ChartBars;
  85. bars = indi.Bars;
  86. chartControl = indi.ChartControl;
  87. renderTarget = indi.RenderTarget;
  88. chartScale = new NinjaTrader.Gui.Chart.ChartScale(indi.ChartPanel, ScaleJustification.Overlay);
  89. }
  90. else if (indi_strat is NinjaTrader.NinjaScript.Strategies.Strategy)
  91. {
  92. strat = indi_strat as NinjaTrader.NinjaScript.Strategies.Strategy;
  93. chartBars = strat.ChartBars;
  94. bars = strat.Bars;
  95. chartControl = strat.ChartControl;
  96. renderTarget = strat.RenderTarget;
  97. chartScale = new NinjaTrader.Gui.Chart.ChartScale(strat.ChartPanel, ScaleJustification.Overlay);
  98. }
  99.  
  100.  
  101. SharpDX.DirectWrite.TextFormat format1 = new SharpDX.DirectWrite.TextFormat(
  102. new SharpDX.DirectWrite.Factory(),
  103. new NinjaTrader.Gui.Tools.SimpleFont("Consolas", 9).Family.ToString(),
  104. SharpDX.DirectWrite.FontWeight.Normal,
  105. SharpDX.DirectWrite.FontStyle.Normal,
  106. 11
  107. );
  108. //format1.WordWrapping = WordWrapping.NoWrap;
  109. //format1.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Center;
  110.  
  111. SharpDX.RectangleF tmpRect = new SharpDX.RectangleF(barX - (int)(chartControl.BarWidth / 1.1), barY, (float)chartControl.BarWidth * 2.0f, 30);
  112. renderTarget.DrawText(obj.ToString(), format1, tmpRect, BrushCol.ToDxBrush(renderTarget));
  113. }
  114. */
RAW Paste Data