input double Lots = 0.1; //+------------------------------------------------------------------+ // Connect the DLL adapter, using which we are going to use the DLL neuronet created in NeuroSolutions #import "NeuroSolutionsAdapter.dll" int CalcNeuralNet(string dllPath, string weightsPath, double& inputs[], double& outputs[]); #import //+------------------------------------------------------------------+ class CNeuroSolutionsNeuralNet { private: string dllPath; // Path to a DLL neuronet created in NeuroSolutions string weightsPath; // Path to a file of the neuronet balances public: double in[20]; // Neuronet inputs - OHLC of 5 bars double out[1]; // Neuronet outputs - Close of a current bar CNeuroSolutionsNeuralNet(); bool Calc(); }; //+------------------------------------------------------------------+ void CNeuroSolutionsNeuralNet::CNeuroSolutionsNeuralNet() { string terminal = TerminalInfoString(TERMINAL_PATH); dllPath = terminal + "\\MQL5\\Files\\NeuroSolutions\\WeekPattern.dll"; weightsPath = terminal + "\\MQL5\\Files\\NeuroSolutions\\WeekPattern.nsw"; } //+------------------------------------------------------------------+ bool CNeuroSolutionsNeuralNet::Calc() { // Get current quotes for the neuronet MqlRates rates[], rate; CopyRates(Symbol(), Period(), 0, 6, rates); ArraySetAsSeries(rates, true); // Fill the array of input data of the neuronet double zlevel=0; for (int bar=0; bar<=5; bar++) { rate = rates[bar]; // 0 bar is not taken for input if (bar==0) zlevel=rate.open; // level of price calculation // 1-5 bars are inputed else { int i=(bar-1)*4; // input number in[i ] = rate.open -zlevel; in[i+1] = rate.high -zlevel; in[i+2] = rate.low -zlevel; in[i+3] = rate.close-zlevel; } } // Calculate the neuronet in the NeuroSolutions DLL (though the DLL adapter) int res = CalcNeuralNet(dllPath, weightsPath, in, out); switch (res) { case 1: Print("Error of creating neuronet from DLL \"", dllPath, "\""); return (false); case 2: Print("Error of loading balances to neuronet from the file \"", weightsPath, "\""); return (false); case 3: Print("Error of calculation of neuronet"); return (false); } // Output of the neuronet has appeared in the array out, you shouldn't do anything with it return (true); } //+------------------------------------------------------------------+ CNeuroSolutionsNeuralNet NN; double Prognoze; //+------------------------------------------------------------------+ #include //+------------------------------------------------------------------+ void OnTick() { // Get the price prediction from the neuronet if (NN.Calc()) Prognoze = NN.out[0]; else Prognoze = 0; // Perform necessary trade actions Trade(); } //+------------------------------------------------------------------+ void Trade() { // Close an open position if it is opposite to the prediction if(PositionSelect(_Symbol)) { long type=PositionGetInteger(POSITION_TYPE); bool close=false; if((type == POSITION_TYPE_BUY) && (Prognoze <= 0)) close = true; if((type == POSITION_TYPE_SELL) && (Prognoze >= 0)) close = true; if(close) { CTrade trade; trade.PositionClose(_Symbol); } } // If there is no positions, open one according to the prediction if((Prognoze!=0) && (!PositionSelect(_Symbol))) { CTrade trade; if(Prognoze > 0) trade.Buy (Lots); if(Prognoze < 0) trade.Sell(Lots); } } //+------------------------------------------------------------------+