الان ،نعلم ماذا يجب أن نقوم به . إذا لدينا لمحة معلومات من المستقبل ، يمكننا استعمالها في إنشاء اكسبيرت
وذلك باستخدام الشبكة العصبية لتنبؤ بدلا من اقتباس المستقبل .
واريد أن أذكركم مرة أخرى أن الهدف من هذه الدورة هو أن تعلم كيفية إنشاء اكسبيرت يعتمد على الشبكة العصبية
ولا يعني ذلك أنه سيكون اكسبيرت مثالي ،ولاكن يمكن أن يكون ،من خلال بحثكم و تجاربكم بعد الدورة.
في هذا الدرس سنقوم بتجريب عدة تركيبات ومحاولات (شارت،وصف الخسارة ،جني الربح ، مستويات البيع والشراء ...إلخ )
السكريبت أدناه يحتوي على بعض التعليقات ولكن يجب أن تحاولوا فاهمه بدون مساعدة خصوصا بعد هذا الكم الهائل من الأمثلة ودرس البرمجة التي مررنا بها في هذه الدورة:
كود PHP:
void main()
{
OUT_CLEANUP();
string strImagePath =
"c:\\S_Projects\\CortexPro\\data\\stocks_nn\\images\\";
PRINT("%s\r\n", "Deleting image files...");
array_s arrDirList =
GET_DIR(strImagePath, 0, "*.png");
for(double n = 0; n < ARRAY_SIZE(arrDirList); n = n + 1)
{
F_UNLINK(arrDirList[n]);
}
string strForexName = "EURUSD_H1";
string strNnPath =
"c:\\S_Projects\\CortexPro\\data\\stocks_nn\\nn\\";
string strNnFileName = strNnPath + strForexName + ".nn";
PRINT("%s\r\n", "Deleting nn files...");
array_s arrDirList =
GET_DIR(strNnPath, 0, "*.nn");
for(double n = 0; n < ARRAY_SIZE(arrDirList); n = n + 1)
{
F_UNLINK(arrDirList[n]);
}
// ------------
string strDataFileName =
"c:\\S_Projects\\CortexPro\\data\\samples\\forex\\"
+ strForexName + ".TXT";
string strLagFileName =
"c:\\S_Projects\\CortexPro\\data\\stocks_nn\\forex\\"
+ strForexName + ".lgg";
double bIsPathRelative = 0;
array arrDate = CREATE_ARRAY(0);
array arrTime = CREATE_ARRAY(0);
array arrOpen = CREATE_ARRAY(0);
array arrHigh = CREATE_ARRAY(0);
array arrLow = CREATE_ARRAY(0);
array arrClose = CREATE_ARRAY(0);
TABLE_LOADER(strDataFileName, bIsPathRelative, 0, "",
0, "", 0, arrDate, 1, arrTime, 2, arrOpen, 3,
arrHigh, 4, arrLow, 5, arrClose);
// Interval, Ma, OutLag
array_s arrParameters = CREATE_ARRAY_S(0);
arrParameters[0] = "24,4,2";
arrParameters[1] = "24,4,3";
arrParameters[2] = "24,7,2";
arrParameters[3] = "24,7,3";
arrParameters[4] = "24,7,4";
arrParameters[5] = "32,4,2";
arrParameters[6] = "32,4,3";
arrParameters[7] = "32,7,4";
arrParameters[8] = "48,7,8";
array arrClv;
array arrClvSmooth;
double nNetNum = 1;
double nRemoveFirst = 200;
double dStopError = 0;
double nStopEpoch;
array arrLags = CREATE_ARRAY(0);
array_s arrStrLags = CREATE_ARRAY_S(0)
// ATTN: These lags are based on nWinLag.
// Example: nWinLag = 1, then each number
// should be increased by 1
arrStrLags[0] =
"18,0,1,2,3,4,6,8,12,14,16,20,24,28,32,40,48,56,64";
arrStrLags[1] =
"20,0,1,2,3,4,6,8,12,14,16,20,24,28,32,50,70,90,110,130,150";
array arrBalance = CREATE_ARRAY(0);
array arrBalanceBuy = CREATE_ARRAY(0);
array arrBalanceSell = CREATE_ARRAY(0);
array arrWinInterval = CREATE_ARRAY(0);
array arrWinMa = CREATE_ARRAY(0);
array arrWinLag = CREATE_ARRAY(0);
array arrWinStopLoss = CREATE_ARRAY(0);
array arrWinTakeProfit = CREATE_ARRAY(0);
array arrWinBuyLevel = CREATE_ARRAY(0);
array arrWinSellLevel = CREATE_ARRAY(0);
array arrWinNeurons = CREATE_ARRAY(0);
array_s arrWinNnLags = CREATE_ARRAY_S(0);
array arrWinProfit = CREATE_ARRAY(0);
array arrWinProfitBuy = CREATE_ARRAY(0);
array arrWinProfitSell = CREATE_ARRAY(0);
array arrNn = CREATE_ARRAY(0);
array arrStopLoss = CREATE_ARRAY(0);
arrStopLoss[0] = 0.005;
arrStopLoss[1] = 0.0075;
arrStopLoss[2] = 0.01;
arrStopLoss[3] = 0.015;
arrStopLoss[4] = 0.02;
string strParam;
string strToken;
double nMa;
double nOutLag;
double hNn;
double dBuyLevel;
double dSellLevel;
double nInterval;
double nExtractRecords;
double nCounter = 0;
double nSelectedCounter = 0;
double dExpectedCycles =
ARRAY_SIZE(arrParameters) * ARRAY_SIZE(arrStrLags);
for(double nParIdx = 0; nParIdx < ARRAY_SIZE(arrParameters);
nParIdx = nParIdx + 1)
{
strParam = arrParameters[nParIdx];
strToken = GET_TOKEN(strParam, ",");
nInterval = STR2NUM(strToken);
arrClv = CreateClv(nInterval);
strToken = GET_TOKEN(strParam, ",");
nMa = STR2NUM(strToken);
arrClvSmooth = EXP_MVAVG(arrClv, nMa);
strToken = GET_TOKEN(strParam, ",");
nOutLag = STR2NUM(strToken);
for(double nLagIdx = 0; nLagIdx < ARRAY_SIZE(arrStrLags);
nLagIdx = nLagIdx + 1)
{
double nNumOfLags;
string strLagBuf = arrStrLags[nLagIdx];
CreateLagFile(strLagBuf, nRemoveFirst);
double nNeurons = (nNumOfLags + 1) / 2 + 1;
nStopEpoch = nNeurons * 1000;
nCounter = nCounter + 1;
NewNn(arrLags, dStopError, nStopEpoch, nNeurons);
TeachNn();
hNn = OPEN_NN(strNnFileName, bIsPathRelative);
APPLY_NN(hNn, nExtractRecords, 1.0, 1,
arrClvSmooth, arrLags, 1, arrNn);
CLOSE_NN(hNn);
OUT_CLEANUP();
for(double nStopIdx = 0; nStopIdx < ARRAY_SIZE(arrStopLoss);
nStopIdx = nStopIdx + 1)
{
double dStopLoss = arrStopLoss[nStopIdx];
for(double dTakeProfit = 0; dTakeProfit <= 0.05;
dTakeProfit = dTakeProfit + 0.01)
{
for(double nBuySellIdx = 0; nBuySellIdx < 24;
nBuySellIdx = nBuySellIdx + 1)
{
dBuyLevel = 0.1 + 0.01 * nBuySellIdx;
dSellLevel = 0.9 - 0.01 * nBuySellIdx;
PRINT("%.0f", nCounter, " of %.0f",
dExpectedCycles, " (%.0f): ",
nSelectedCounter, "%.0f\r\n", nNetNum);
Test();
if(arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1]
> 1000
&& arrBalanceSell[ARRAY_SIZE(arrBalanceSell)
- 1] > 1000)
{
nSelectedCounter = nSelectedCounter + 1;
SaveWin();
double dBuyLevelTmp = dBuyLevel;
double dSellLevelTmp = dSellLevel;
dBuyLevel = dBuyLevel - 0.003;
dSellLevel = dSellLevel + 0.003;
Test();
if(arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)
- 1] > 1000
&& arrBalanceSell[ARRAY_SIZE(
arrBalanceSell) - 1] > 1000)
{
SaveWin();
}
dBuyLevel = dBuyLevel + 0.006;
dSellLevel = dSellLevel - 0.006;
Test();
if(arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)
- 1] > 1000
&& arrBalanceSell[ARRAY_SIZE(
arrBalanceSell) - 1] > 1000)
{
SaveWin();
}
dBuyLevel = dBuyLevelTmp;
dSellLevel = dSellLevelTmp;
}
}
}
}
}
}
Chart(strForexName);
PRINT("%s\r\n", "Done");
}
// ----------------
void Test()
{
nNetNum = nNetNum + 1;
ARRAY_REMOVE(arrBalance, -1);
arrBalance[0] = 1000;
ARRAY_REMOVE(arrBalanceBuy, -1);
arrBalanceBuy[0] = 1000;
ARRAY_REMOVE(arrBalanceSell, -1);
arrBalanceSell[0] = 1000;
array arrBars = CREATE_ARRAY(0);
arrBars[0] = 0;
double dLotSize = 100; // 0.1 lot
double nType = 0; // 1 buy, -1 sell, 0 - none
double dSpread = 0.0005;
double bStop;
double dMaxDrawDown = 0; // Max. Drawdown
double dCurrentMax = arrBalance[0]; // To calculate drawdown
double nTradeNumber = 0;
double nTradeNumberBuy = 0;
double nTradeNumberSell = 0;
double dOpenPrice;
double dStop;
double dTp = 0;
for(double nBar = nRemoveFirst + 1;
nBar < ARRAY_SIZE(arrClose) - nRemoveFirst;
nBar = nBar + 1)
{
if(nType != 0)
{
bStop = 0;
double dClosedAt;
// If BUY and stop loss or take profit reached
if(nType == -1 && (arrLow[nBar] <= dStop
|| (dTakeProfit > 0
&& arrHigh[nBar] >= dTp - dSpread)))
{
arrBalance[ARRAY_SIZE(arrBalance)] =
arrBalance[ARRAY_SIZE(arrBalance) - 1]
+ 100 * (arrLow[nBar] - dOpenPrice) * dLotSize;
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)] =
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1]
+ 100 * (arrLow[nBar] - dOpenPrice) * dLotSize;
arrBalanceSell[ARRAY_SIZE(arrBalanceSell)] =
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1];
bStop = 1;
dClosedAt = arrLow[nBar];
}
else
{
if(nType == 1 && (arrHigh[nBar] >= dStop - dSpread ||
(dTakeProfit > 0 && arrLow[nBar] <= dTp)))
{
arrBalance[ARRAY_SIZE(arrBalance)] =
arrBalance[ARRAY_SIZE(arrBalance) - 1] +
100 * (dOpenPrice - arrHigh[nBar] - dSpread)
* dLotSize;
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)] =
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1];
arrBalanceSell[ARRAY_SIZE(arrBalanceSell)] =
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1] +
100 * (dOpenPrice - arrHigh[nBar] - dSpread)
* dLotSize;
bStop = 1;
dClosedAt = arrHigh[nBar];
}
}
if(bStop == 1)
{
nType = 0;
arrBars[ARRAY_SIZE(arrBars)] = nBar;
}
}
if(arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1] < 500 ||
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1] < 500)
{
break nBar;
}
double dDrawDown = (dCurrentMax -
arrBalance[ARRAY_SIZE(arrBalance) - 1]) / 1000;
dMaxDrawDown = MAX(dMaxDrawDown, dDrawDown);
dCurrentMax = MAX(dCurrentMax,
arrBalance[ARRAY_SIZE(arrBalance) - 1]);
if(nType != -1 && arrNn[nBar - 1] <= dBuyLevel
&& arrNn[nBar] >= dBuyLevel)
{
if(nType == 1)
{
arrBalance[ARRAY_SIZE(arrBalance)] =
arrBalance[ARRAY_SIZE(arrBalance) - 1] +
100 * (dOpenPrice - arrHigh[nBar] - dSpread)
* dLotSize;
arrBalanceSell[ARRAY_SIZE(arrBalanceSell)] =
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1] +
100 * (dOpenPrice - arrHigh[nBar] - dSpread)
* dLotSize;
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)] =
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1];
arrBars[ARRAY_SIZE(arrBars)] = nBar;
}
dOpenPrice = arrHigh[nBar];
dStop = dOpenPrice - dStopLoss;
dTp = dOpenPrice + dTakeProfit;
nType = -1;
nTradeNumber = nTradeNumber + 1;
nTradeNumberBuy = nTradeNumberBuy + 1;
}
else
{
if(nType != 1 && arrNn[nBar - 1] >= dSellLevel
&& arrNn[nBar] <= dSellLevel)
{
if(nType == -1)
{
arrBalance[ARRAY_SIZE(arrBalance)] =
arrBalance[ARRAY_SIZE(arrBalance) - 1] +
100 * (arrLow[nBar] - dOpenPrice) * dLotSize;
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)] =
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1] +
100 * (arrLow[nBar] - dOpenPrice) * dLotSize;
arrBalanceSell[ARRAY_SIZE(arrBalanceSell)] =
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1];
arrBars[ARRAY_SIZE(arrBars)] = nBar;
}
dOpenPrice = arrLow[nBar];
dStop = dOpenPrice + dStopLoss;
dTp = dOpenPrice - dTakeProfit;
nType = 1;
nTradeNumber = nTradeNumber + 1;
nTradeNumberSell = nTradeNumberSell + 1;
}
}
}
// If at the end we have open positions, close them
if(nType == 1)
{
arrBalance[ARRAY_SIZE(arrBalance)] =
arrBalance[ARRAY_SIZE(arrBalance) - 1] +
100 * (dOpenPrice - arrHigh[nBar - 1] - dSpread)
* dLotSize;
arrBalanceSell[ARRAY_SIZE(arrBalanceSell)] =
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1] +
100 * (dOpenPrice - arrHigh[nBar - 1] - dSpread)
* dLotSize;
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)] =
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1];
arrBars[ARRAY_SIZE(arrBars)] = nBar - 1;
}
else
{
if(nType == -1)
{
arrBalance[ARRAY_SIZE(arrBalance)] =
arrBalance[ARRAY_SIZE(arrBalance) - 1] +
100 * (arrLow[nBar - 1] - dOpenPrice) * dLotSize;
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy)] =
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1] +
100 * (arrLow[nBar - 1] - dOpenPrice) * dLotSize;
arrBalanceSell[ARRAY_SIZE(arrBalanceSell)] =
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1];
arrBars[ARRAY_SIZE(arrBars)] = nBar - 1;
}
}
if(arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1] > 1000 &&
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1] > 1000)
{
PRINT("%.0f", nNetNum, ". Trades: %.0f", nTradeNumber,
" (B: %.0f", nTradeNumberBuy,
", S: %.0f", nTradeNumberSell,
"), Balance: %f", arrBalance[ARRAY_SIZE(arrBalance) - 1],
" (%f", arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1],
", %f)\r\n", arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1],
"\tI: %.0f", nInterval, ", Ma: %.0f", nMa, ", Out: %.0f",
nOutLag,
", Stop: %.4f", dStopLoss, ", Tp: %.4f\r\n", dTakeProfit,
"\tBuy: %.3f", dBuyLevel, ", Sell: %.3f", dSellLevel,
", Neurons: %.0f", nNeurons, ", Lags: %s\r\n", strLagBuf);
}
}
// ---------------
array CreateClv(double nInterval)
{
PRINT("%s\r\n", "Creating CLV indicator");
array arrClv = CREATE_ARRAY(0);
array arrPeriodLow = CREATE_ARRAY(0);
array arrPeriodHigh = CREATE_ARRAY(0);
double nArraySize = ARRAY_SIZE(arrClose);
array arrPeriodLow = MVMIN(arrLow, nInterval);
array arrPeriodHigh = MVMAX(arrHigh, nInterval);
for(double i = 0; i < nInterval; i = i + 1)
{
arrClv[i] = 0;
}
double dClose;
double dLow;
double dHigh;
for(i = nInterval; i < nArraySize; i = i + 1)
{
dClose = arrClose[i];
dLow = arrPeriodLow[i];
dHigh = arrPeriodHigh[i];
// / 2 + 1 to confine to 0...1 instead of -1...1
arrClv[i] = (((dClose - dLow) - (dHigh - dClose))
/ (dHigh - dLow)) / 2 + 0.5;
}
return arrClv;
}
// ----------------
void SaveWin()
{
if(arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1] > 1000
&& arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1] > 1000)
{
double nWinIdx = ARRAY_SIZE(arrWinInterval);
arrWinInterval[nWinIdx] = nInterval;
arrWinMa[nWinIdx] = nMa;
arrWinLag[nWinIdx] = nOutLag;
arrWinStopLoss[nWinIdx] = dStopLoss;
arrWinTakeProfit[nWinIdx] = dTakeProfit;
arrWinBuyLevel[nWinIdx] = dBuyLevel;
arrWinSellLevel[nWinIdx] = dSellLevel;
arrWinNeurons[nWinIdx] = nNeurons;
arrWinNnLags[nWinIdx] = arrStrLags[nLagIdx];
arrWinProfit[nWinIdx] = arrBalance[ARRAY_SIZE(arrBalance) - 1];
arrWinProfitBuy[nWinIdx] =
arrBalanceBuy[ARRAY_SIZE(arrBalanceBuy) - 1];
arrWinProfitSell[nWinIdx] =
arrBalanceSell[ARRAY_SIZE(arrBalanceSell) - 1];
string strWinNnFileName = strNnPath + strForexName + "_"
+ NUM2STR(nWinIdx, "%.0f") + ".nn";
F_COPY(strNnFileName, strWinNnFileName);
}
}
// -----------------
void CreateLagFile(string strLags, double nRemoveFirst)
{
double hFile = F_OPEN(strLagFileName, "wb");
F_PRINT(hFile, "%s", "No,Clv");
ARRAY_REMOVE(arrLags, -1);
string strToken = GET_TOKEN(strLags, ",");
nNumOfLags = STR2NUM(strToken);
for(double i = 0; i < nNumOfLags; i = i + 1)
{
strToken = GET_TOKEN(strLags, ",");
arrLags[i] = STR2NUM(strToken) + nOutLag;
}
double nFullLag;
for(i = 0; i < ARRAY_SIZE(arrLags); i = i + 1)
{
nFullLag = arrLags[i];
F_PRINT(hFile, ",ClvMa%.0f", nMa, "-%.0f", nFullLag);
}
F_PRINT(hFile, "%s\r\n", "");
double nNum;
for(i = nRemoveFirst; i < ARRAY_SIZE(arrClose); i = i + 1)
{
nNum = i - nRemoveFirst + 1;
F_PRINT(hFile, "%.0f", nNum, ",%f", arrClvSmooth[i]);
for(double j = 0; j < ARRAY_SIZE(arrLags); j = j + 1)
{
F_PRINT(hFile, ",%f", arrClvSmooth[i - arrLags[j]]);
}
F_PRINT(hFile, "%s\r\n", "");
}
F_CLOSE(hFile);
}
// --------------
void NewNn(array arrLags, double dStopError,
double nStopEpoch, double nNeuronsLayer2)
{
double nSkipBefore = 0;
double nSkipAfter = 0;
string strStartLine = "";
string strEndLine = "";
double bReverseArrays = 0;
// Inputs
array arrInputColumns = CREATE_ARRAY(0);
array_s arrInputColumnNames = CREATE_ARRAY_S(0);
// 0 - Number, 1 - Clv, our input begins at column No 2
for(double nInputCol = 0; nInputCol < ARRAY_SIZE(arrLags);
nInputCol = nInputCol + 1)
{
arrInputColumns[nInputCol] = nInputCol + 2;
arrInputColumnNames[nInputCol] =
"Clv-" + NUM2STR(arrLags[nInputCol], "%.0f");
}
array arrOutputColumns = CREATE_ARRAY(0);
arrOutputColumns[0] = 1; // Clv
array_s arrOutputColumnNames = CREATE_ARRAY_S(0);
arrOutputColumnNames[0] = "Clv";
nExtractRecords = 0.7 * ARRAY_SIZE(arrClose);
// To do: Modify if more than one indicator is used
double nNeuronsLayer1 = ARRAY_SIZE(arrLags);
// double nNeuronsLayer2 = 7;
double nNeuronsLayer3 = 1;
double nNeuronsLayer4 = 0;
double nLayers = 3;
double nActivation = 0;
double nAdjustRange = 1.0;
array arrOutTabInputColumns = CREATE_ARRAY(0);
arrOutTabInputColumns[0] = 0; // Number
array_s arrOutTabInputColumnNames = CREATE_ARRAY_S(0);
arrOutTabInputColumnNames[0] = "No";
array arrOutTabOutputColumns = CREATE_ARRAY(0);
// Desired output and NN output will be added to the
// same list, right after inputs
arrOutTabOutputColumns[0] = ARRAY_SIZE(arrLags) + 2;
arrOutTabOutputColumns[1] = ARRAY_SIZE(arrLags) + 3;
array_s arrOutTabOutputColumnNames = CREATE_ARRAY_S(0);
arrOutTabOutputColumnNames[0] = "Clv";
arrOutTabOutputColumnNames[1] = "NN: Clv" ;
CREATE_NN(strNnFileName, bIsPathRelative, strLagFileName,
bIsPathRelative, nSkipBefore, nSkipAfter, strStartLine,
strEndLine, bReverseArrays, arrInputColumns,
arrInputColumnNames, arrOutputColumns, arrOutputColumnNames,
nExtractRecords, dStopError, nStopEpoch,
nNeuronsLayer1, nNeuronsLayer2, nNeuronsLayer3, nNeuronsLayer4,
nLayers, nActivation, nAdjustRange, arrOutTabInputColumns,
arrOutTabInputColumnNames,
arrOutTabOutputColumns, arrOutTabOutputColumnNames);
}
// ----------------
void TeachNn()
{
PRINT("%s\r\n", "Opening NN dialog, teaching the NN");
double bStartLearning = 1;
double bResumeScript = 1;
double bReset = 1;
OPEN_NN_FILE(strNnFileName, bIsPathRelative,
bStartLearning, bResumeScript, bReset);
}
// -------------
void Chart(strForexName)
{
PRINT("%s\r\n", "Processing winning configurations...");
string strXML = "<forex>\r\n";
string strWinNnFileName;
for(double nWin = 0; nWin < ARRAY_SIZE(arrWinInterval);
nWin = nWin + 1)
{
PRINT("%.0f...", nWin);
if(arrWinProfit[nWin] > 1000)
{
PRINT(" %s\r\n", "accepted");
nInterval = arrWinInterval[nWin];
nMa = arrWinMa[nWin];
nOutLag = arrWinLag[nWin];
dStopLoss = arrWinStopLoss[nWin];
dTakeProfit = arrWinTakeProfit[nWin];
dBuyLevel = arrWinBuyLevel[nWin];
dSellLevel = arrWinSellLevel[nWin];
strLagBuf = arrWinNnLags[nWin];
arrClv = CreateClv(nInterval);
arrClvSmooth = EXP_MVAVG(arrClv, nMa);
CreateLagFile(strLagBuf, nRemoveFirst);
strWinNnFileName = strNnPath + strForexName +
"_" + NUM2STR(nWin, "%.0f") + ".nn";
hNn = OPEN_NN(strWinNnFileName, bIsPathRelative);
APPLY_NN(hNn, nExtractRecords, 1.0, 1, arrClvSmooth,
arrLags, 1, arrNn);
CLOSE_NN(hNn);
nNetNum = nWin - 1;
Test();
string strImageFileName = strImagePath +
strForexName + "_" +
NUM2STR(nWin, "%.0f") + ".png";
strXML = strXML +
"\t<symbol>\r\n\t\t<symbol>\r\n";
strXML = strXML + "Trades:" + NUM2STR(nTradeNumber, "%.0f")
+ "(Buy:" + NUM2STR(nTradeNumberBuy, "%.0f")
+ ",Sell:" + NUM2STR(nTradeNumberSell, "%.0f")
+ "),I:" + NUM2STR(nInterval, "%.0f")
+ ",Ma:" + NUM2STR(nMa, "%.0f")
+ ",Lag:" + NUM2STR(nOutLag, "%.0f")
+ ",Stop:" + NUM2STR(dStopLoss, "%.4f")
+ ",Tp:" + NUM2STR(dTakeProfit, "%.4f")
+ ",Buy:" + NUM2STR(dBuyLevel, "%.3f")
+ ",Sell:" + NUM2STR(dSellLevel, "%.3f")
+ ",Neurons:" + NUM2STR(arrWinNeurons[nWin], "%.0f")
+ ",Nn Lags:" + strLags
+ ",Balance:" + NUM2STR(arrWinProfit[nWin], "%f")
+ ",Balance long:" +
NUM2STR(arrWinProfitBuy[nWin], "%f")
+ ",Balance short:" +
NUM2STR(arrWinProfitSell[nWin], "%f\r\n");
strXML = strXML + "\t\t</symbol>\r\n";
strXML = strXML + "\t\t" + SAVE_CHART(400, 300, 0,
strImageFileName,
arrBars, arrBalance, arrBalanceBuy, arrBalanceSell);
strXML = strXML + "\t</symbol>\r\n";
}
else
{
PRINT(" %s\r\n", "rejected");
}
}
strXML = strXML + "</forex>\r\n";
SAVE_XML(strImagePath, "chart_forex_nn",
"chart_forex_nn", "root", strXML);
SHOW_XML(strImagePath + "chart_forex_nn.xml");
}
سيستغرق البرنامج وقت طويل للعمل ،وستكون النتيجة قائمة طويلة من الشارتات ،والتي سنختار منها واحدة حسب نسبة الصفقات الرابحة والخاسرة وعدة معايير
كما ترون ، فإن هذا النظام لا يزال يفقد المال. في الفصول التالية سوف نركز على جعلها مربحة بإذن الله .