Questions from Beginners MQL5 MT5 MetaTrader 5 - page 587

 
Karputov Vladimir:
Dream11:

Good afternoon, here's the problem... there's a trailing stop function...

How to change it to trawl an unlimited number of orders instead of just one ...


I have one of these, it trawls everything.
extern int             TrailingStep = 10;     //Шаг трейлинга
extern int             TrailingStop = 30;     //Трейлинг стоп
//+------------------------------------------------------------------+
//Трейлинг стоп
void Trailing()
{
 int err = GetLastError();
 err = 0;
 
 for(int i = OrdersTotal()-1; i>=0; i--)
 {
  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
  {
   if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
   {
    if(OrderType() == OP_BUY)
    {     
     if(Ask - OrderOpenPrice() > TrailingStop*Point)
     {
      if(OrderStopLoss() < Ask - (TrailingStep + TrailingStop)*Point)
      {
       if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask - TrailingStop*Point,Digits),OrderTakeProfit(),0,clrGreen))
       {
        err = GetLastError();
        if(err != 0) Print("Ошибка модификации ордера № ",OrderTicket()," на покупку! Код ошибки: ",err,".");
       }
      }
     }
    }
    if(OrderType() == OP_SELL)
    {
     if(OrderOpenPrice() - Bid > TrailingStop*Point)
     {
      if(OrderStopLoss() > Bid + (TrailingStep + TrailingStop)*Point)
      {
       if(!OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid + TrailingStop*Point,Digits),OrderTakeProfit(),0,clrRed))
       {
        err = GetLastError();
        if(err != 0) Print("Ошибка модификации ордера № ",OrderTicket()," на продажу! Код ошибки: ",err,".");
       }
      }
     }
    }
   }
  }
 }
}
//+------------------------------------------------------------------+
 
barudkinarseniy:
I've got one of these, it fucks everything.
It's pretty much the same, maybe you're calling it in the wrong place.
 
Alexey Viktorov:
Can you not do it through the OnTimer()?

I'm doing it by timer. Already figured it out, thanks, I just needed to add ChartRedraw function in each time loop to update the chart. Damn, they added a lot of complexities in mql5 after mql4, but maybe it's for the best...

 
Another question, how can a date-time variable (datetime type) be converted to NUMBER of seconds after 1970? Because if you equate the time to a regular integer, this int-variable will indeed be equal to this number of seconds, but there will be a warning"possible loss of data due to type conversion", it is a bit annoying, is there any way to solve the problem?

 
loleg1991:
Another question, how can a date-time variable (datetime type) be converted to NUMBER of seconds after 1970? Because if you equate to a regular integer time value, this int-variable will indeed be equal to this number of seconds, but there will be a warning"possible loss of data due to type conversion", it is a bit annoying, is there any way to solve the problem?

Read "Numeric type conversion" in the documentation
Документация по MQL5: Основы языка / Типы данных / Приведение типов
Документация по MQL5: Основы языка / Типы данных / Приведение типов
  • www.mql5.com
Основы языка / Типы данных / Приведение типов - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
loleg1991:
Another question, how can a date-time variable (datetime type) be converted to NUMBER of seconds after 1970? Because if you equate to a regular integer time value, this int-variable will really equal this number of seconds, but there will be a warning"possible loss of data due to type conversion", it is a bit of a nuisance, is there any way to solve the problem?

datetime is the number of seconds

https://www.mql5.com/ru/docs/basis/types/integer/datetime

.

https://www.mql5.com/ru/docs/convert/stringtotime

Документация по MQL5: Основы языка / Типы данных / Целые типы / Тип datetime
Документация по MQL5: Основы языка / Типы данных / Целые типы / Тип datetime
  • www.mql5.com
Основы языка / Типы данных / Целые типы / Тип datetime - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
loleg1991:
Another question, how can a date-time variable (datetime type) be converted to NUMBER of seconds after 1970? Because if you equate it to a regular integer value of time, this int-variable will really equal this number of seconds, but there will be a warning"possible loss of data due to type conversion", it is a bit annoying, is there any way to solve the problem?

If you mean not as date, but as number of seconds, then explicitly convert it to long type.
 
Alexey Kozitsyn:
If you mean to display the number of seconds, but not the date, then explicitly make it a long type.
Yes, I meant the display, thank you, that helps.
 
loleg1991:
Yes, I meant about the display, thank you, that helps.
You're welcome)
 

Hello, could you please tell me if it is possible for the Expert Advisor to add an object such as a button or toggle switch to the chart, and if so, how?

Reason: