The Terms of Trade, very generally, is a ratio of the prices of a country’s exports to the country’s imports.
Investopedia’s definition of terms of trade:

What are ‘Terms of Trade – TOT’?

Terms of trade represent the ratio between a country’s export prices and its import prices. The ratio is calculated by dividing the price of the exports by the price of the imports and multiplying the result by 100.

But how exactly do you calculate the “price of exports and imports” of a country like, say Brazil, that has USD 190B of exports a year comprising surely thousands, if not more, of different products, and what to do about the changing quantities of each of those products every year? How do we understand the terms of trade in a way that doesn’t vaguely seem like the trade balance? The trade balance is the total value of exports minus imports, or net value of exports. Where $$p_i$$ and $$q_i$$ are the price and quantity of export product $$i$$ and $$p’_i$$ and $$q’_i$$ are the price and quantity of import product $$i$$:

$$\textrm{Trade Balance } = EX – IM = \sum_{i}^{}{p_i \cdot q_i} – \sum_{i}^{}{p’_i \cdot q’_i}$$

$$\textrm{A ratio vaguely like the trade balance } = \frac{EX}{IM} = \frac{\sum_{i}^{}{p_i \cdot q_i}}{\sum_{i}^{}{p’_i \cdot q’_i}}$$

The answer is that the terms of trade is a ratio of a price index of exports to the same price index of imports. The price index can be calculated by deciding on a base year to compare the year in question. For example, for the prices of products in the year in question, we sum the values of exports for each product in that year, i.e. $$\sum_{i} {p_{i,n} \cdot q_{i,n}}$$ where $$i$$ is the index for each different product and $$n$$ is the year in question. For the prices of products in the base year $$0$$, we take the price of each product $$i$$ in that base year $$p_{i,0}$$ multiplied by the quantity of that product $$i$$ in the year in question $$n$$ instead of the base year $$0$$, $$q_{i,n}$$. In other words, we fix the quantity of each product $$q_i$$ to the quantity of each product in the year in question $$q_{i,n}$$ so that we are strictly comparing prices between year $$n$$ and $$0$$ and not letting changes in quantity $$q$$ get in the way. This is the Paasche index – always keeping $$q_{i}$$ as $$q_{i,n}$$.

Another way we can do this is: for the prices of products in the year in question $$n$$, we sum the prices of each product in that year $$p_{i,n}$$ multiplied by the quantity of each product from the base year $$q_{i,0}$$. For the prices in the base year $$0$$, we take the price of each product $$i$$ in that base year $$p_{i,0}$$ multiplied by the quantity of that product $$i$$ also in the base year $$0$$, $$q_{i,0}$$. So this time, instead of fixing the quantity of each product to the year in question $$n$$, we fix the quantity of each product to the base year $$0$$. This is the Laspeyres index.

Paasche index:

$$P_{\textrm{Paasche}} = \frac{\sum_{i}{p_{i,n} \cdot q_{i,n}}}{\sum_{i}{p_{i,0} \cdot q_{i,n}}}$$

Laspeyres index:

$$P_{\textrm{Laspeyres}} = \frac{\sum_{i}{p_{i,n} \cdot q_{i,0}}}{\sum_{i}{p_{i,0} \cdot q_{i,0}}}$$

Thus, by using such a price index calculation we “cancel out” the effect of changing export quantities or import quantities so that we are only looking at the change of price of exports or imports between two time periods. With a base year $$0$$, we can calculate the price index for exports in year $$n$$, the price index for imports in year $$n$$, and then divide the former by the latter to achieve the terms of trade for year $$n$$:

$$\textrm{Terms of Trade} \ = \frac{P_{\textrm{Paasche, exports}}}{P_{\textrm{Paasche, imports}}} \ \textrm{or} \ \frac{P_{\textrm{Laspeyres, exports}}}{P_{\textrm{Laspeyres, imports}}}$$

Note: If prices have gone up from year $$0$$ to year $$n$$, it’s likely that the quantities have adjusted between year $$0$$ and year $$n$$ by substituting other things for those products whose prices have risen or by simply just decreasing consumption of those products in order to deal with the price shock. For example, take a look at the ratio of value of products in year $$n$$ to the ratio of value of produces in base year $$0$$:

$$\frac{\sum_{i}{p_{i,n} \cdot q_{i,n}}}{\sum_{i}{p_{i,0} \cdot q_{i,0}}}$$

Compared to the base year, the value in the numerator from year $$n$$ have a new price $$p_{i,n}$$ and a new quantity $$q_{i,n}$$. The year $$n$$ quantity $$q_{i,n}$$ has adjusted to the new price of $$p_{i,n}$$ and thus if the price in year $$n$$ has increased from the price in year $$0$$, we expect the new quantity to be lower than the base year quantity $$q_{i,n} < q_{i,0}$$. Thus, the Laspeyres index overstates the price increase (because the quantity in the numerator $$q_{i,0}$$ is from before the price increase, from before adjusting to the new higher prices, and thus is larger than intended) and the Paasche index understates the price increase (because the quantity in the denominator is $$q_{i,n}$$, which is from after the price increase and thus $$q_{i,n}$$ is larger than intended, making the index value smaller than intended). If prices have decreased from year $$0$$ to year $$n$$, the quantity should increase from year $$0$$ to year $$n$$ to take advantage of those lower prices. Thus, the Laspeyres index value will be larger than intended (the quantity in the numerator $$q_{i,0}$$ is smaller than intended because time $$0$$ is before the quantity adjustment that would take advantage of lower prices; thus, the numerator is larger than intended) and thus understates the price decrease and the Paasche index value will be smaller than intended (the quantity in the denominator $$q_{i,n}$$ is larger than intended because time $$n$$ is after the quantity adjustment to take advantage of lower prices and thus the denominator is larger than intended; thus, the index is smaller than intended) and thus overstates the price decrease.

A terms of trade chart quantitatively summarizes the change in prices of a country’s exports and imports.

What is the conceptual difference between the

$$\textbf{Terms of Trade} \ = \frac{P_{\textbf{Paasche, exports}}}{P_{\textbf{Paasche, imports}}} \ \textbf{and}$$

$$\textbf{Current Account} \ = \sum_{i}{p_{i,n,exp} \cdot q_{i,n,exp}} – \sum_{j}{p_{j,n,imp} \cdot q_{j,n,imp}} \ \textbf{?}$$

The Terms of Trade can be thought of as a weather forecast for the trade situation of a country by taking some base year $$0$$ in the past and the current present time as year $$n$$. Data on the prices of goods and services on the world market at the current time for year $$n$$ are theoretically always available to us in the present time. Thus, we can always create an up-to-date Terms of Trade data point for the present. However, the Current Account is trickier to have in the exact present time because the exchange of goods and services takes time and surely there is more time lag between the act of trading goods and services for payment and the data of that act being available (to calculate the present Current Account) than the time lag between the price-setting or price-reporting for goods and services and the data of that price being available (to calculate the present Terms of Trade). So if the Terms of Trade of a country changes, that is a certain kind of forecast for that country’s Current Account for that year. But how?

How do we interpret the Terms of Trade in terms of the Current Account? If the Terms of Trade of a country increases, that means the prices of things that the country exports have relatively increased compared to the prices of things that the country imports. (This could be due to market forces of the global import and export market, or due to an appreciation in the country’s currency, or due to the country demanding more of what it imports causing import prices to rise, or due to the country unable to supply as much exports, e.g. due to adverse weather damaging agricultural or raw materials production, causing export prices to rise due to global demand for those products being inelastic, etc.) The factor to consider is the elasticity of those goods and services. If they’re inelastic (and price changes mean that the quantity doesn’t change much), then an increase in the Terms of Trade should mean an increase in the Trade Balance and Current Account ceteris paribus and a decrease in the Terms of Trade should mean a decrease in the Trade Balance and Current Account. But if the goods and services are highly elastic, that means that an increase in the Terms of Trade and thus a relative increase in the prices of that country’s exports means that the quantity demanded by importers for those goods and services decreases a lot, perhaps because importers of those goods and services are substituting something else for those goods and services or because they simply decrease their consumption of them. Thus, in this case, an increase in the Terms of Trade could result in a decrease in the Trade Balance and Current Account; and in the opposite case, a decrease in the Terms of Trade with elastic exports may result in an increase in the Trade Balance and Current Account. (A decrease in the Terms of Trade could be due to market forces of the global trade market, or due to a depreciation in the country’s currency, or due to the country demanding less of what it imports causing import prices to decrease, or due to the country’s increased competitiveness in production allowing it to supply its export prices at lower cost to attract more buyers, etc.)

Digression: Developing countries whose exports are largely primary commodities (e.g. raw materials, agricultural products) face:
1) A relatively inelastic demand. As world population and consumption increases, the demand for primary commodities doesn’t rise as much, likely due to improving technology and movements towards recycling and more ecologically friendly methods.
2) Quantity of supply by all developing countries increasing. Improving technology means that developing countries that supply primary commodities are able to supply more of their products. However, this coupled with 1) above means that there is downward pressure on prices. Suppliers supply more but buyers have inelastic demand – the quantity of primary commodities that developed countries demand does not grow as much as the quantity supplied by developing countries.
3) Developed countries whose exports face a relatively elastic demand. As world population and consumption (i.e. world income) increases, the demand for high-end manufacturing and services that developed countries export rises as much or even more, perhaps due to greater technological ability to produce high-end products at lower prices and great quantities, allowing consumers to purchase more and more high-end products. Thus, as world income rises, if the standards for standard of living and quality of life is measured depending on the consumption or availability of those high-end products, developing countries have exports that struggle more and more and developed countries have exports that gain an advantage more and more.
4) A degree of market concentration in the suppliers of manufactured goods from developed countries. If developing countries face suppliers that have monopolistic power, developing countries may be importing at high prices.
5) Instability in their ability to supply primary commodities due to reliance on weather and ecology. This instability makes long-term planning of fiscal and economic development difficult.