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

 
ilnur17021992:
SELL_Lvl is the number of knees (orders) of the sell grid andSELL_NoLossLevel is the total level (price) of the CU of these orders. Well, the idea is the following: we need a line drawn at the level of a Buy Line and redrawn respectively when new Lines are opened. I do not know how to do it.

Don't understand how to determine the BU line of all orders?

 

Can you tell me how to write it down to save resources and get up-to-date prices?

  for(int i=OrdersTotal(); i>=0; i--) {
   if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) {
    if(OrderSymbol()==symb) {
      if(OrderType()==OP_BUY) {
       tk=OrderTicket();
       SymbolInfoTick(OrderSymbol(),Last_Tick); <<<
       ask=Last_Tick.ask;
       bid=Last_Tick.bid;
       ...

or like this?

 SymbolInfoTick(symb,Last_Tick); <<<
  for(int i=OrdersTotal(); i>=0; i--) {
   if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) {
    if(OrderSymbol()==symb) {
      if(OrderType()==OP_BUY) {
       tk=OrderTicket();
       ask=Last_Tick.ask;
       bid=Last_Tick.bid;
       ...
 
Vitaly Muzichenko:

Can you tell me how to write it down to save resources and get up-to-date prices?

  for(int i=OrdersTotal(); i>=0; i--) {
   if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) {
    if(OrderSymbol()==symb) {
      if(OrderType()==OP_BUY) {
       tk=OrderTicket();
       SymbolInfoTick(OrderSymbol(),Last_Tick); <<<
       ask=Last_Tick.ask;
       bid=Last_Tick.bid;
       ...

or like this?

SymbolInfoTick(OrderSymbol(),Last_Tick); <<<
  for(int i=OrdersTotal(); i>=0; i--) {
   if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) {
    if(OrderSymbol()==symb) {
      if(OrderType()==OP_BUY) {
       tk=OrderTicket();
       ask=Last_Tick.ask;
       bid=Last_Tick.bid;
       ...


The first option is more correct. In the second one, you should write this lineSymbolInfoTick(symb,Last_Tick); <<<<
 
Vitaly Muzichenko:

Can you tell me how to write it down to save resources and get up-to-date prices?

  for(int i=OrdersTotal(); i>=0; i--) {
   if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) {
    if(OrderSymbol()==symb) {
      if(OrderType()==OP_BUY) {
       tk=OrderTicket();
       SymbolInfoTick(OrderSymbol(),Last_Tick); <<<
       ask=Last_Tick.ask;
       bid=Last_Tick.bid;
       ...

or like this?

SymbolInfoTick(OrderSymbol(),Last_Tick); <<<
  for(int i=OrdersTotal(); i>=0; i--) {
   if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) {
    if(OrderSymbol()==symb) {
      if(OrderType()==OP_BUY) {
       tk=OrderTicket();
       ask=Last_Tick.ask;
       bid=Last_Tick.bid;
       ...


I would say it depends on the size of OrdersTotal() and the probability of price changes during the cycle.

In my opinion, getting fresh data directly in the loop is more correct.

And I think additional variables (highlighted in the code) are absolutely unnecessary.

 
Alexey Viktorov:

There is an example in the documentation.

It would probably be better to go through the orders in the loop and, provided that the next order is lower than the previous one, select it for further work with it. Thus, when we exit the loop, the order to be deleted is already selected.

Or, you can first save its position in the list of orders in the loop and then select it after exiting the loop using the index saved in the loop.

It is not that easy to set both higher and lower orders if
 
Sergey Gritsay:
The first option is more correct. The second one should writeSymbolInfoTick(symb,Last_Tick); <<<<

Yes, I just copied it and didn't notice.

I'm wondering ifSymbolInfoTick is the right way to put it inside the loop, if it's needed there, or if it can be put before the loop. Used in trailing stop, can pull grid up to 50pc.

 
Vitaly Muzichenko:

Yes, I just copied it and didn't notice.

I'm wondering ifSymbolInfoTick is the right way to put it inside the loop, if it's needed, or if it can be put before the loop. Used in trailing stop, can pull a grid of up to 50pc.

For trailing stop it is of course better to put it once before the cycle.
 
Alexey Viktorov:

Can't figure out how to determine the BU line of all orders?

I know how to determine the BU, I need the line to be drawn at this level
 
Alexey Viktorov:
For trailing stop it is of course better once before the cycle.

I'm now slowly rewriting it for 5. I mean that price may change very quickly and the level may be less than the stop-loss value, which will lead to an error. I mean that the price may change very quickly and the level will be less than the allowable stop level, which will lead to an error.

I understand that this"SymbolInfoTick" hat is needed to get actual prices?

 
problem solved by comparing prices