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

 
Artyom Trishkin #:

In your code, if one position is open, another position will not open on the opposite signal. That is, first of all, when the signal comes in, you need to check if there is an opposing position and close it.

But again, this all greatly limits the possibilities to improve the strategies.

We should avoid binding to the presence/absence of orders (especially in four - pending orders (which is correct) and positions (which is wrong)).

No, it is correct and necessary to have the number of orders and positions by their types at hand. But it is wrong to rely on the absence of any orders only for the signals.

In general, the correct way is to have functions to calculate orders and positions (one function that fills the structure when changes the number of orders and positions), functions to open/close positions, functions to set orders and alarm functions. Plus, the ability to compare position data (open or closed) with some values.

Any strategy can be built from this set.

Artem, the strategy there is one order in the market until it closes at TP or SL.
 
MakarFX #:

Your code

(A bar opened and no orders)

Checked the signal - no signal

... Wait for the next bar.

You repeated the same mistake as last time

P.S.

it's

must be carried out after the order has been opened

Actually my code was designed for something else. For a robot that only trades at opening prices. I simply took it from me and added it to the code of alaw-abiding citizen user and changed it according to the comments. All the nuances cannot be considered at once. You only see them during testing of the robot.

But there is one thing. You also seem to have taken everything into consideration. A signal has been received and the function bSignalSell orbSignalBuy has sent a command to open an order and returned true (the first point). The second point is that no order has yet been opened (the command is waiting for its turn in the terminal). Then, when the command queue comes up, it is sent to the server (this is still time). On the server it is executed. Or server refuses to execute it for one of a number of possible reasons (see documentation for details). Or it doesn't get there (interference, bad connection and other network bugs). And your robot thinks that it has opened an order and updates the bar opening time. It is fine. But that order does not show up in the list of open orders. Thus, imagine that you have 0 orders in the list and the robot "thinks": "It's OK, I have entered the market. As a result, there is a signal during a whole bar after an unsuccessful entry, but the Expert Advisor does not "see" it and does nothing. Is such a situation possible? It is possible! So, your code is not very good. You'd better think better. Or let the law-abiding citizen think. Unfortunately, I can't right now. I'm working on a very interesting project. And creating a proper fully working EA with all of its mechanisms makes sense only for a good, profitable trading system. The robot can be simply run in the Strategy Tester and see whether it is another one of my version or the one developed by you. It does not make any difference.

 
законопослушный гражданин #:

I've only just noticed.

bool bSignalBuy()
  {
   if(dMA > Open[1] && dMA < Close[1])  //Open[1] и Close[1]- цены открытия и закрытия каждого бара текущего графика.
      return(true);

   return(false);
  }
Open[1] и Close[1]

Index 1.

dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0);

Whereas you have the MA with an Index of 0! That is, it walks throughout the bar and can go beyond Open and Close. Therefore, it is better to index MA by 1.

dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 1);

Then all the signals will be taken exceptionally on the formed bar and the robot will be fully consistent with the trading system with signals on the open prices. Thus, the robot will only have to track the bar opening (I have already added this code) and enter on the newest bar. It will be more reliable. And there will be no need to get twisted, as Makar had to do because of the originally wrong entry algorithm.

 
Mihail Matkovskij #:

I've only just noticed.

Index 1.

Whereas you have the MA with an Index of 0! That is, it walks throughout the bar and can go beyond Open and Close. Therefore, it is better to index MA by 1.

Then all the signals will be taken exceptionally on the formed bar and the robot will be fully consistent with the trading system with signals on the open prices.

This is the essence of the signal.

The current MA goes into the body of the previous candle and depending on which candle (UP/DN) gives the same signal.

 
MakarFX #:

This is the essence of the signal.

The current MA goes into the body of a previous candle and depending on the candle (UP/DN), it will be the same signal.

In this case the MA should be drawn with the index 1 in the lower timeframe. Then there will be no need to apply any changes. Within the Open and Close of the higher time frame there will be several (or a lot of) bars on the lower one. You know why timeframes were invented, don't you? If not, then start studying this question from the history of the Japanese candlesticks. In brief, the point is to simplify technical analysis. And with the advent of the digital age it also simplified the discretization of trading systems.

 
Mihail Matkovskij #:

In that case the MA should be taken with index 1 on the lower time frame. Then, there will be no need to get twisted. There will be several (or many) bars within Open and Close of the higher timeframe on the lower one. You know why timeframes were invented, don't you? If not, then start studying this question from the history of the Japanese candlesticks. In brief, the point is to simplify technical analysis. And with the advent of the digital age it also simplifies the discretization of trading systems.

I do not understand why you're mad at me. The man writes his strategy the way he sees it, and this man is not me.

I only answered his question, "How do I avoid multiple openings on the same bar?"

What do I learn I know myself, and if I don't know, I ask. Right now I have not asked anyone anything.

 
MakarFX #:

I don't understand why you're taking it out on me. The man writes his strategy as he sees it and that man is not me.

I only answered his question: "How to avoid multiple openings on the same bar?"

What do I learn I know myself, and if I don't know, I ask. Now I didn't ask anyone anything.

Strange. I'm trying to get to the bottom of an issue and you're talking about some sort of relationship clarification. I'm communicating solely on the subject of programming. If you're offended by something, don't be offended. I've been writing software for 15 years. You say my codedoesn't workcorrectly in your opinion. I'm not taking offense. I'm trying to explain to you how automated trading systems work. It's a purely technical conversation. And you are talking to me about some kind of insult... :)

 
Mihail Matkovskij #:

That's weird. I'm trying to get to the bottom of an issue and you're talking about some sort of relationship. I'm communicating solely on the subject of programming. If it offends you, don't be offended. I've been writing software for 15 years. You say my codedoesn't workcorrectly in your opinion. I'm not taking offense. I'm trying to explain to you how automated trading systems work in reality. It's a purely technical conversation. And you are talking to me about some kind of insult... :)

So I also explained to you what your code is wrong (in this case), and you say you need to redo the EA)
 
Mihail Matkovskij #:

I have been writing programmes for 15 years.

I have a suggestion. Give me your telegram in private.

 
MakarFX #:
So I also explained to you what your code is wrong (in this case), and you say you need to redo the EA)

In this case, it needs to be reworked so that it doesn't get twisted. Because the code I've added is designed for a robot with opening price signals, as I said before. I thought: This is strange. And then I found the reason. If you get it right from the beginning, you won't have any problems in the future. Thus, you should always look for the cause and not fight the consequence.

Reason: