Learning and writing together in MQL5 - page 4

 
Hello! If someone can tell me if I have called the indicators correctly in my EA?

double perceptron()
{
double w1 = x1 - 100;
double w2 = x2 - 100;
double w3 = x3 - 100;
double w4 = x4 - 100;
double a1 = iCustom(NULL,0, "Custom CCI", 0);
double a2 = iCustom(NULL,0, "Custom CCI", 7)
double a3 = iCustom(NULL,0, "Custom CCI", 14);//this is CCI

double a4=iMA(NULL,0,21,0,0,0);//this is Force Index

return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
 
Avelox   :
Hi, can someone please tell me if I've called the indicators in my EA correctly?

double perceptron()
{
double w1 = x1 - 100;
double w2 = x2 - 100;
double w3 = x3 - 100;
double w4 = x4 - 100;
double a1 = iCustom(NULL,0, "Custom CCI", 0);
double a2 = iCustom(NULL,0, "Custom CCI", 7)
double a3 = iCustom(NULL,0, "Custom CCI", 14);//this is CCI

double a4=iMA(NULL,0,21,0,0,0);//this is Force Index

return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}


no.

iCustom, like any other indicator call function, returns the indicator handle. Read the documentation.

 

Thank you! Then like this!? double a2 = iCCI(NULL,0,7, 0);

double a4=iForce(NULL,0,21,0,0);

The compiler accepts the previous version as well.

 

See an example of our custom Alligator indicator https://www.mql5.com/en/code/9

There:

  1. A handle(iMA) is obtained
  2. Monitors how much data is calculated from this handle(BarsCalculated)
  3. Copy the data portion(CopyBuffer)
Alligator
Alligator
  • votes: 14
  • 2010.01.26
  • MetaQuotes Software Corp.
  • www.mql5.com
The Alligator Indicator is a combination of Balance Lines (Moving Averages).
 
Avelox   :

Thank you! Then like this!? double a2 = iCCI(NULL,0,7, 0);

double a4=iForce(NULL,0,21,0,0);

The compiler will also be satisfied with the previous variant.


The compiler is just fine. I've got such a code fragment when porting one of the 4-compiler indukes:


   iMA1Handle=iMA(NULL,0,Period1/2,0,3,PRICE_CLOSE); // Не забыть потом перемножить на 2
   iMA2Handle=  iMA(NULL,0, Period1,   0,3,PRICE_CLOSE);
   SQPeriod=NormalizeDouble(MathSqrt(Period1),0);

... Бла-бла-бла ...

It looked like this on 4:

   while (i>=0)
      {
         ExtMapBuffer2[i]=2*iMA(NULL,0,PeriodX/2,0,3,PRICE_CLOSE,i);
         ExtMapBuffer3[i]=  iMA(NULL,0, PeriodX,0,3,PRICE_CLOSE,i);
         ExtMapBuffer4[i]=ExtMapBuffer2[i]-ExtMapBuffer3[i];
         i--;
      }
   i=i2; // Возврат i для расчёта значений индюка
   while (i>=0)
      {
         ExtMapBuffer1[i]=iMAOnArray(ExtMapBuffer4,0,NormalizeDouble(MathSqrt(PeriodX),0),0,3,i);

... Бла-бла-бла ...

I didn't manage to translate line-by-line because iMAOnArray is absent in 5, and I don't want to use include from beta. Well, at first I transferred 2*iMa.... I couldn't understand why the output turns out to be rubbish. I was getting mad. I was about to write to the forum. Then I figured it out - my habit has taken over. The compiler accepts it because the returned handle in 5 has data type Int (a number, in fact) and it can be multiplied by 2. But the output handle is a question and it won't work that way

 

I start trying to migrate the system to 5 and immediately get in trouble

//+------------------------------------------------------------------+
//|                                                  GetInternet.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#import "wininet.dll"
  int InternetAttemptConnect (int x);
  int InternetOpenA(string sAgent, int lAccessType, 
                    string sProxyName = "", string sProxyBypass = "", 
                    int lFlags = 0);
  int InternetOpenUrlA(int hInternetSession, string sUrl, 
                       string sHeaders = "", int lHeadersLength = 0,
                       int lFlags = 0, int lContext = 0);
          
  int InternetReadFile(int hFile, int& sBuffer[], int lNumBytesToRead, 
                       int& lNumberOfBytesRead[]);
  int InternetCloseHandle(int hInet);


#import "stdlib.ex5"
#import
input int Step = 300;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("Старт...");
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
    Comment(GetURL("http://www.forexremote.net"));
    
  }
//+------------------------------------------------------------------+


//+----------------------------------------------------------------------------------------------------------+
//| Функция получения WEB страницы                                                                           |
//+----------------------------------------------------------------------------------------------------------+
string GetURL(string url)
{
   int rv = InternetAttemptConnect(0);
   if(rv != 0)
     {
       Alert("Ошибка при вызове InternetAttemptConnect()");
       return("");
     }

   int hInternetSession = InternetOpenA("Microsoft Internet Explorer", 1, "", "", 0);
   if(hInternetSession <= 0)
     {
       Alert("Ошибка при вызове InternetOpenA()");
       return("");         
     }

   int hURL = InternetOpenUrlA(hInternetSession, url, "", 0, 0, 0);
   if(hURL <= 0)
    {
       Print("Ошибка получения данных с узла!");
       //fComment("Ошибка получения данных с узла!",true);
       InternetCloseHandle(hInternetSession);
       return("");         
     } 
          
   int cBuffer[256];
   int dwBytesRead[1]; 
   string TXT = "";
   while(!IsStopped())
     {
       bool bResult = InternetReadFile(hURL, cBuffer, 1024, dwBytesRead);
       if(dwBytesRead[0] == 0)
           break;
       string text = "";   
       for(int i = 0; i < 256; i++)
         {
              text = text + CharToString(cBuffer[i] & 0x000000FF);
              if(StringLen(text) == dwBytesRead[0])
                  break;
              text = text + CharToString(cBuffer[i] >> 8 & 0x000000FF);
              if(StringLen(text) == dwBytesRead[0])
                  break;
           text = text + CharToString(cBuffer[i] >> 16 & 0x000000FF);
           if(StringLen(text) == dwBytesRead[0])
               break;
           text = text + CharToString(cBuffer[i] >> 24 & 0x000000FF);
         }
       TXT = TXT + text;
       //Sleep(500);

     }
     InternetCloseHandle(hInternetSession);
     return(TXT);
}
//+----------------------------------------------------------------------------------------------------------+
//| Конец Функции получения WEB страницы                                                                     |
//+----------------------------------------------------------------------------------------------------------+
Compile with 0 errors, but the script doesn't work :-(
 
maxandsoft   :

I start trying a system transfer to a five and it's an instant hitch

Compile with 0 errors, but the script doesn't work :-(


What do you mean by "script". Judging by the functions in the code, you have published EA code. Look at Transition with MQL4
 
Rosh   :


What do you mean by the name "script". Judging by the functions in the code, you have published EA code. Look at the Transition with MQL4


Yes it is an EA, verbatim of course. I need to get a response from the server using wininet.dll
 
maxandsoft   :


Yes, exactly an advisor, verbatim of course. I need to get a response from the server using wininet.dll

Try to use Unicode versions of these functions. MQL5 uses Unicode encoding.

 
Rosh   :

Try to use Unicode versions of these functions. MQL5 uses Unicode.



The point is that when I compile it during debugging it throws me back to the MQL editor without even giving an error. And when you just pull it to the chart, it doesn't even appear on it. I.e., neither debugging nor launching the EA gives errors anywhere

Reason: