SIDEBAR FIGURE 1:
C++ System Implementation.Here's the equivalent of a TradeStation system module. Please refer to Technical Analysis of STOCKS & COMMODITIES magazine, January 1997, for complete text of this article.
void SC_Art3_Model (float **d, int nb, float *p, float *res, TRDSIM &tsim) { static float prices[22], avgdiff1, avgdiff2, oldprofit, tmp1, tmp2; static int cb, i, j, k; static bool condition1, condition2, firstpass=TRUE; #define diff1 d[101] #define diff2 d[102] // obtain guess of model parameters from genetic optimizer int n1 = (int) (p[1] = (int) p[1]); // 1..21 int n2 = (int) (p[2] = (int) p[2]); // 1..21 float n3 = (float) (p[3] = (float) p[3]); // -2.0..2.0 int m1 = (int) (p[4] = (int) p[4]); // 1..21 int m2 = (int) (p[5] = (int) p[5]); // 1..21 float m3 = (float) (p[6] = (float) p[6]); // -2.0..2.0 // for each bar... for (cb = 50; cb <= nb; cb++) { // update tsim, a simulated trading account tsim.update (O[cb], H[cb], L[cb], C[cb], cb); // assemble array of prices for easy comparison (see text) prices[1] = O[cb+1]; for (i = 0; i < 5; i++) { prices[2+4*i] = C[cb-i]; prices[3+4*i] = L[cb-i]; prices[4+4*i] = H[cb-i]; prices[5+4*i] = O[cb-i]; } // compute absolute differences as series variables diff1[cb] = fabs (prices[m1] - prices[m2]); diff2[cb] = fabs (prices[n1] - prices[n2]); // evaluate trading rules (use lookback of 110 bars) if (cb > 110) { avgdiff1 = Average (diff1, 25, cb); avgdiff2 = Average (diff2, 25, cb); condition1 = prices[m1] > prices[m2] + m3 * avgdiff1; condition2 = prices[n1] > prices[n2] + n3 * avgdiff2; if (condition1 == TRUE && condition2 == TRUE) { tsim.buy_open(); // buy tomorrow's open tsim.exit_long_close(); // exit tomorrow's close } } // return system fitness (see text) tmp1 = tsim.net_long() + tsim.net_short(); if (DATE[cb] == 880104) oldprofit = tmp1; if (DATE[cb] == 941230) res[1] = tmp1 - oldprofit; } }