Hello, dear friends.
Please suggest a solution, how can the existing Expert Advisor expertmapsarsizeoptimized programmatically allow the opening of new orders only in a certain period of time of day?
Preferably without significant changes in the code.
I broke my head how to do it beautifully.
How to allow trading at certain times
Share
alexeyvik
Oh, my God!!! help me pass by in silence…
operlay
example of the adviser’s work from 11 to 12 days.
//+------------------------------------------------------------------+
//| restrictionTimeOperation.mq4 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "
#property version "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
MqlDateTime mqldt;
if (mqldt.hour >= "11" && mqldt.hour <= "12") {
//your code
Alert("startTick; 11 Hour");
}
//--- return value of prev_calculated for next call
return(rates_total);
}
if from 11 to 12 and from 15 to 16
replace
if ((mqldt.hour >= "11" && mqldt.hour <= "12") ||
(mqldt.hour >= "15" && mqldt.hour <= "16")
) {
//your code
Alert("startTick; 15 Hour/");
}
Read about conditional operators
anatoli_51
hello tell me how to enter the time of permission to trade in this adviser flat adviser and turn off the time of the london and american trading session was very good thank you to everyone who will help
vladon
the main thing is that it works for you, I just noticed
st2050
to sergeev
Thanks. further implementation is clear.
lazarev-d-m
if (mqldt.hour>=22||mqldt.hour>=0&&mqldt.hour<=2)
{
//your code
}
a few modifications and everything works again
I used this method in my program in general
if (
(mqldt.day_of_weak==1&&mqldt.hour==1&&mqldt.min>=0&&mqldt.min<=10) | /
...
//there are 20-50 such conditions for each pair
...
(mqldt.day_of_weak==5& & mqldt. hour==16&&mqldt. min>=>0&&mqldt. min<=10)
)
{
//code
}
sergeev
if you even know where the opening occurs, what prevents you from inserting it here?
st2050
to sergeev:
The Expert Advisor expertmapsarsizeoptimized. mq5 is available in the standard set of the MT5 terminal. It can be seen in the navigator (Expert Advisors>Advisors), it is located in the mql5expertsadvisors folder.
If necessary, I will post the text.
The order is opened not in the Expert Advisor file itself, but in the includeexpertexpert.mqh module. However, the code of trailing stop is in the module IncludeExpertTrailingTrailingParabolicsar.mqh. Thus, the code is scattered in different files.
Therefore, the question was: how to modify the adviser beautifully and effectively.
vladon
and if the end of the period= 2 and the beginning of the period=22
???
then your code is not correct
lazarev-d-m
My Expert Advisor is based on trading at a certain time
after #include #property (at the beginning of the code), insert
mqldatetime mqldt;
in your main function OnTimer/onTick, insert thisTimeCurrent(mqldt) after curly brackets);
next, insert all the working code inside this
OnTimer
thus, the EA will only work at a certain time, the only drawback is that you can skip some event, so it is more convenient to push not the entire code inside the if statement, but only the part that is responsible for opening an order{
if (mqldt.hour>=>"period start"& & mqldt. hour>=>"period end"
{
//your code
}
}
sergeev
??? neither the adviser nor the text has not been seen. therefore, this is a purely theoretical bazaar.
so what’s the matter? open it.
st2050
Comrades, I know how to open an order at a certain time.
The question was how to modify this particular Expert Advisor with its specific text. It’s not all that obvious.
As for the offer of GODZILLA (by the way, thank you so much for your posts), will not the modification of the order be prohibited in this case? I only need to block the opening of new ones.
godzilla
Well, redo my function a little and that’s it!
abolk
Yedelkin:
“How to allow trading at a certain time” is very simple. Prohibit sending requests at certain times. Type if(date=date) return;
a small clarification “<=”.
usually when they say ” prohibit trading from 8:00 to 12:00 – they mean “allow from 12:00”.
yedelkin
“How to allow trading at a certain time” is very simple. Prohibit sending requests at certain times. Type if(date
sergeev
if (Current hour >= required start & & current hour < required completion )
{
// open an order
}