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

 
Alexey Viktorov:

One of them is me. And I've never studied C# or C++ and I've never known what OOP is.

Please understand the simple truth, that mql5 differs from mql5 only in OrderSend() function and maybe a few more functions that I don't remember. Another important difference is the direction of indexing of indicator buffers. However, it can be solved very quickly, but you'd better get used to the new features. And getting indicator values remains the same. I haven't read Kovalev's book, I don't know what is there, but I doubt that any solution from this book cannot be written using the updated MetaEditor mql4.

Cool. )))) Didn't work for me, really loaded with procedural Fortran and Basic. It's a good tutorial, well structured, clear enough and can really be taken as a basis, if the creators need students of course. Unfortunately there aren't any others. I haven't got enough of PLO, so I have to read articles. I have tried a lot of the tutorial on the updated MT4 terminal. There are a lot of remarks on data types that are not given. The compiler didn't see any errors even in the strict check.

 
Valeriy Yastremskiy:

Cool. )))) I didn't get it, though, with procedural Fortran and Basic in the load. Good tutorial, well structured, clear enough and could really be taken as a basis, if the creators need students of course. Unfortunately there aren't any others. I haven't got enough of PLO, so I have to read articles. I have tried a lot of the tutorial on the updated MT4 terminal. There are a lot of remarks on data types that are not given. The compiler didn't see any errors even in the strict check.

Here are my thoughts on OOP. And it wouldn't hurt to read the whole thread from the beginning.

ООП для школьников.
ООП для школьников.
  • 2019.10.04
  • www.mql5.com
======================================================================================================================== В этой теме будет нескольк...
 

Greetings. Please advise, after selecting an order it is not clear for what reason the ticket changes. Code:

      for(int i=OrdersTotal()-1; i>=0; i--){
         if(OrderSelect(i ,SELECT_BY_POS, MODE_TRADES)){
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUYSTOP){
               Print("111  OrderTicket() ", OrderTicket(), "  OrderType() ", StringType(OrderType()));
               temp=OrderTicket();
               if( OrderOpenPrice()>start_bid
               +((MathCeil( (Bid-start_bid)/(bs_distance*Point) )+bs_orders+Orders("bs")+1)*bs_distance*Point) ){
                  Print("222 OrderDelete bs Bid ", Bid, "  OrderOpenPrice() ", OrderOpenPrice()); 
                  if(!OrderDelete(OrderTicket(), clrBlack)){
                     Print("333 OrderDelete bs Bid ", Bid, "  OrderTicket() ", OrderTicket(), "  OrderType() ", StringType(OrderType()));
                  }
               }
            }
         } 
      }

There are two orders in the market,BUYSTOP ticket 10 andBUY ticket 9 .

Log:


 
Alexey Viktorov:

Here are my thoughts on OOP. And it wouldn't hurt to read the whole thread from the beginning.

Thanks, I agree))))

 
Andrey Sokolov:

Greetings. Please advise, after selecting an order it is not clear for what reason the ticket changes. Code:

There are two orders in the market,BUYSTOP ticket 10 andBUY ticket 9 .

Log:


I assume one of the self written functions is going through the orders (e.g.Orders("bs")) and therefore re-running OrderSelect(). at the time it returns to the presented loop, all data is given for the last order selected there.

 
Igor Zakharov:

I assume that one of the self written functions goes through the orders (e.g.Orders("bs")), and accordingly re OrderSelect(). at the time of returning to the submitted loop, all data is given for the last order selected there.

thanks

 
Andrey Sokolov:

Greetings. Please advise, after selecting an order it is not clear for what reason the ticket changes. Code:

There are two orders in the market,BUYSTOP ticket 10 andBUY ticket 9 .

Log:


Your work code does not match the posted code.

Print("222 OrderDelete bs Bid ", Bid, "  OrderOpenPrice() ", OrderOpenPrice());

Where in this code "OrderTicket()" is printed

Pay attention to calls to other user functions which may include order selection.

 
Alexey Viktorov:

You have come to the right place. Here is a tip on how to do mql4 correctly, guided by the new mql4 documentation.

If you find it difficult to write something, then ask a concrete question, what you have written and what you failed to get. Just keep in mind that nobody will read a kilometer-long code with one incomprehensible line. I certainly won't.

You are the person my question was meant for. Because based on your request I have made my Mql4 code for the tester short, just to show my problem clearly. But unfortunately Artem didn't understand it.

I would be very grateful to you if you could change the code to solve my problem. Once again I will tell you its essence.

When I close each order (and there are many open orders at the same time), I need to output some parameters of a closed order in Print (). I have learned to do this very successfully. But..... there is one problem which my mind is not enough to solve. Some orders are closed by stop on the same tick and at the same price. In this case, the program ignores the first closed order and prints Print() only the last closed order. And it doesn't print after the first one.

Q: .

What language construction can be used to make the program print () in the cases I described above even after the first order closed by the stop?

int H;
int L;
int TP;  
int start()
{
int Ht = OrdersHistoryTotal();
if (OrderSelect (Ht-1,SELECT_BY_POS, MODE_HISTORY))                                             
if (TP!=OrderTicket( ))
{
Print("---------------------------------------------------------------=",TimeToString(OrderOpenTime()) );
TP=OrderTicket( );
}

if (TimeCurrent()==1262598040)
if (H==0)
{
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,1.6217,1.60919,"300",10 );
H=1;
}
if (TimeCurrent()==1262601140)
if (L==0)
{
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,1.62199,1.61758,"300",10 );
L=1;
}
return(0);


 
ANDREY:

You are the person for whom my question was meant. Because based on your request I have made my Mql4 code for the tester short, just to clearly demonstrate my problem. But unfortunately Artem didn't understand it.

I will be very grateful to you if you can change the code to solve my problem. Once again I will tell you its essence.

When I close each order (and there are a lot of them open at the same time), I need to print () some parameters of a closed order. I have learned to do this very successfully. But..... there is one problem which my mind is not enough to solve. Some orders are closed by stop on the same tick and at the same price. In this case, the program ignores the first closed order and prints Print() only the last closed order. And it doesn't print after the first one.

Q: .

What language construction can be used to make the application print Print () even after the first order closed at stop, in the cases I described above?


What does your code do other than open two sell positions, each at a strictly specified time, and print the time of the last position opening when allowed? That's it. Using uninitialized variables, which can lead to "miracles" in code behavior, and very, very old start() handler, which was pulled from dusty shelf with years of cobwebs, and in the market (someday you want to sell something) with ancient handlers will never miss validator - it will say that the wrong program type.

 
ANDREY:

You are the person for whom my question was meant. Because based on your request I have made my Mql4 code for the tester short, just to clearly demonstrate my problem. But unfortunately Artem didn't understand it.

I will be very grateful to you if you can change the code to solve my problem. Once again I will tell you its essence.

When I close each order (and there are a lot of them open at the same time), I need to print () some parameters of a closed order. I have learned to do this very successfully. But..... there is one problem which my mind is not enough to solve. Some orders are closed by stop on the same tick and at the same price. In this case, the program ignores the first closed order and prints Print() only the last closed order. And it doesn't print after the first one.

Q: .

What language structure can be used to make the program print () even after the first order closed at stop in the cases I have described above?

I don't remember Artem's answer. All of the codes in his articles are either multiterminal or have two versions, one for mql5 and another for mql4. I have checked these versions on mql4. Everything works properly and detects closing by stop or take and makes no mistakes.

Yes, these articles are difficult to understand, but it's worth it if you are no older than me. And I, for a programmer, am obscenely old.

The other option is simpler, but will work much slower. Write order tickets in an array, and using this array select the order, check the order closing time. If it is greater than zero, it means it is closed. If the comment of a closed order contains the letters "sl", it means that the order is closed using a stop. If the order is closed, it is deleted from the array. Or, after the array is completed, it is refilled with remaining open orders. Imagination is flying in general.

Which option you choose is up to you. And read some of my posts on Kovalev's textbook. The tutorial suggests to write int start(), while in the updated mql4, void OnTick() should be written for Expert Advisors.

For indicators and scripts, please refer to documentation. And by the way, it's much easier to write indicators in updated mql4 than it was when Sergey wrote this tutorial.

Reason: