Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 846

 
erotin:

Can you tell me what is wrong with the rationing of the lot?

Everything is wrong. Read the article "What checks an EA should pass...". There's a ready-made function there.

 

Done, made an empty template, prepared everything necessary for iCustom() function.

I put the iCrossAD indicator I am interested in into the function.

The function works, it finds the indexes of outermost Up and Down arrows correctly, but the price values at which these arrows were set are wrong.

The code is short, so I will put it right here, I will attach files of this advisor and indicator just in case.

//+------------------------------------------------------------------+
//|                                             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();
  }
Files:
iCrossAD.mq5  49 kb
 

This is what the log entries on the "Experts" tab look like

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:

This is what the log entries on the "Experts" tab look like

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

Instead of the price at which the arrows were created = -11211905.17483469



 

Sergey Voytsekhovsky:

...

Instead of the prices at which the arrows were created = -11211905.17483469

Press Ctrl+D, move the mouse along the lines of the indicator and see in the data window what values its buffers have.

 
Artyom Trishkin:

Press Ctrl+D, drag the mouse along the indicator lines and look in the data window to see what values its buffers have.

If I understood you correctly, I was looking for a cat in the room that is not there? The array was not filled with prices, but with the values of the indicator at that time? Thanks, I'll rethink it.

One last question - the compiler gives me 2 warnings


sign mismatch Test_iCustom.mq5 79 20

sign mismatch Test_iCustom.mq5 92 20


I can not understand their reason, please tell me. What does "sign mismatch" (Yandex translator) mean???


 
Sergey Voytsekhovsky:

If I understood you correctly, I was looking for a cat in the room that is not there? The array was not filled with prices, but with the values of the indicator at that time? Thanks, I'll rethink it.

One last question - the compiler gives me 2 warnings


sign mismatch Test_iCustom.mq5 79 20

sign mismatch Test_iCustom.mq5 92 20


I can not understand their reason, please tell me. What does "sign mismatch" (Yandex translator) mean?


You might be losing a number sign. Show these lines of code.

 
Artyom Trishkin:

You might be losing a number sign. Show these lines of code.

for(n=0; n<period_find; n++)
The second one is exactly the same (loops to find non-zero values in Arrows arrays).
 
Sergey Voytsekhovsky:
The second is exactly the same (loops to find non-zero values in arrays "Arrows").

What are the types of variables n and period_find ? The most important thing they didn't show...

Try it:

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

Why do you declare a loop variable at the level of the OnTick() handler?

You can do it this way:

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

You can remove n declaration from OnTick() - we don't need it there.

 
Artyom Trishkin:

What are the types of variables n and period_find ? The most important thing and didn't show...

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