- First of all you should not iterate through entire array but just iterate through visible chart area to output some text on chart.
- There is not any dist array variable required to set an y offset. PlotText function does have an y-offset argument (last argument of the function). https://www.amibroker.com/guide/afl/plottext.html
- Use DateTime() function and conversion to string to output date/time as text.
/// @link http://forum.amibroker.com/t/plottext-to-print-buy-sell-price-and-date-at-the-signals/4433/2
/// signal text output: Signal type, price, date/time
Version(6.20);
fntsize = 8;// font size
dist = 65;// y-offset
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
dt = DateTime();
dtformat = "\n%Y-%m-%d\n%H:%M:%S";
bkcolor = -1;// text background color, -1 means default color (transparent)
PlotTextSetFont( "", "ARIAL", fntsize, BarCount-1, 0, -1 );
for ( i = fvb; i <= lvb; i++ ) {
if( Buy[i] || Sell[i] ) {
var = "\n@" + C[i] + DateTimeFormat(dtformat, dt[i]);
if( Buy[i] ) PlotText( "Buy" + var, i, L[i], colorGreen, bkcolor, -dist+3*fntsize );
if( Sell[i] ) PlotText( "Sell" + var, i, H[i], colorRed, bkcolor, dist );
}
}
17 Likes