I am using Amibroker. I would like to get the yearly gain of last 2 years using AFL. The yearly gain is defined as price gain on last date of year in December compared to first date of year in January. One way to get this is to view the chart in yearly mode. However, I want the yearly returns to be obtained in AFL.
As you have no code to show, here's something to start.
b = TimeFrameGetPrice( "C", inYearly, -1 );
v = TimeFrameGetPrice( "C", inYearly, -2 );
change = ((b-v)/v)*100
printf(" = "+WriteVal(b)+" = "+Writeval(v)+" = "+WriteVal(change));
This shows the rate of change for the past year if you put it unto Guru commentary.
You should be able to work out the previous year, then print the output to the chart and pretty it all up (with % symbol, different colors, etc). Look at TmeFrameCompress and Expand, to get data from different timeframes, PlotText function to plot output.