FX TRADING SYSTEMS
labels.element(0)[0] = 0; RegressionDataset
datasetInput(inputs,labels); testOutput =
network(
datasetInput.inputs()); if (testOutput.element(0)[0] >
0) return(1); if (testOutput.element(0)[0] < 0) return(-1); return(0); }
Example construction and training is fundamental to the success of a neural network based system. Code Fragment 1 shows the function used to construct the set of past 84 examples used for the training of the neural network on each bar. Code Fragment 2 then shows the function that actually generates, trains the neural network and makes the prediction for the current candle. In this case the neural network is trained for 300 cycles and the functions used to link the input, hidden and output layers are fast sigmoid functions. The function returns a 1 if the current candle is expected to be bullish and -1 if it’s expected to be bearish. The function is called by the actual trading strategy showed in Code Fragment 3. The system uses a stop loss at 60% of the daily ATR calculated with a period of 9 days and then trades according to the signal generated by the neural network. If the expected day is bullish the system goes long and if
it’s bearish the system goes short. If there is currently an open 24 FX TRADER MAGAZINE April - June 2016
Code Fragment 3. Simple trading system based on a neural network using a stop of 60% of the daily ATR(6) indicator.
AsirikuyReturnCode runSimpleNeuralNet workSystem(StrategyParams* pParams) {
AsirikuyReturnCode returnCode = SUCCESS; double stopLoss, prediction;
stopLoss = iAtr(PRIMARY_RATES, 6, 1)*0.6;
prediction = NN_Prediction_i_ simpleReturn_o_simpleReturn() ;
if(prediction > 0){ return openOrUpdateLongEasy(0, stopLoss); }
if(prediction < 0){ return openOrUpdateShortEasy(0, stopLoss); }
return SUCCESS; }
long position and a bearish signal is
received the position is
short positions. The trading system always adjusts the lot size to risk 1% of the trading account per trade. ( Code Fragment 3. )
Trading System Simulation closed
and reversed while if a long signal is received the stop loss is updated as if the trade had been opened in the current bar. The same logic applies to
If we simulate this trading strategy using EUR/USD data from 1986 to February 2016 we find some rather interesting results (data before the introduction of the EUR belongs to the DEM/USD). A constant spread of 3 pips was used within the simulation, stops on gaps were assumed to be filled at the next available price, not at the stop level. The system has rather stable linear results with an R2=0.9 as showed in Figure 1 (y axis is logarithmic). Other statistics for the strategy are rather modest with a maximum drawdown of 27.5% and a CAGR of 7.97%. The system takes an average of around 2 trades per week with a winning percentage of 45.26% and a reward to risk ratio of 1.34. The
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
Page 8 |
Page 9 |
Page 10 |
Page 11 |
Page 12 |
Page 13 |
Page 14 |
Page 15 |
Page 16 |
Page 17 |
Page 18 |
Page 19 |
Page 20 |
Page 21 |
Page 22 |
Page 23 |
Page 24 |
Page 25 |
Page 26 |
Page 27 |
Page 28 |
Page 29 |
Page 30 |
Page 31 |
Page 32 |
Page 33 |
Page 34 |
Page 35 |
Page 36 |
Page 37 |
Page 38 |
Page 39 |
Page 40 |
Page 41 |
Page 42 |
Page 43 |
Page 44 |
Page 45 |
Page 46 |
Page 47 |
Page 48 |
Page 49 |
Page 50 |
Page 51 |
Page 52 |
Page 53 |
Page 54 |
Page 55 |
Page 56 |
Page 57 |
Page 58 |
Page 59 |
Page 60 |
Page 61 |
Page 62 |
Page 63 |
Page 64 |
Page 65 |
Page 66 |
Page 67 |
Page 68 |
Page 69 |
Page 70 |
Page 71 |
Page 72 |
Page 73 |
Page 74 |
Page 75 |
Page 76 |
Page 77 |
Page 78 |
Page 79 |
Page 80 |
Page 81 |
Page 82 |
Page 83 |
Page 84 |
Page 85 |
Page 86 |
Page 87 |
Page 88 |
Page 89 |
Page 90 |
Page 91 |
Page 92 |
Page 93 |
Page 94 |
Page 95