Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1212

 
Vitaly Muzichenko:

OK, I'll look for a mon with 4K.

Where is this picture from?

 
Alexey Viktorov:

Where is this picture from?

Sent from 4K

 
Vitaly Muzichenko:

Sent with 4K

Well, can you check again I suppose? Or not?

 
Alexey Viktorov:

Well, can you check again I suppose? Or not?

Not desirable)

 
How to get the value of MQL5 program version defined by property# version in the code ?
 
leonerd:
How to get the value of MQL5 program version defined by property# version?

It turns out that you can't, because inPredefined macro substitutions

Constant

Description

__DATE__

Date when file was compiled without time (hours, minutes and seconds are 0)

__DATETIME__

Date and time when the file was compiled

__LINE__

Line number in the source code where the macro is located

__FILE__

Name of the file being compiled

__PATH__

Absolute path to the current compiled file

__FUNCTION__

Name of the function in the body of which the macro is located

__FUNCSIG__

Function signature in the body of which the macro is located. The function description with types of parameters can be useful in identification ofoverloaded functions

__MQLBUILD__, __MQL5BUILD__

Number of the compiler build


no such variable

Документация по MQL5: Константы, перечисления и структуры / Именованные константы / Предопределенные макроподстановки
Документация по MQL5: Константы, перечисления и структуры / Именованные константы / Предопределенные макроподстановки
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
leonerd:
How to get the value of MQL5 program version defined by property# version?

I use this, I couldn't find any other option. You need to specify the version twice, but it's not that difficult

#property version     "23.25" // 16.04.2020
#define   version     "23.25"
 

Good day, dear experts.

Could you please tell me where in the code there is an error that prevents opening BUY position on the same bar with SELL that has closed the previous position?

The rules are simple (to learn):
1 Entry - slow indicator crossing 0 + fast also in the zone (buy/sell)

2 Exit - crossing by fast indicator 0

//+------------------------------------------------------------------+
//|                                                      TestDPO.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Trade\Trade.mqh>
CTrade trade;

input int dpo_fast_period = 9;  // DPO Fast Period
input int dpo_slow_period = 40; // DPO Fast Period
input int magic = 1000;         // Magic советника
input ulong slippage = 10;         // Проскальзывание цены
input double volume = 0.1;      // размер позиции

int DPO_fast;                 // Хэндл для быстрого DPO
int DPO_slow;                 // Хэндл для медленного DPO


double fDPOVal[];                 //Динамический массив для хранения значений fast DPO
double sDPOVal[];                 //Динамический массив для хранения значений slow DPO

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {



   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---------------Задаем цены покупки и продажи------------------------
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

   int signal=0;  // сигнал на покупку, продажу

//--------------Проверка на новый бар
   if(!isNewBar())
      return;
//--------------------------------------------------------------------

   DPO_fast=iCustom(NULL,0,"Examples\\DPO",dpo_fast_period);   // получаем хэндлы для быстрого
   DPO_slow=iCustom(NULL,0,"Examples\\DPO",dpo_slow_period); // получаем хэндлы для медленного


   ArraySetAsSeries(fDPOVal,true);              //задаем направление индексов массива
   ArraySetAsSeries(sDPOVal,true);
   if(CopyBuffer(DPO_fast,0,0,10,fDPOVal)<0)    // наполняем массив значений DPO fast
     {
      Alert("Ошибка копирования буфера индикатора fast DPO. Ошибка ", GetLastError());
     }
   if(CopyBuffer(DPO_slow,0,0,10,sDPOVal)<0)    // наполняем массив значений DPO slow
     {
      Alert("Ошибка копирования буфера индикатора slow DPO. Ошибка ", GetLastError());
     }

   double DPO_fast_c_value=NormalizeDouble(fDPOVal[1],6);  // запоминаем значение индикатора DPO fast на предыдущем баре
   double DPO_slow_c_value=NormalizeDouble(sDPOVal[1],6);  // запоминаем значение индикатора DPO slow на предыдущем баре
   double DPO_fast_p_value=NormalizeDouble(fDPOVal[2],6);  // запоминаем значение индикатора DPO fast на пред-предыдущем баре
   double DPO_slow_p_value=NormalizeDouble(sDPOVal[2],6);  // запоминаем значение индикатора DPO slow на пред-предыдущем баре

   if(DPO_slow_c_value>0 && DPO_slow_p_value<0 && DPO_fast_c_value>0)  // если медленный индикатор пересекает 0 снизу вверх и быстрый находится выше 0
      signal=1;                                                           // сигнал на открытие покупки
   if(DPO_slow_c_value<0 && DPO_slow_p_value>0 && DPO_fast_c_value<0)  // если медленный индикатор пересекает 0 сверху вниз и быстрый находится ниже 0
      signal=-1;                                                          // сигнал на открытие продажи
   if(DPO_fast_c_value>0 && DPO_fast_p_value<0)                       // если быстрый индикатор пересекает 0 снизу вверх
      signal=-2;                                                           // сигнал на закрытие продажи
   if(DPO_fast_c_value<0 && DPO_fast_p_value>0)                       // если быстрый индикатор пересекает 0 сверху вниз
      signal=2;                                                          // сигнал на закрытие покупки

switch (signal)
         {
         case -1:
         trade.Sell(volume,NULL,Bid,0,0,NULL);
         break;
         case 1:
         trade.Buy(volume,NULL,Ask,0,0,NULL);
         break;
         case -2:
         trade.PositionClose(_Symbol,slippage);
         break;
         case 2:
         trade.PositionClose(_Symbol,slippage);
         break;
	}
  }
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
Задавайте вопросы по техническому анализу, обсуждайте торговые системы и улучшайте свои навыки программирования торговых стратегий на языке MQL5. Общайтесь и обменивайтесь опытом на форуме с трейдерами всего мира и помогайте ответами новичкам — наше сообщество развивается вместе с вами. Как я собираю себе советника методом тыка Из этих...
 
Andrey.Sabitov:

Good afternoon, esteemed experts.

Could you please tell me where in the code there is an error that prevents to open BUY position on the same bar with SELL that closed a previous position?

The rules are simple (to learn):
1 Entry - slow indicator crossing 0 + fast also in the zone (buy/sell)

2 Exit - fast indicator crossing 0 line

All works correctly: opening conditions crossing of slow indicator 0 line, only fast indicator crossed 0 line in the specified place.

A condition must be added to open a position at the specified location, slow in the same area and fast crosses the 0 line

 
Andrey.Sabitov:

Good day, dear experts.

Could you please advise where in the code there is an error that prevents BUY position from opening on the same bar with SELL, which has closed a previous position?

The rules are simple (to learn):
1 Entry - slow indicator crossing 0 + fast also in the zone (buy/sell)

2 Exit - crossing by fast indicator 0

You are making a gross error: You ARE creating TWO INLIKERS FOR EACH TICK!

//--------------------------------------------------------------------

   DPO_fast=iCustom(NULL,0,"Examples\\DPO",dpo_fast_period);   // получаем хэндлы для быстрого
   DPO_slow=iCustom(NULL,0,"Examples\\DPO",dpo_slow_period); // получаем хэндлы для медленного

Indicator handle MUST be created once at OnInit.


Please read theiCustom help.

Основы тестирования в MetaTrader 5
Основы тестирования в MetaTrader 5
  • www.mql5.com
Идея автоматической торговли привлекательна тем, что торговый робот может без устали работать 24 часа в сутки и семь дней в неделю. Робот не знает усталости, сомнений и страха,  ему не ведомы психологические проблемы. Достаточно четко формализовать торговые правила и реализовать их в виде алгоритмов, и робот готов неустанно трудиться. Но прежде...
Reason: