Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1120
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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)?
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() если текущий день не равен установленному дню
// тут остальной код советника.
}
//+------------------------------------------------------------------+
...
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.
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?
...
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);
default: return( true);
}
}
There is a ban on trading on Thursdays
You can make it a little bit more beautiful, it all depends on the task:
#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?
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.