Thank you very much! As always you are a life saver. Adding _TRACEF function was a huge help but I'm still trying to get data to show up on trade list via trade.AddCustomMetric
You should use RawTextOutput since there can be multiple scale in/out per result list row. Also scale in/out will be at different dates other than trade.EntryDateTime/ExitDateTime.
// Incomplete code snippet! Look below link for what it is about
/// @link https://forum.amibroker.com/t/assistance-requested-please-acquire-price-on-scaled-entry-using-mid-level-cbt/13219/4
// ....
dt = DateTime();
for (i = 0; i < BarCount; i++)
{
for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
{
if ( sig.IsScale() ) {
sig_dt = dt[i];
bo.RawTextOutput( StrFormat("Date: %s, Scale Price: %g", DateTimeToStr(sig_dt), sig.Price));
}
}
bo.ProcessTradeSignals(i);
}
// ...
Is it possible to the have the data shown in the trade list in such a format where 2nd scale-in entry is shown in separate column along the same row as the initial entry? For example, in the image shown below it would be ideal if the 2nd scale-in price was listed under column heading E2nd followed by the 2nd scale-in date under column heading E2ndDt while still lining up with the initial entry Date of 01/20/2011. Data from the 3rd entry would like wise show up in a similar fashion.
My apologies, I am still a bit confused. Below is code snippet for the image above. Is it possible to some how get and store the data from the first phase to a variable which may be able to be show in via trade.AddCustomMetric on the trade list? I only ask because that currently seems like my best option to get the data to line up as mentioned above.
Despite several weeks in attempting to find a solution, I am still stuck? Could someone PLEASE be kind enough to provide some assistance on how to display the second signal price followed by the second signal entry date on the trade list via AddCustomMetric function.
The problem is that in your main bar-by-bar loop (the one with the bo.ProcessTradeSignals() call), you are generating a trade number (NumTrades) which is incremented every time you get a new entry. In other words, you are numbering your trade based on the order of entry.
In the bo.GetFirstTrade()/GetNextTrade() loop, the trades will be retrieved in the order that they were exited, not the order they were entered. Therefore, trying to match up the trades in this way won't work.
There may be multiple ways to solve this problem, but personally I would switch to a low-level CBT so that I could call bo.EnterTrade(), immediately retrieve the open trade object, and then call trade.AddCustomMetric() to add the initial entry date and price. When the trade scales, I would call trade.AddCustomMetric() again with the scale-in date and price.
Another way to do this would be to save static or dynamic variables as you are now, but instead of naming them something like "E1stDt1", "E1stDt2", etc. give them names that include the symbol and entry datenum so you can more easily retrieve them later. For example, "AAPL_1190705_E1stDt" would be the first entry date (which you already have in the trade list, incidentally) for the AAPL trade that entered on July 5, 2019.
A third alternative would be to abandon the concept of scaling and simply have multiple open trades on the same symbol, which would mean the trade list would show all the prices and dates you're interested in. However, that may introduce other complications that you don't want to deal with.