Download MetaTrader 5

Convert MQ5 codes to MQ4

To add comments, please log in or register
Rex_Loner
123
Rex_Loner  

Hi,

 

I found this code in some article around here.

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 <Trade\Trade.mqh>
//+------------------------------------------------------------------+
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);
     }
  }
//+------------------------------------------------------------------+

 

Now, there's no such function as Trade.mqh in MQL4, so I change Function Call of void Trade() to:

void Trade()
{
   // close position it it's opposite to the prediction
   for (int i = 0; i <= OrdersTotal(); i++)
      {
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            {
               if (OrderSymbol() == _Symbol)
                  {
                     if (OrderType() == OP_BUY && Prognoze <= 0)
                        OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage * MyPoint, Blue);
                     if (OrderType() == OP_SELL && Prognoze >= 0)
                        OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage * MyPoint, Blue);
                  }
            }
      }
   // if there's no position, open one according to the prediction
   if (Prognoze != 0 && Symbol() == _Symbol)
      {
         if (Prognoze > 0) OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "", 0, 0, Green);
         if (Prognoze < 0) OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "", 0, 0, Red);
      }
}

 

After compiling, there are warnings telling me that return value of 'OrderClose' should be checked and return value of 'OrderSend' should be checked. What am I supposed to do? Can anyone help me with this?

 

Regards,

Aras 

rocketman99
122
rocketman99  

The warning message is pretty clear? Check the return value from OrderClose and OrderSend to see of an error did not occur.


https://www.google.com.au/search?q=return+value+of+'OrderClose'+should+be+checked

whroeder1
15348
whroeder1  
rex_loner: should be checked. What am I supposed to do?
How about you add code to check them? What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
To add comments, please log in or register