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

 

I don't understand any of this. My question was moved by the moderator from MKL5 to MKL4. Followed the link - yes, my question is hanging there, but the last answer is 5.02.2018. Came here - also MKL4 and life is boiling...So why is the moderator throwing in a dead thread? Alright, let's move on. Now to the point: throwing my "problem" over here.


Vladimir Karputov:

For condition 1, put the magic number ID +1, for condition 2 magic number +2 and so on. That way you can then understand that this position was opened by condition 1 or by condition 2 ...

Afternoon. I have only succeeded for one position BAY. The magik set for sell does not work for some reason. Everything is absolutely identical, except for the magician of course. What have I done wrong?

int total=OrdersTotal();

      for(int i=OrdersTotal()-1;i>=0;i--)

      {

        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

         {

         if(TimeCurrent()>OrderOpenTime()+100 && OrderTicket() && OrderType()==OP_BUY && (MathAbs(WPR1)<5))

         rez =  OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),int(MarketInfo(OrderSymbol(),MODE_DIGITS))),slippage,Yellow); 

        

         if(TimeCurrent()>OrderOpenTime()+100 && OrderTicket() && OrderType()==OP_BUY && OrderMagicNumber==111 && MathAbs(WPR1)<20)

         rez =  OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),int(MarketInfo(OrderSymbol(),MODE_DIGITS))),slippage,Yellow);

      

         if(TimeCurrent()>OrderOpenTime()+100 && OrderTicket() && OrderType()==OP_SELL && OrderMagicNumber==222 && MathAbs(WPR1)>97.55)

         rez =  OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),int(MarketInfo(OrderSymbol(),MODE_DIGITS))),slippage,Yellow); 

           

         if(TimeCurrent()>OrderOpenTime()+100 && OrderTicket() && OrderType()==OP_SELL && MathAbs(WPR1)>96)

         rez =  OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),int(MarketInfo(OrderSymbol(),MODE_DIGITS))),slippage,Yellow);               

         }

       continue;  

      } 
 
novichok2018:

I don't understand any of this. My question was moved by the moderator from MKL5 to MKL4. Followed the link - yes, my question is hanging there, but the last answer is 5.02.2018. Came here - also MKL4 and life is boiling...So why is the moderator throwing in a dead thread? Alright, let's move on. Now to the point: throwing my "problem" over here.


Afternoon. It only worked for one position BAY. The magik set up for SELL doesn't work for some reason. All is absolutely identical, except for the magician itself of course. What did I do wrong?

1. it does not know mql4.

2. To close an order with magic 222 it should be opened with magic 222 first. Look at which wizard opens SELL orders

3. After the OrderMagicNumber, there should be brackets ().

if(TimeCurrent()>OrderOpenTime()+100 && OrderTicket() && OrderType()==OP_SELL && OrderMagicNumber==222 && MathAbs(WPR1)>97.55)

4. Why is the highlighted in the condition?

if(TimeCurrent()>OrderOpenTime()+100 && OrderTicket() && OrderType()==OP_BUY && (MathAbs(WPR1)<5))
 

Guys, here's a question - how do I put variable values into a one-dimensional array?

Don't send it to help - there is NO example there for such a problem.


Let's say there is a variable a, which changes under certain conditions.

I want an array to store the last 3 values of this variable. How this is implemented in mql4?


I'm writing int mas[3];

mas[]=a; inside the loop, after a condition that changes a,

The compiler gives out ']', but nothing works, although logically it should. - It wants me to put some unknown expression into mas[]=a inside the parentheses.

Does MQL4 have any function that fills the array with a variable value at each loop iteration?


 
John Smith:

Guys, here's a question - how do I put a variable value into a one-dimensional array?

Don't send it to help - there is NO example there for such a problem.


Let's say there is a variable a, which changes under certain conditions.

I want an array to store the last 3 values of this variable. How this is implemented in mql4?


I'm writing int mas[3];

mas[]=a; inside the loop, after a condition that changes a,

The compiler gives out ']', but nothing works, although logically it should. - expression expected, it wants me to put some unknown expression inside of brackets in mas[]=a.

Does MQL4 have any function that fills the array with a variable value at each iteration of the loop?


Which cell of the array do you think the value of variable 'a' is placed in, like this: mas[]=a; ?

I'd send you to the help, read from the beginning :)

 
John Smith:

Guys, here's a question - how do I put variable values into a one-dimensional array?

Don't send it to help - there is NO example for such a problem.


Let's say there is a variable a, which changes under certain conditions.

I want an array to store the last 3 values of this variable. How this is implemented in mql4?


I'm writing int mas[3];

mas[]=a; inside the loop, after a condition that changes a,

The compiler gives out ']', but nothing works, although logically it should. - It wants me to put some unknown expression inside of brackets in mas[]=a.

Does MQL4 have any function that fills the array with a variable value at each loop iteration?


Maybe, you should read not only the code samples, but some other letters as well.

Here is a quote from the documentation:

Group of functions for working with arrays

No more than four-dimensional arrays are allowed. Each dimension is indexed from 0 to dimension_size-1. In a particular case of a one-dimensional array of 50 elements, calling the first element is array[0], the last one is array[49].

 
Alexey Viktorov:

1. he does not know mql4.

2. To close an order with magic 222 it must first be opened with magic 222. Look at which wizard opens SELL orders

3. After the OrderMagicNumber, there should be brackets ().

4. Why is it marked in the condition?

Thank you for your reply. It's clear that I need to open with a magik first. I've removed the orderticket and checked the logic with comments. It turned out that the closing of positions is done according to the conditions of the first open position. That is, if first you open a Buy or Sell position with Condition 1 and then a second position opened with the same condition but with Condition 2, the closing condition is ignored and the second position is also closed with Condition 1 despite the other Magic.

I applied break after the order has been closed but the solution has been half-hearted:only if one position of the same type is opened. If, for instance, a Sell position has been opened first and has not yet been closed yet, while a Buy position is being opened and closed, the Sell position does not see any conditions to be closed until another Sell position is opened and closed (in accordance with its conditions). And if BAY opens and closes again, it again misses its closing conditions. So what to do?

 
Good afternoon all. Dear programmers, please help me insert a line with the ability to specify a sound file for each Alert3.Lv1;2;3, to trigger a different sound that you specify. I myself am not good at coding and programming.
Files:
 
Good day mister programmers and MQL connoisseurs! I have a very good Expert Advisor that stops auto-trading based on the news. I have found one on the net that either does not work or works poorly. Or may someone write one based on the urdala indicator?
 
Hi guys. Can you tell me how to get rid of the [Trade context is busy] error?
 
Rustam Bikbulatov:
Hi guys. Can you tell me how to get rid of the [Trade context is busy] error?
if(!IsTradeContextBusy())   //торговый поток свободен
  {
 // здесь оформляем запрос
 // на торговую операцию

  }
Reason: