And so, after long tests and unsuccessful attempts, I decided to find out why the data differs directly from tradingview itself.

I wrote to tech support and received this response.
Here is the response of technical support:

Quote
Due to the peculiarities of FXCM API, FXCM sends us different data in real-time streaming and in history, therefore FXCM data can be different every time the chart was opened or refreshed.
We are working in cooperation with FXCM to show the same data.


The solution at the moment:

In tradingview, there is an option "export data", the only disadvantage, since tradingview has limitations, for example, on a 1-minute timeframe, you can get data in just 2-4 months.

The data export option is also available for a pro, premium subscription.