Display last buy date on the screen

Hi can some guide me in getting last buy date on the display by using writeif/ similar function

Buy = .. your code...;
dt = DateTime();

lastdt = LastValue( ValueWhen( Buy, dt ) );

Title = DateTimeToStr( lastdt );
3 Likes

Tomasz just beat me to it :slightly_smiling_face: but since I have the code now handy anyway I show it below. I also display the cursor selected day so that you can verify the dates.

// Dummy Trading system
m = MA( Close, 20 );
Buy = Cross( Close, m );
Sell = Cross( m, Close );

Plot( C, "Close", colorGrey50, stylebar );

LastBuyDateTime = LastValue( ValueWhen( Buy, DateTime() ) );

Title = 
"Selected DateTime: "+ DateTimeToStr( selectedvalue( DateTime()))+"\n"+
"    Last Buy Date: " + DateTimeToStr( LastBuyDateTime );


PlotShapes( IIf( Buy, 	shapeSmallUpTriangle, shapeNone ), ColorBrightgreen, 0, BuyPrice, 0 );
PlotShapes( IIf( Sell,	shapeSmallDownTriangle, shapeNone ), Colorred, 0, SellPrice, 0 );

image

3 Likes

Thanks a Ton…You Made my Day

Thanks a Ton…you Made my Day…

Hi Tomasz,

And how to display buy price when last buy on the screen ?

Thank you this topic so help me fully.