Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 270

 
Artyom Trishkin:
It's enough to know what day of the week the first of the month was. The rest is calculated.

It's like scratching your right ear with your left hand.

 
Darirunu:

I'm sorry, you probably weren't paying attention to the question.

How do you write the condition in the four: if the first Friday of the month was bullish and

the second Monday is bearish then we open a sell trade.

DayOfWeek()==1 Monday is clear, but what Monday of the month?)

Got it! You're talking about your algorithm, which only you know. I have written, determine the day of the week for the first day of the month! And then we use a table or two simple formulas to determine the dates of the days we are interested in.

Check the table on the calendar.

If the first day of the month is 6, then the number of the first Friday is 7. Otherwise, first Friday equals 6 - the day of the beginning of the month.

If day of the month start < 2, second Monday equals 9 - day of the month. Otherwise the second Monday number is 16 - the day of the month.

Using math functions, the remainder of division and the modulus will be much shorter

 
LRA:

Got it! You are talking about your algorithm, which only you know. What I'm saying is, determine the day of the week for the first day of the month! And then we use a table or two simple formulas to determine the dates of the days of interest.

Check the table on the calendar.

If the first day of the month is 6, then the number of the first Friday is 7. Otherwise, first Friday equals 6 - the day of the beginning of the month.

If day of the month start < 2, second Monday equals 9 - day of the month. Otherwise the second Monday equals 16 - the day of the month

Thank you. God bless you... I'll be checking.
 
Darirunu:
Thank you. God bless you. I'll keep checking.

Thank you very much for your wish. And still put a space after the dot and a space before the dot. It will help in programming. Good luck and, if you need it, profits!

 
LRA:

Thank you very much for your suggestions. And you may want to put a space after a full stop and skip a space before a full stop. It will help in programming. Good luck and, if you need it, good luck!


It comes out very complicated. There must be a simpler option. Can anyone share?

Let's say tomorrow something will change in the updates and we will have to rewrite everything.

 
Darirunu:

It comes out very complicated. There must be a simpler option. Can anyone share?

Let's say tomorrow something changes in the updates and we have to rewrite everything.

It is not so difficult. But for each situation we have to set different values, how many daily bars should be copied and which ones should be imported into the structures.

/********************Script program start function********************/
void OnStart()
{
 MqlDateTime mqlDateTime0, mqlDateTime1;
 datetime arrDateTime[7];
 CopyTime(_Symbol, PERIOD_D1, 0, 7, arrDateTime);
 TimeToStruct(arrDateTime[0], mqlDateTime0);
 TimeToStruct(arrDateTime[6], mqlDateTime1);
 if(mqlDateTime0.day_of_week == FRIDAY && mqlDateTime0.mon != mqlDateTime1.mon)
  {
   Print("Ура!!! Сегодня первая пятница");
   // Дальше можно брать по времени пятницы открытие и закрытие бара и на основании этого определяем бычья или медвежья свеча...
  }
}/********************************************************************/

It's better to take the candlestick parameters into the MqlRates structure

 
Alexey Viktorov:

But for each situation you have to set different values, how many daily bars to copy and which ones to put in the structures.



This is what I am talking about and I am only interested in MQL4.

 
Darirunu:

That's what I'm talking about and I'm only interested in MQL4 ...We need to find another solution .

That's what mql4 is.
Files:
00.mq4  2 kb
 
double ma;
   int    res;
   int nomber = OrdersHistoryTotal();
   int tip=OrderType();
   if(OrderSelect(nomber,SELECT_BY_POS,MODE_HISTORY))
   {
   tip=OrderType();
   }
   ma=iMA(NULL,0,MovingPeriod,120,MODE_SMA,PRICE_CLOSE,1);
   if(Bid<ma)
   if(tip!=OP_SELL)
   {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,Bid-TP*Point,"",MAGICMA,0,Red);
      return;
     }



Good afternoon. I need some help. If there is a closed Sell order, then the next order can only be opened Buy.
 
Darirunu:

That's what I'm talking about and I'm only interested in MQL4.

I also have this idea.

If you need the first Friday, the number should be less than 8. If the first Friday of the month is Friday, the next Friday will be the eighth. Accordingly we can easily recalculate to any day of the week and any day, second, third...