Questions from Beginners MQL5 MT5 MetaTrader 5 - page 646

 
Tra-der:
There are two MT5 terminals. Problem: can I write scripts to allow only long trades in one terminal and only short trades in the other?
#define ORDER_TYPE_BUY ORDER_TYPE_BUY_STOP   // поставить в самом начале советника, если нужно отказаться от BUY-сделок
#define ORDER_TYPE_SELL ORDER_TYPE_SELL_STOP // поставить в самом начале советника, если нужно отказаться от SELL-сделок
 
Tra-der:
There are two MT5 terminals. Task: Is it possible to write scripts to allow only long trades in one terminal and only short trades in the other?

Simply enter an input parameter into your EA and depending on the value assigned to it when you start, you will either only buy or only sell:

input bool Long=true;            // allow only "Long"
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
...
void OnTick()
  {
   if(!Long)
      trade.Sell(0.01);
   if(Long)
      trade.Buy(0.01);
  }
 
Artyom Trishkin:

In order to know if it is a new top or bottom, you need to remember the time of the last top/top you found, and compare it with what you have found so far.

Thank you, it's clear with the buffer.

In order to remember the time of the last vertex found, you need to know it somehow.

How to do it, how to know the time of the last vertex found?

 
mila.com:

Thank you, the buffer is clear.

In order to remember the time of the last vertex found, you need to know it somehow.

How to do this, how to know the time of the last vertex found?

You declare a static variable to store the time of the previous extremum of the zigzag and initialize it with zero.

2. Find a vertex and if its time is not equal to the time in the static variable, consider that you have found the required extremum and memorize the new time in this variable.

3. GoTo(2);

 

Comrade programmers!

Recommend a way to find out if the spread has increased.

The problem is the following: during the transition to a new day brokerage company widens spread, and sometimes it is crazy for some pairs - it exceeds by 3-5 times the normal value. Daylight-saving spreads are different in brokerage companies with time change from 23 to 59 and from 20 to 59 and so on.

For some guys the spread does not change much, so we cannot cut off the "Working by time" robot because if the spread does not change, we will not have to prohibit trading.

The main question is how to detect that the spread is too large and therefore prohibit the robot from opening a position. I see a variant of storing spread sizes in a file for each new bar for the last 5-7 bars, then adding it all and dividing by the number, thus getting the average spread and multiplying by 1.2 - 1.4 (margin), but I don't think it is interesting to save and multiply files and I am not sure that it is the correct solution for calculation of the average spread size. If I manually enter the maximum allowable spread in the settings, it's very trivial and uninteresting in terms of bot operation.

Please advise the optimal solution for the question, that would not be afraid of rebooting the terminal, and emergency shutdown in case of power outage. Also, preferably a solution that minimizes the load on the program, so it does not recalculate on every tick.

Thank you!

 
Vitaly Muzichenko:

Comrade programmers!

Recommend a way to find out if the spread has increased.

The problem is the following: during the transition to a new day brokerage company widens spread, and sometimes it is crazy for some pairs - it exceeds by 3-5 times the normal value. Daylight-saving spreads are different in brokerage companies with time change from 23 to 59 and from 20 to 59 and so on.

For some guys the spread does not change much, so we cannot cut off the "Working by time" robot because if the spread does not change, we will not have to prohibit trading.

The main question is how to detect that the spread is too large and thus prohibit the robot from opening a position. I see a variant of storing spread sizes in a file for each new bar for the last 5-7 bars, then adding it all and dividing by the number and thus getting the average spread and multiplying by 1.2 - 1.4 (margin), but it is not interesting to save and multiply files. If I manually enter the maximum allowable spread in settings, it's very trivial and uninteresting in terms of bot operation.

Please advise what would be the best solution to this question. Thank you!

It may be trivial, but I enter the limit manually. And if on New Year's Eve for the last N candles the spread will be 3 times bigger than usual, and at night it will be even 3 times bigger ? The analysis system will consider it as a normal x3 spread. I think if a person is trading on real account, it is not difficult for him to manually estimate the average working spread and set the threshold. Although the solution of your question would be interesting to me too)
 
What kind of TC logic is that so dependent on the spread!
 
fxsaber:
What kind of TS-logic is this spread-dependent?!

OK, let's put it this way. Here, for example, the spread widens not even three times, but more, and if you enter the market with a spread of 20pp, while the normal spread is 4-6pp, then it is not normal, and we need to cut off these moments.

 
Vitaly Muzichenko:

OK, let's put it this way. For example, the spread here is not even three times wider, but more, and if you enter the market with a spread of 20pp, while the normal spread is 4-6pp, this is not normal, and we need to cut these points off.

So, focus on bid if you are going to do SELL. What difference does it make what spread? Ok, I won't interfere again.
 
Vitaly Muzichenko:

OK, let's put it this way. For example, the spread here is not even three times wider, but more, and if you enter the market with a spread of 20pp, while the normal spread is 4-6pp, this is not normal, and we need to cut these points off.

Global won't help?
Reason: