I have a method that works via a mouse click. However it ONLY produces text the second time I use it - the first time i get everything except the text. First time I run through it I get no text printed. I get the lines but no text. When I debug and print the text there are no errors and the text strings are valid and complete???
I am at a complete loss with this one. I have tried try/catch and i get no captures.
#region DrawMaxExcursions
void DrawMaxExcursions(ChartScale chartScale, float labelStartX)
{
try
{
if (myEntry == 0 || TickSize <= 0 )
return;
void DrawSingleExcursion(double excursionTicks, double excursionPrice, SharpDX.Direct2D1.Brush brush)
{
if (excursionTicks == 0)
return;
float y = chartScale.GetYByValue(excursionPrice);
float offsetX = labelStartX - labelOffsetX;
double rValue = (excursionTicks * TickSize) / R;
string line1 = $"{rValue:0.0R}"; // R-multiple
string line2 = $"{excursionTicks:0}"; // Ticks
var fontCollection = Globals.DirectWriteFactory.GetSystemFontCollection(false);
using var textFormat = new SharpDX.DirectWrite.TextFormat(
Globals.DirectWriteFactory,
"Segoe UI",
fontCollection,
SharpDX.DirectWrite.FontWeight.Normal,
SharpDX.DirectWrite.FontStyle.Normal,
SharpDX.DirectWrite.FontStretch.Normal,
12f,
"en-us");
using var layout1 = new SharpDX.DirectWrite.TextLayout(Globals.DirectWriteFactory, line1, textFormat, 100f, 20f);
using var layout2 = new SharpDX.DirectWrite.TextLayout(Globals.DirectWriteFactory, line2, textFormat, 100f, 20f);
// Y-positions
float line1Y = y - layout1.Metrics.Height;
float line2Y = y + 2f; // Slight padding between lines
// X-centering
float line1X = offsetX;
float line2X = offsetX + (layout1.Metrics.Width - layout2.Metrics.Width) / 2f;
Print("Line 1 = "+line1);
Print("Line2 = "+line2);
RenderTarget.DrawTextLayout(new SharpDX.Vector2(line1X, line1Y), layout1, brush);
RenderTarget.DrawTextLayout(new SharpDX.Vector2(line2X, line2Y), layout2, brush);
RenderTarget.DrawLine(
new SharpDX.Vector2(singleTickStart - labelOffsetX, y),
new SharpDX.Vector2(singleTickEnd - labelOffsetX, y),
brush,
5f);
}
using var brushGold = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget,SharpDX.Color.Gold);
using var brushPink = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget,SharpDX.Color.HotPink);
// Draw MFE (Gold) and MAE (Fuchsia)
DrawSingleExcursion(myExcursion.MaxMFE, myExcursion.BestPriceReached, brushGold);
DrawSingleExcursion(myExcursion.MaxMAE, myExcursion.WorstPriceReached, brushPink);
}
catch (Exception ex)
{
Print($"[Exception] {ex.Message}\n{ex.StackTrace}");
}
}
#endregion