Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 100

 
alexey1979621:
Hi all! Here's the question. How to measure the distance between High and Low of the first, second, third candle and prescribe the condition that this distance of each candle should not be less than, say, 10 points. Thank you in advance.

Here are the market environment variables to help you https://docs.mql4.com/ru/predefined/variables
 
artmedia70:
Robot uprising... :)


Aha ha ha. yosuf, Cyborg sent you... )))))))
 
artmedia70:

Here's an EA to test the function. It contains the function itself and its call. Before calling it, you have to prepare a message, which can be up to four lines. The length of each line, if I remember correctly, should not exceed 64 characters. That's why I've split one message into several lines. Each line of one message can be output in a different colour. It's kind of clear in the code there - first we prepare message lines, then we call the function. I haven't commented much there - I wrote it in one go long ago. Now I have already forgotten what is there for. If I have any questions, I'll remember, but I remember only necessary things now.

And a turkey:

That's the way it is... I hope you get the hang of it.

Of course, I can make an underlay instead of outputting it to the main chart in the window of the indicator, but I am too lazy ... :)



Artem, I've looked at your code, the turkey is the bomb: )))). In essence, everything is clear with more, although I have seen a couple of points in the implementation, a bit different from what I would have done, but that's just a small thing.

Here's the interesting thing. Only what is in the expert is printed in the turkey. But how do you use it to your advantage?

 
hoz:


Artem, I've looked at your code, the turkey is the bomb: )))). In essence, everything is clear with more, although I have seen a couple of points in the implementation, a bit different from what I would have done, but that's only trifles.

Here's what's interesting. Only what is in the Expert Advisor is printed in the turntable. But how do I use it to my advantage?

I don't understand the question. It replaces the Print() function. Outputs all messages to the indictor window. You can set colour for each line of one message (like priority of message). More convenient than print. That's all the usefulness.
 

It is a function. That expert is just for showing what the function does. So use that function to display your messages from your EA.

That expert only shows how to use it.

 
artmedia70:

It is a function. That expert is just for showing what the function does. So use that function to display your messages from your EA.

That expert only shows how to use it.


Although yes... It's a function... I missed the most important thing while I was figuring it out :(
 

There's a new headache. Here's what it takes to make it happen:

1. There is a number of orders in the market, i.e. there are market and pending orders in the market all the time.

2. At a certain moment when the last order opened so far is closed by a TP, we need to close all the orders that were opened and delete all the pending ones as well.

I did it this way (I put it in the start() function):

for (int ord=OrdersTotal()-1; ord>=0; ord--)
   {
      if (!OrderSelect(ord,SELECT_BY_POS)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
        
      g_ticket = OrderTicket();
      g_type = OrderType();
              
      // Блок модификации ордеров       
      if (i_sl != 0 || i_tp != 0)
      {
         if (OrderStopLoss() == 0 && OrderTakeProfit() == 0)
         {
            OrdersModifyer(g_ticket);
         }
      }
      // Закрытие всех ордеров, если последний ордер закрыт
      if (GetLastOrderState() != 0)              
      {
          if (g_type > 1)
          {
              DeletePendingOrders(g_ticket);
          }
          else
          {
              CloseMarketOrders(g_ticket);
          }
      }
   }

Function GetLastOrderState() checks if the last order is closed:

//+-------------------------------------------------------------------------------------+
//| Получаем состояние последней позиции (Открыта или закрыта)                          |
//+-------------------------------------------------------------------------------------+
datetime GetLastOrderState()
{
   datetime lastOrderCloseTime = -1,                   // Время закрытия последнего ордера
            lastOrderOpenTime = -1;                    // Время открытия последнего ордера
   
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
  
      if (lastOrderOpenTime < OrderOpenTime())
          lastOrderOpenTime = OrderOpenTime();
   }
   Comment("Время открытия последнего открытого ордера = ", lastOrderOpenTime);
   for (int h=OrdersHistoryTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(h, SELECT_BY_POS, MODE_HISTORY)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      
      if (OrderOpenPrice() == lastOrderOpenTime)
          lastOrderCloseTime = OrderCloseTime();
   }
  // Comment("Время закрытия последнего открытого ордера = ", lastOrderCloseTime);
   return (lastOrderCloseTime);
}

And then functions deleting pending and closing market orders. I see that it's not working correctly somehow. Is my function ok?

I understand that the function is in order by idea. But the logic is not ok here. Do you have any thoughts on this subject? It turns out that, in any case, even when none of the EA's orders has closed by TP, everything is closed in a blink of an eye after it has been opened by the signal...

 
hoz:

Aha ha ha. yosuf, Cyborg sent you... )))))))
Still, a good, responsive proger. As if all problems are his, for that fate will repay, unquestionably, or, come across the grail.
 
yosuf:
Still, a good, sympathetic proger. As if all the problems were his, for that fate will reward, unquestionably, or, come across the grail.


But there was no specificity, and therefore no question. I do not know what to answer.... You must try to explain the situation as clearly as possible to get an answer.
 
hoz:

There's a new headache. Here's what it takes to make it happen:

1. There is a number of orders in the market, i.e. there are market and pending orders in the market all the time.

2. At a certain moment when the last order opened so far is closed by a TP, we need to close all the orders that were opened and delete all the pending ones as well.

I did it this way (I put it in the start() function):

Function GetLastOrderState() checks if the last order is closed:

And then functions deleting pending and closing market orders. I see that it's not working correctly somehow. Is my function ok?

I understand that the function is in order by idea. But the logic is not ok here. Do you have any thoughts on this subject? It turns out that, in any case, even if none of the EA's orders has closed at TP, everything is closed in a flash after it has been opened by the signal...

Victor, take the tried and tested Kim's function that checks if a position is closed by TP:

isCloseLastPosByTake - Returns a flag to close the last position on the take. Find in Only useful functions
And then close everything.

Reason: