# Grid Trading System Robot (GTSbot): A Novel Mathematical Algorithm for Trading FX Market
## 3 GTSbot: The Proposed Pipeline
### GTSbot: Trend Classification Block  
The output of the regression network SCG block (the predicted currency close price) was used to estimate the most probable trend of the traded financial currency cross. In a classical \(1\) min (one minute) intraday trading timeframe, there are \(n\) close price quotations so that if we denote \(c_{f}^{close}(k)\) the close price to be the predicted at k-time (by the SCG BP neural network), then we define the following relationship (1):  
\[c_{f}^{Close}(k)=R_{SCG}\Big{(}c^{Close}(k-1),c^{Open}(k-1),c^{Law}(k-1),c^{ High}(k-1),c^{Volume}(k-1)\Big{)} \tag{1}\]  
We denoted \(R_{SCG}\) as the regression map function of the SCG regression network block. At the next step, the trend classification block (TCB) provided an estimation of the current financial trend performing the following check:  
\[\begin{array}{ll}Long\;Trend&if\;\frac{\partial c_{f}^{Close}(k+1)}{\partial k }>\delta\;and\;\frac{\partial^{2}c_{f}^{Close}(k+1)}{\partial k^{2}}>0\\ Short\;Trend&if\;\frac{\partial c_{f}^{Close}(k+1)}{\partial k}<\delta\;and \;\frac{\partial^{2}c_{f}^{Close}(k+1)}{\partial k^{2}}<0\\ Null\;Trend&otherwise\end{array} \tag{2}\]  
Basically, the TCB performs ad-hoc fast mathematical analysis of the financial currency time-series acquired from the broker quotations. More in detail, the TCB system performs careful analysis of the first and second derivative of the collected FX cross time-series and the predicted close price at  
Figure 3: (**a**) The EUR/USD real close time-series (red) vs EUR/USD forecasted close prices (black). (**b,c**) A detail of the forecasted close pricing (by the proposed scaled conjugate gradient back-propagation (SCG BP) neural network).  
(\(k\)+1)-time. It can be noted that, if the first derivative is greater than an empirically defined threshold \(\delta\) (defined equal to the broker spread), then the trend increases over time (long trend). To confirm this we needed to check whether the sign of the second derivative, which is a robust measure of the concavity of the acquired time-series curve. If both conditions were true, the TCB confirmed the long trend or short trend, otherwise. If at least one of the above check failed (i.e., the first and second derivative did not show same mathematical behavior), it was enough to indicate that the trend was not well determined, therefore, no operation was suggested. For the mathematical computation of the first and the second derivative, we used the Equations (3) and (4), respectively.  
\[\frac{\partial c_{f}^{Close}(k+1)}{\partial k}c_{f}^{Close}\;(k+1)-c_{real}^{ Close}(k) \tag{3}\]  
\[\frac{\partial^{2}c_{f}^{Close}(k+1)}{\partial k^{2}}c_{f}^{Close}\;(k+1)-c_{ real}^{Close}(k-1)-2c_{real}^{Close}(k) \tag{4}\]  
In Figure 4 an instance of the trend prediction made by TCB is reported, both for the long trend as well as for the short ones.  
We tested the described trend forecast algorithm over EUR/USD currency historical data (as said: Latest five years (2014-2018)) at 1 min timeframe. From our experimental results, the TCB was able to forecast the trend with an accuracy of 73.2%.