Any thoughts on why this code does not work with futures?
Code:
#def allows you to teach ThinkScript new "words" that you can reference later in your code
#GetYYYYMMDD() returns today's date
#there are 252 trading days each year
def yearstart = getyear() * 10000 + 101;
def tradedays = countTradingDays(yearstart, GetYYYYMMDD());
def closeEOY = getvalue(close, tradedays, 252);
def YTDnetchange = ((close - closeEOY)/closeEOY) * 100;
#YTDnetchange could have been the plot line, however to view results with a limited number of decimal places that line was another def or definition for ThinkScript. And a new "word" value was used for the plot line in this code. 2 means round to 2 decimal places
plot value = round(YTDnetchange, 2);
#AddLabel tells ThinkScript how you want the results of your code diplayed. Yes means do show the label. Words or sybols in " " will appear with your label.
#This label could have been created complicated using concat function ... or the simplified method of using a + sign between values and text you want to appear in the label
AddLabel(yes, value + "% YTD", color.BLACK);
#any watchlist column label can be quickly converted into a chart label via copy/paste/tweak into a new chart Study or Strategy. HOWEVER AssignBackgroundColor on a chart label will change entire background of the chart when condition is met
AssignBackgroundColor(if value < 0
then Color.RED
else if value > 0
then Color.GREEN
else color.LIGHT_GRAY);