- ago
Here's a screenshot of the Update Log window I took today after updating:


The text meanders all over the place. The main/sole culprit in this case is the first column 'Symbols' which can vary in length from 1 to over 15 (some WealthData symbols, Option contracts).

Fortunately, there's an easy fix for this in .NET: The PadRight method.
https://learn.microsoft.com/en-us/dotnet/api/system.string.padright?view=net-9.0

To illustrate how I used it to fix the same issue in my coded strategies:
CODE:
//WriteToDebugLog(List[a].sym ...

CODE:
WriteToDebugLog(List[a].sym.PadRight(6) ...

Works like a charm.

Helpful tips:
- a value of 20 for PadRight is suggested for Update Log, 25 will make it more future-proof for whatever comes down the road in the foreseeable future
- PadRight can be used in any string column, as needed
- can be implemented elsewhere in the program, as needed, for outputting text that looks prettier and professional


You're welcome.
0
103
2 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.02% )
- ago
#1
Nice find with PadRight 👍
1
Cone8
 ( 9.83% )
- ago
#2
For even simpler column control for non-proportional text, just specify the column width, negative/positive for left/right alignment.

CODE:
public override void Initialize(BarHistory bars) {          string s = $"|{bars.Symbol,-10}|{bars.Symbol,10}|{bars.LastValue.ToString("N3"),20}|{bars.Count,-12}|";          WriteToDebugLog(s, false);          }


Result:
CODE:
---Sequential Debug Log--- |WMT | WMT| 97.270|623 | |CSCO | CSCO| 68.650|623 | |NKE | NKE| 72.040|623 | |BA | BA| 214.550|623 | |MMM | MMM| 152.020|623 | |KO | KO| 70.330|623 | |AXP | AXP| 317.190|623 | |AAPL | AAPL| 201.080|623 | |VZ | VZ| 42.310|623 | |HD | HD| 368.740|623 | |CVX | CVX| 143.790|623 | |IBM | IBM| 289.700|623 | |PG | PG| 159.860|623 | |JNJ | JNJ| 152.410|623 | |V | V| 348.610|623 | |TRV | TRV| 263.310|623 | |DOW | DOW| 48.900|466 | |MRK | MRK| 79.100|623 | |MCD | MCD| 291.550|623 | |CAT | CAT| 384.710|623 | |INTC | INTC| 26.230|466 | |JPM | JPM| 287.110|623 | |SHW | SHW| 345.720|410 | |MSFT | MSFT| 495.940|623 | |WBA | WBA| 11.450|623 | |GS | GS| 690.810|623 | |UNH | UNH| 309.110|623 | |HON | HON| 228.850|623 | |CRM | CRM| 273.420|623 | |NVDA | NVDA| 157.750|410 | |AMGN | AMGN| 277.130|623 | |DIS | DIS| 122.340|623 |
2

Reply

Bookmark

Sort