新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 846

 
erotin:

你能告诉我该地段的配给有什么问题吗?

一切都是错的。阅读文章 "EA应该通过哪些检查..."。那里有一个现成的功能。

 

完成了,做了一个空模板,为iCustom()函数准备了一切必要的东西。

我把我感兴趣的iCrossAD指标放到函数中。

该函数是有效的,它能正确地找到最外层的向上和向下箭头的索引,但这些箭头被设置的价格值是错误的。

代码很短,所以我将把它放在这里,我将附上这个顾问和指标的文件以备不时之需。

//+------------------------------------------------------------------+
//|                                             TestDoEasyPart08.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property description ""
#property strict
//--- includes
#include <DoEasy\Engine.mqh>
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>
//---
input string               Inp_param_indi_iCrossAD = "Input parameters indicator iCrossAD";//----- "Внешние параметры индикатора iCrossAD" -----

input uint                 InpPeriodFind           = 400;                 // Bars for calculate
input uint                 InpUnheckedBars         = 2;                   // Unchecked bars
input uint                 InpPeriodIND            = 21;                  // CCI period

//--- global variables

CEngine        engine;
CTrade         trade;
CPositionInfo  apos;
CSymbolInfo    asymbol;

uint            period_find = InpPeriodFind;       //Number bars for calculate

int            CrossAD;                           //Хэндл индикатора iCrossAD

double         Buf_Arrow_Sell[],                  //Массив буфера для приема значений последних стрелок ВНИЗ из индикатора iCrossAD
               Last_Arrow_Sell_volume,            //Переменная для записи значения цены последней стрелки ВНИЗ индикатора iCrossAD
               Last_Arrow_Sell_index;             //Переменная для записи значения индекса свечи последней стрелки ВНИЗ индикатора iCrossAD
               
double         Buf_Arrow_Buy[], Last_Arrow_Buy_volume, Last_Arrow_Buy_index;
   
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ArraySetAsSeries(Buf_Arrow_Buy, true);
   ArraySetAsSeries(Buf_Arrow_Sell, true);
//---
   CrossAD = iCustom(asymbol.Name(), _Period, "iCrossAD");
   if (CrossAD == INVALID_HANDLE)
   {
      Print("Не удалось создать описатель индикатора iCrossAD!");
      return(INIT_FAILED);
   }
      else Print("Хендл iCrossAD = ",CrossAD);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- delete objects
   ObjectsDeleteAll(0,"",-1);
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int n=0;
   
   if (CopyBuffer(CrossAD, 1, 0, period_find, Buf_Arrow_Buy) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 1-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return;
      }
         for(n=0; n<period_find; n++)
            {
               if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Buy_volume = Buf_Arrow_Buy[n];
         Last_Arrow_Buy_index  = n;
         Print("Last_Arrow_Buy_volume = ",Last_Arrow_Buy_volume,", Last_Arrow_Buy_index = ",Last_Arrow_Buy_index);
         
   if (CopyBuffer(CrossAD, 2, 0, period_find, Buf_Arrow_Sell) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 2-го буфера индикатора iCrossAD, error code %d",GetLastError());
         return;
      }
         for(n=0; n<period_find; n++)
            {
               if(Buf_Arrow_Sell[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Sell_volume = Buf_Arrow_Sell[n];
         Last_Arrow_Sell_index  = n;
         Print("Last_Arrow_Sell_volume = ",Last_Arrow_Sell_volume,", Last_Arrow_Sell_index = ",Last_Arrow_Sell_index);
      
Comment("-------------------------", 
         "\n Last_Arrow_Buy_volume     = ",Last_Arrow_Buy_volume,
         "\n Last_Arrow_Buy_index        = ",Last_Arrow_Buy_index,
         "\n ---------------------- ",
         "\n Last_Arrow_Sell_volume     = ",Last_Arrow_Sell_volume,
         "\n Last_Arrow_Sell_index        = ",Last_Arrow_Sell_index
         ); 
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(!MQLInfoInteger(MQL_TESTER))
      engine.OnTimer();
  }
附加的文件:
iCrossAD.mq5  49 kb
 

这就是 "专家 "标签上的日志条目的样子

2019.05.20 15:11:15.025 Test_iCustom (EURUSD,H1) Last_Arrow_Buy_volume = -11211905.17483469, Last_Arrow_Buy_index = 5.0

2019.05.20 15:11:15.025 Test_iCustom (EURUSD,H1) Last_Arrow_Sell_volume = -11203799.85975282, Last_Arrow_Sell_index = 50.0

2019.05.20 15:11:16.798 Test_iCustom (EURUSD,H1) Last_Arrow_Buy_volume = -11211905.17483469, Last_Arrow_Buy_index = 5.0

2019.05.20 15:11:16.798 Test_iCustom (EURUSD,H1) Last_Arrow_Sell_volume = -11203799.85975282, Last_Arrow_Sell_index = 50.0


 
Sergey Voytsekhovsky:

这就是 "专家 "标签上的日志条目的样子

2019.05.20 15:11:15.025 Test_iCustom (EURUSD,H1) Last_Arrow_Buy_volume = -11211905.17483469, Last_Arrow_Buy_index = 5.0

而不是创建箭头的价格=-11211905.17483469



 

Sergey Voytsekhovsky:

...

而不是创建箭头的价格= -11211905.17483469

按Ctrl+D,沿着指标的线条 移动鼠标,在数据窗口中看到其缓冲区有哪些数值。

 
Artyom Trishkin:

按Ctrl+D,沿着指标线 拖动鼠标,在数据窗口中查看其缓冲区有哪些数值。

如果我没有理解错的话,我是在房间里寻找一只不存在的猫?数组中没有填入价格,而是填入当时的指标值?谢谢,我会重新考虑的。

最后一个问题 - 编译器给了我两个警告


符号不匹配 Test_iCustom.mq5 79 20

符号不匹配 Test_iCustom.mq5 92 20


我不明白他们的理由,请告诉我。符号不匹配"(Yandex翻译器)是什么意思?


 
Sergey Voytsekhovsky:

如果我没有理解错的话,我是在房间里寻找一只不存在的猫?数组中没有填入价格,而是填入当时的指标值?谢谢,我会重新考虑的。

最后一个问题 - 编译器给了我两个警告


符号不匹配 Test_iCustom.mq5 79 20

符号不匹配 Test_iCustom.mq5 92 20


我不明白他们的理由,请告诉我。"符号不匹配"(Yandex翻译器)是什么意思?


你可能正在失去一个数字符号。显示这几行代码。

 
Artyom Trishkin:

你可能正在失去一个数字符号。显示这几行代码。

for(n=0; n<period_find; n++)
第二个是完全一样的(循环寻找Arrows数组中的非零值)。
 
Sergey Voytsekhovsky:
第二个是完全相同的(循环寻找数组 "箭头 "中的非零值)。

变量n 和 period_find 的类型是什么 他们没有展示的最重要的东西...

试试吧。

for(n=0; n<(int)period_find; n++)

为什么要在OnTick()处理程序一级声明一个循环变量?

你可以这样做。

for(int n=0; n<(int)period_find; n++)

你可以从OnTick()中删除n声明--我们不需要它。

 
Artyom Trishkin:

变量 n 和 period_find 的类型是什么?最重要的是,并没有显示...

uint            period_find = InpPeriodFind;       //Number bars for calculate
int             n=0;