Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1120

 
RichLux:

I have an EA, I want it to be able to choose which days to trade on, and which not.

Mon - false

Tues - true

Cp- ...

Please advise how to implement it?

DayOfWeek

Returns the sequential number of the day of the week of the last known server time.

intDayOfWeek();

Returned value

Sequential number of the day of the week (Sunday-0,1,2,3,4,5,6).

Note

During testing, the last known server time is simulated.

Example:

// does not work on weekends.
if(DayOfWeek()==0 ||DayOfWeek()==6)return(0);

 

DayOfWeek

Returns the sequence numberof the day of the week of the last known server time.

Thanks, that makes more sense.

I can't figure out how to implement selecting trading days in external parameters now. In details, I want one and the same Expert Advisor to trade on one trade pair on Monday, and not to trade on another one.

How to write it in "extern" and then implement it in condition (if...else)?

 
RichLux:

DayOfWeek

Returns the sequence numberof the day of the week of the last known server time.

Thanks, that makes more sense.

I can't figure out how to implement selecting trading days in external parameters now. In details, I want one and the same Expert Advisor to trade on one trade pair on Monday, and not to trade on another one.

How to write it in "extern" and then implement it in condition (if...else)?

here is a simple example allowing to trade on Monday only. This code works in MT4 and MT5

//+------------------------------------------------------------------+
//|                                                       test08.mq4 |
//|                                                   Sergey Gritsay |
//|                         https://www.mql5.com/ru/users/sergey1294 |
//+------------------------------------------------------------------+
#property copyright "Sergey Gritsay"
#property link      "https://www.mql5.com/ru/users/sergey1294"
#property version   "1.00"
#property strict

input ENUM_DAY_OF_WEEK dayofweek=MONDAY;

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

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

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   TimeToStruct(TimeCurrent(),time);
   if(time.day_of_week!=dayofweek)return; // выйдем из OnTick() если текущий день не равен установленному дню
  
   // тут остальной код советника.
  }
//+------------------------------------------------------------------+


...

 
RichLux:

DayOfWeek

Returns the sequence numberof the day of the week of the last known server time.

Thanks, that makes more sense.

I can't figure out how to implement selecting trading days in external parameters now. In details, I want one and the same Expert Advisor to trade on one trade pair on Monday, and not to trade on another one.

How to write it in "extern" and then implement in condition (if...else)?

Use enumeration ENUM_DAY_OF_WEEK

At the very end of the page.

Информация об инструменте - Состояние окружения - Стандартные константы, перечисления и структуры - Справочник MQL4
Информация об инструменте - Состояние окружения - Стандартные константы, перечисления и структуры - Справочник MQL4
  • docs.mql4.com
Информация об инструменте - Состояние окружения - Стандартные константы, перечисления и структуры - Справочник MQL4
 

void OnTick()
{
//---
TimeToStruct(TimeCurrent(),time);
if(time.day_of_week!=dayofweek)return; // quit OnTick() if current day is not equal to set day

// here the rest of EA code
}
//+------------------------------------------------------------------+


...

Thank you!

Really, now we have to deal with the point, that each pair has a different number of "working" days.

Probably need to enter 5 variables:dayofweek1,dayofweek2,...?

But again, what should I enter in the remaining 2 variables if there are 3 trading days?

 
Good afternoon, could you please tell me how to solve this problem? There is a code with entry on M15, but the signal from H1 is taken into account. While there is a signal on H1, on M15 the indicator gives several signals. The question is to limit it to one (i.e. the first signal).
Files:
nsm.txt  1 kb
 
RichLux:


...

Thank you!

Now, though, we need to deal with the fact that each pair has a different number of "working" days.

Probably need to enter 5 variables:dayofweek1,dayofweek2,...?

But again, what should I enter in the remaining 2 variables if there are 3 trading days!

We may try to do it this way:

#property strict

//-
enum YesNo {
_no       = 0, // NoTrade
_yes      = 1  // Trade
};
//-
sinput YesNo day1 = _yes; // Пн
sinput YesNo day2 = _yes; // Вт
sinput YesNo day3 = _yes; // Ср
sinput YesNo day4 = _no;  // Чт
sinput YesNo day5 = _yes; // Пт


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

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//--

 // здесь какой-то код, например закрытие

  ... 

 // проверка запрета на торговлю
  if(TradeAllow()) return;
   // далее код
  
}

//+------------------------------------------------------------------+
//| Разрешение на торговлю по дням                                   |
//+------------------------------------------------------------------+
bool TradeAllow() {
TimeToStruct(TimeCurrent(),time);
  switch(time.day_of_week) {
   case 1 : return(!day1);
   case 2 : return(!day2);
   case 3 : return(!day3);
   case 4 : return(!day4);
   case 5 : return(!day5);
   defaultreturntrue);
  }
}

There is a ban on trading on Thursdays

You can make it a little bit more beautiful, it all depends on the task:

#property version   "1.00"
#property strict

//-
enum YesNo {
_no       = 0, // No trade
_yes      = 1  // Trade
};
//-
sinput YesNo day1 = _yes; // Пн
sinput YesNo day2 = _yes; // Вт
sinput YesNo day3 = _yes; // Ср
sinput YesNo day4 = _no;  // Чт
sinput YesNo day5 = _yes; // Пт


MqlDateTime time;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//--
  if(TradeAllow()) {
    ClosePos(); // Только закрытие
  } else {
    ClosePos(); // Закрытие
    OpenPos();  // Открытие
    Function()  // Ещё что-то
  }
  
//-
}
//+------------------------------------------------------------------+
//| Функция закрытия                                                 |
//+------------------------------------------------------------------+
void ClosePos()
{
  // код
}

//+------------------------------------------------------------------+
//| Функция открытия                                                 |
//+------------------------------------------------------------------+
void OpenPos()
{
  // код
}

//+------------------------------------------------------------------+
//| Разрешение на торговлю по дням                                   |
//+------------------------------------------------------------------+
bool TradeAllow() {
TimeToStruct(TimeCurrent(),time);
  switch(time.day_of_week) {
   case 1 : return(!day1);
   case 2 : return(!day2);
   case 3 : return(!day3);
   case 4 : return(!day4);
   case 5 : return(!day5);
   default: return( true);
  }
}
//+------------------------------------------------------------------+
 
Hi all! I use the delta indicator from clusterdelta.com in my MT4 trading. I need a freelancer who could make it so that when a certain threshold in the indicator values is reached, an alert or some other sound is emitted. Can you tell me who to contact about this issue?
 
Lexx1:
Hi all! I use the delta indicator from clusterdelta.com in my MT4 trading. I need a freelancer who could make it so that when a certain threshold in the indicator values is reached, an alert or some other sound is emitted. Can you tell me who to contact about this issue?
There's a blue bar at the top with lots of different letters on it. Look for the word "Freelance" and click on it. I think you know what to do from there.
 

Guys!

When trying to run a timer based EA, the errorCannot set timer (1) pops up.

What can it be associated with? Thanks in advance.