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

 
Artyom Trishkin:
  1. There is a signal to open a Buy position, for example.
  2. Find in the order history the most recently closed trade.
  3. see its type,
    1. If it is Sell, you can open Buy ----> return(ORDER_TYPE_BUY);
    2. if it is a Buy, then
  4. see what kind of profit this Buy position was closed with.
    1. If it is negative, we can open a Buy ----> return(ORDER_TYPE_BUY);
    2. If it is positive, we cannot open a new Buy ----> return(WRONG_VALUE);
   double ma;
   int    res;
   bool nomber = OrdersHistoryTotal();
   bool tip=OrderType();
   if(OrderSelect(nomber,SELECT_BY_POS,MODE_HISTORY)==true)
   {
   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;
     }

I wrote it here but it still does not work. What is wrong? Please advise.

 

Good afternoon.

How to write the condition in the four: if the first Friday of the month was a bull, and

Thesecond Monday is bearish, then we open a sell trade.

 
Darirunu: Write the condition: if the first Friday of the month was a bullish one, and

the second Monday is bearish then open a sell trade.

Now this is an interesting problem: it can show the sequence of steps to solve any problem
Determine the current month MM and year YYYY. Take the date 1.MM.YYYY and determine the day of the week for it.
2. Think of a formula or two (for this we make up two tables of 7 rows) and use these formulas to determine the dates of the days in which you are interested
3. If the second date in the future - output.
4. Using the dates we determine the numbers of corresponding bars on the daily chart
5. Determine the number of bars by their belonging to the bulls - bears.
6. Making a conclusion about entering the market

Совершение сделок - Торговые операции - Справка по MetaTrader 5
Совершение сделок - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением...
 
LRA:

This is an interesting problem: it can be used to show a sequence of steps to solve any problem
Determine the current month MM and year YYYY. Take the date MM.YYYY and determine the day of the week for it.
2. Think of a formula or two (for this we make up two tables of 7 rows) and use these formulas to determine the dates of the days in which you are interested
3. If the second date in the future - output.
4. Using the dates we determine the numbers of corresponding bars on the daily chart
5. Determine the number of bars by their belonging to the bulls - bears.
6. Making a conclusion about entering the market


In fact, I still haven't seen the answer in the form of a code ... The algorithm is clear ...

 
Darirunu: In fact, I still haven't seen an answer in the form of a code... The algorithm is clear...

If the algorithm is clear, write a program... If you have difficulties, ask...

 
LRA:

If the algorithm is clear - write a program... If you have problems - ask ...


You must be a genius)) You think if I knew I would ask here? Just write the day of the week is not a problem ... The question is how to determine what week of the month? The Mt4 book doesn't say anything about it.

Any questions from newbies in MQL4, help and discussion on algorithms and codes

 
Lowech:
   bool nomber = OrdersHistoryTotal();
   bool tip=OrderType();
   if(OrderSelect(nomber,SELECT_BY_POS,MODE_HISTORY)==true)
   {
   tip=OrderType();
   }

Here I have preselected it, but it still doesn't work. What's wrong? Please advise.

Let's look at this part. In the first line, the variable nomber stores the number of orders in the history. Let's put the cursor on OrdersHistoryTotal() and press F1. Here you can see:

intOrdersHistoryTotal();


The function returns an integer number. But a bool has only two values. Well, how can a bool contain a value of int type?

The second line contains the same error and one more. You put the cursor on OrderType() and press F1. We see:The order must be preselected using the OrderSelect() function.

The third line contains a horrible situation. 1) if(OrderSelect( - if an order is selected, something is executed. But what if an error occurs here? Your program is still running. 2) An order with the number nomber should be selected. But is there an order with such a number? What is the minimum and maximum order number if the total number is nomber? 3) Instead of if(OrderSelect(nomber,SELECT_BY_POS,MODE_HISTORY)==true) almost anyone would write simply if(OrderSelect(nomber,SELECT_BY_POS,MODE_HISTORY)) and one more little thing.

My advice is this - start learning the language with simple elements, write simple scripts and display the result. Check the result of each line

 
Darirunu: The thing is how do you determine which week of the month it is? There is nothing in the Mt4 book about

Why do you need to know which week of the month it is? It's not in my algorithm. (only put a space after punctuation marks)

 
LRA:

Why do I need to know what week of the month it is? In my algorithm, it does not. (put a space only after punctuation marks)


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?)

 
Darirunu:

In fact, I never saw an answer in the form of a code ... The algorithm is clear ...

You just need to know what day of the week the first of the month was. The rest is calculated.