Performance beginning of the year until to today

How can I program the performance roc(close,beginning of the year)
from today till at the beginning of the year in the explorer?

Thanks.

@Munichtrader try something like this

TradeDayOfYear = BarsSince( year() > Ref( year(), -1 ) ) + 1;

// For ROC Year-to-Date
RateOfChangeYTD = ( C - Ref( C, -TradeDayOfYear ) ) / ( Ref( C, -TradeDayOfYear ) ) * 100;

Filter = 1;
AddColumn( C, "Close", 1.2 );
AddColumn( TradeDayOfYear, "TradeDayOfYear", 1.0, colorBlack, colorLightYellow );
AddColumn( rateofchangeYTD, "rocYTD" );

image

6 Likes

@portfoliobuilder: Couldn’t you simplify that to:

RateOfChangeYTD = ROC(C,TradeDayOfYear);

@mradtke I believe that ROC() function requires a Number and can not take an Array. As TradeDayOfYear is an Array i think that your line will not work.

1 Like

Excellent point, @portfoliobuilder! You are correct that the second argument to ROC() cannot be an array.

as always thanks for the result:smiley:

assuming the TradeDayOfYear array contains the same values
using LastValue will do the trick

RateOfChangeYTD = ROC(C,LastValue(TradeDayOfYear));