在MQL5中一起学习和写作 - 页 4

 
你好!如果有人能告诉我,我在我的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);//这是CCI

double a4=iMA(NULL,0,21,0,0,0);//这是力指数

return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
 
Avelox   :
你好,谁能告诉我,我在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);//这是CCI

double a4=iMA(NULL,0,21,0,0,0);//这是力指数

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


不。

iCustom,像任何其他指标调用函数 一样,返回指标句柄。阅读文件。

 

谢谢你!然后像这样!?double a2 = iCCI(NULL,0,7, 0)。

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

编译器也接受以前的版本。

 

请看我们定制的鳄鱼指示器的例子https://www.mql5.com/en/code/9

在那里。

  1. 获得一个手柄(iMA)。
  2. 监视从这个句柄中计算出的数据的多少(BarsCalculated)。
  3. 拷贝数据部分(CopyBuffer)。
Alligator
Alligator
  • 投票: 14
  • 2010.01.26
  • MetaQuotes Software Corp.
  • www.mql5.com
The Alligator Indicator is a combination of Balance Lines (Moving Averages).
 
Avelox   :

谢谢你!然后像这样!?double a2 = iCCI(NULL,0,7, 0)。

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

编译器也会对之前的变体感到满意。


编译器就很好。我在移植4个编译器中的一个时遇到了这样的代码片段。


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

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

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

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

我没有设法逐行翻译,因为5中没有iMAOnArray,而且我不想使用测试版的include。嗯,一开始我转了2*iMa....,我不明白为什么输出结果是垃圾。我真的开始生气了。我正准备给论坛写信。后来我想明白了--我的习惯已经占据了上风。编译器接受它,因为5中返回的句柄的数据类型 是Int(实际上是一个数字),而且可以乘以2。但输出柄是一个问题,它不会这样做的

 

我开始尝试将系统迁移到5,并立即遇到了麻烦

//+------------------------------------------------------------------+
//|                                                  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 страницы                                                                     |
//+----------------------------------------------------------------------------------------------------------+
编译时有0个错误,但脚本不工作 :-(
 
maxandsoft   :

我开始尝试将系统转移到五号机上,结果立刻出现了问题。

编译时有0个错误,但脚本不工作 :-(


你说的 "剧本 "是什么意思。从代码中的功能来看,你已经发布了EA代码。用MQL4看过渡期
 
Rosh   :


你说的 "剧本 "这个名字是什么意思。从代码中的功能来看,你已经发布了EA代码。用MQL4看一下过渡期


是的,它是一个EA,当然是逐字逐句的。我需要使用wininet.dll从服务器上获得一个响应。
 
maxandsoft   :


是的,正是一个顾问,当然是逐字逐句的。我需要使用wininet.dll从服务器上获得一个响应。

尽量使用这些函数的Unicode版本。MQL5使用Unicode编码。

 
Rosh   :

尽量使用这些函数的Unicode版本。MQL5使用Unicode。



问题是,当我在调试期间编译它时,它把我扔回了MQL编辑器,甚至没有给出一个错误。而当你把它拉到图表上时,它甚至没有出现在图表上。 也就是说,无论是调试还是启动EA,都不会在任何地方出现错误。