Questions from a "dummy" - page 44

 

Alex, can you tell me how to compare m_rates[1].low with m_rates[0].close?

m_rates[1].low=m_rates[0].close will it be correct and in general, m_rates[0].close is the last price of the bar which is not yet closed?

and in general, what is the correct way to deal with the last bar without using indicators?(CopyRates, CopyHigh)

 
Makser:

Alex, how can I compare m_rates[1].low with m_rates[0].close?

m_rates[1].low=m_rates[0].close will it be correct and in general m_rates[0].close is the last price of the bar which is not yet closed?

and in general, what is the correct way to deal with the last bar without using indicators? (CopyRates, CopyHigh)

you correctly wrote that you should use CopyRates or CopyHigh/Low/Close, etc. to work with price data outside of indicators.

You can find examples in the help or in the code base.

Документация по MQL5: Доступ к таймсериям и индикаторам / CopyRates
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyRates
  • www.mql5.com
Доступ к таймсериям и индикаторам / CopyRates - Документация по MQL5
 

When compiling the code, a message appears: possible loss of data due to type conversion on the line

datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

and when using the function in the Expert Advisor, it stops working in the tester, please tell me the reason, the code is taken from the article https://www.mql5.com/ru/articles/22

//+------------------------------------------------------------------+
//|                                                 CheckLastBar.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(isNewBar())
     {
      PrintFormat("Новый бар: %s",TimeToString(TimeCurrent(),TIME_SECONDS));
     }
  }
//+------------------------------------------------------------------+
//| Возвращает true, если появился новый бар для пары символ/период  |
//+------------------------------------------------------------------+
bool isNewBar()
  {
//--- в статической переменной будем помнить время открытия последнего бара
   static datetime last_time=0;
//--- текущее время
   datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

//--- если это первый вызов функции
   if(last_time==0)
     {
      //--- установим время и выйдем 
      last_time=lastbar_time;
      return(false);
     }

//--- если время отличается
   if(last_time!=lastbar_time)
     {
      //--- запомним время и вернем true
      last_time=lastbar_time;
      return(true);
     }
//--- дошли до этого места - значит бар не новый, вернем false
   return(false);
  }
//+------------------------------------------------------------------+
Ограничения и проверки в экспертах
Ограничения и проверки в экспертах
  • 2010.08.02
  • MetaQuotes Software Corp.
  • www.mql5.com
Можно ли торговать этим инструментом в понедельник? Хватит ли денег на открытие позиции? Какой размер убытка мы получим, если сработает Stop Loss? Как ограничить количество отложенных ордеров? Была ли выполнена торговая операция на этом баре или это было на предыдущем? Если торговый робот не может сделать подобные проверки, то любая прибыльная торговая система может превратиться в проигрышную. В этой статье показаны примеры проверок, которые пригодятся в любом эксперте.
 
Europa:

When compiling the code, a message appears: possible loss of data due to type conversion on the line

and when using the function in the Expert Advisor, it stops working in the tester, please tell me the reason, the code is taken from the articlehttps://www.mql5.com/ru/articles/22

I am not sure about the tester. About "... type conversion":
   datetime lastbar_time=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);
 

Interesting, but I have a similar one too.Filling a doublearray with double data. It gives the same warning on this line.

CopyBuffer(ma_handle,0,0,13,ma);
 
Karlson:

Interesting, but I have a similar one too.Filling a double array with double data.It gives the same warning on this line.

Maybe it's the ambiguous interpretation of the constants (0,0,13). The CopyBuffer has three variants of call. Try to substitute variables of needed type as parameters or use explicit type conversion for constants.
 
Thanks, I'll try it. I've already tried the conversion, the explicit conversion goes through, if I translate a mask handle with (int), but that doesn't suit me of course :-)
 
Karlson:
Thanks, I'll give it a try. I've already tried the conversion, the explicit conversion goes through, if I translate a mask handle via (int), but that doesn't suit me of course :-)
Wait a second. What is your handle's type?
 

Got it wrong. Need an int.

int  iMA(
   string               symbol,            // имя символа
   ENUM_TIMEFRAMES      period,            // период
   int                  ma_period,         // период усреднения
   int                  ma_shift,          // смещение индикатора по горизонтали
   ENUM_MA_METHOD       ma_method,         // тип сглаживания
   ENUM_APPLIED_PRICE   applied_price      // тип цены или handle
   );

Thank you.

 
I have a few questions too. Where are the moving average crossover signal modules? Where are the alligatora signals? One more thing. Each indicator has several types of signals. How to make MACD accept only zero crossing signals?
Reason: