E-mail:    

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 long position and a bearish signal is received the position is 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 short positions. The trading system always adjusts the lot size to risk 1% of the trading account per trade.


AsirikuyReturnCode runSimpleNeuralNetworkSystem(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;

}


Code Fragment 3. Simple trading system based on a neural network using a stop of 60% of the daily ATR(6) indicator.

Trading System Simulation

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 R²=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 annualized return also stays positive most of the time – as showed in Figure 2 – with dips below the zero line being well controlled through the almost 30 year testing period.

<<Previous     Next>>