If it is possible the solution is way beyond the scope of what I can provide free of charge in the Q&A Forum. Perhaps someone else has worked this out though and will come along and post their solution as a new answer to this topic.
There are so many issue with this it makes my head spin. For example the code will need to check for how many shares were purchased and at what price. That's pretty straight forward using existing language tools in Thinkorswim. However the code will only know a trade took place when the number of shares changes. There is just no way to write code in Thinkorswim that can keep track of buys and sells and amounts with any degree of accuracy. Not within a chart environment.
And what you purchased shares 5 years ago? And your chart only has 2 years of historical data loaded? Busted. There are so many ways this can go wrong and I strongly encourage you to drop this and move on to something more productive. This is a black whole that can drain away weeks of productivity with nothing to show for it.
And on top of all of this, the data you are seeking to display on a chart is already available elsewhere on the platform. Just use what's available and focus on making profitable trades.