Imparare e scrivere insieme in MQL5 - pagina 4

 
Ciao, se qualcuno può dirmi se ho chiamato correttamente gli indicatori nel mio 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);//questo è CCI

double a4=iMA(NULL,0,21,0,0,0);//questo è Force Index

return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
 
Avelox   :
Ciao, qualcuno può dirmi se ho chiamato correttamente gli indicatori nel mio 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);//questo è CCI

double a4=iMA(NULL,0,21,0,0,0);//questo è Force Index

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


no.

iCustom, come qualsiasi altra funzione di chiamata dell'indicatore, restituisce l'handle dell'indicatore. Leggete la documentazione.

 

Grazie! Allora come questo? doppio a2 = iCCI(NULL,0,7, 0);

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

Il compilatore accetta anche la versione precedente.

 

Vedi un esempio del nostro indicatore personalizzato Alligator https://www.mql5.com/en/code/9

Ecco:

  1. Si ottiene una maniglia(iMA)
  2. Controlla quanti dati sono calcolati da questo handle(BarsCalculated)
  3. Copiare la porzione di dati(CopyBuffer)
Alligator
Alligator
  • voti: 14
  • 2010.01.26
  • MetaQuotes Software Corp.
  • www.mql5.com
The Alligator Indicator is a combination of Balance Lines (Moving Averages).
 
Avelox   :

Grazie! Allora come questo? doppio a2 = iCCI(NULL,0,7, 0);

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

Il compilatore sarà soddisfatto anche della variante precedente.


Il compilatore va benissimo. Ho un frammento di codice simile durante il porting di uno dei 4 compilatori 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);

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

Il 4 sembrava così:

   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);

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

Non sono riuscito a tradurre linea per linea perché iMAOnArray è assente in 5, e non voglio usare include dalla beta. Beh, all'inizio ho trasferito 2*iMa.... non riuscivo a capire perché l'uscita risulta essere una schifezza. Mi stavo arrabbiando molto. Stavo per scrivere al forum. Poi ho capito: la mia abitudine ha preso il sopravvento. Il compilatore lo accetta perché l'handle restituito in 5 ha il tipo di dati Int (un numero, in effetti) e può essere moltiplicato per 2. Ma la maniglia di uscita è una domanda e non funziona così

 

Comincio a cercare di migrare il sistema al 5 e subito mi trovo nei guai

//+------------------------------------------------------------------+
//|                                                  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 страницы                                                                     |
//+----------------------------------------------------------------------------------------------------------+
Compila con 0 errori, ma lo script non funziona :-(
 
maxandsoft   :

Comincio a provare un trasferimento di sistema a un cinque ed è un intoppo istantaneo

Compila con 0 errori, ma lo script non funziona :-(


Cosa intende per "script". A giudicare dalle funzioni nel codice, avete pubblicato il codice EA. Guarda la transizione con MQL4
 
Rosh   :


Cosa intendete con il nome "script". A giudicare dalle funzioni nel codice, avete pubblicato il codice EA. Guarda la transizione con MQL4


Sì, è un EA, alla lettera ovviamente. Ho bisogno di ottenere una risposta dal server usando wininet.dll
 
maxandsoft   :


Sì, esattamente un consigliere, alla lettera ovviamente. Ho bisogno di ottenere una risposta dal server usando wininet.dll

Cercate di usare le versioni Unicode di queste funzioni. MQL5 usa la codifica Unicode.

 
Rosh   :

Cercate di usare le versioni Unicode di queste funzioni. MQL5 usa Unicode.



Il punto è che quando lo compilo durante il debug mi rimanda all'editor MQL senza nemmeno dare un errore. E quando lo si tira sul grafico, non appare nemmeno su di esso. Cioè, né il debug né il lancio dell'EA danno errori da nessuna parte