Questions from Beginners MQL5 MT5 MetaTrader 5 - page 908

 
Thanks, guys.
 
A.Vakutin:

Please share, who knows and knows how to prohibit an EA from selling after a stop is triggered?

// Оставанивливает работу всех советников, если сработал SL.

#include <MT4Orders.mqh>      // https://www.mql5.com/ru/code/16006
#include <fxsaber\Expert.mqh> // https://www.mql5.com/ru/code/19003

void OnTrade()
{
  static int PrevTotal = OrdersHistoryTotal();
  const int Total = OrdersHistoryTotal();
  
  for (int i = Total - 1; i >= PrevTotal; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderCloseReason() == DEAL_REASON_SL))
    {
      long Chart = ChartFirst();
  
      while (Chart != -1)
      {
        if ((Chart != ChartID()) && EXPERT::Is(Chart))
          EXPERT::Remove(Chart);
  
        Chart = ChartNext(Chart);
      }

      break;
    }        
    
  PrevTotal = Total;
}
 

Good evening, forum users!

A dilemma has arisen.

I had a transaction and stored it in a variable

datetime now=TimeCurrent();

Some time later, an event occurred and I store the time in a variable

datetime now2=TimeCurrent();

How can I check if 15 minutes have passed between these events?

Thought I had two variables now and now2 set in seconds, tried to take the difference and it should be more than 700 seconds

 if(now2-now>700)

BUT it's not working((

I'm asking for help from the community!

 
ISL:

Good evening, forum users!

A dilemma has arisen.

I had a transaction and I stored it in a variable

Some time later, an event occurred and I store the time in a variable

How can I check if 15 minutes have passed between these events?

Thought I had two variables now and now2 set in seconds, tried to take the difference and it should be more than 700 seconds

BUT it's not working((

Please help from the community!

The datetime variable is represented as date and time. You can solve the problem differently, for example to represent 700 (although 15 minutes is 900 seconds) in datetime type

if(now2-now>(datetime)700)

or vice versa represent variables as int type

if(int(now2-now)>700)

or like this

if((int)now2-(int)now>700)
Anyway, we have to check...
 
Alexey Viktorov:

The datetime variable is represented as date and time. You can solve the problem in different ways, e.g. represent 700 (although 15 minutes is 900 seconds) as datetime


The evening is coming)))

 
ISL:

The evening is making itself felt)))

Yeah... It took me an hour and a half to connect the function from the inluder...

 
Vladimir Karputov:

Connect the standard trading classCTrade
(it comes standard with the terminal)

and call two methods:

SetTypeFillingBySymbol

Sets the order type according to the specified symbol

SetMarginMode

Sets the margin calculation mode according to the current account settings

Vladimir, good evening, could you please advise me please make a function that calculates the percentage profit I want to calculate the traded volume but I can't get it right, I think I need to identify the order with the direction out and use them to calculate the volume

double ALL_PROFIT(int rezult)
  {
   HistorySelect(0,TimeCurrent());
   double   rez=0.0;
   double   alprof=0.0;
   uint     total=HistoryDealsTotal();
   for(uint i=0;i<=total;i++) 
     {
      if(m_ticket.SelectByIndex(i))
        {
         if(m_ticket.Magic()==Mg)
           {
            alprof+=(m_ticket.Profit()+m_ticket.Swap()+m_ticket.Commission());
            rez=alprof;
            if(rezult==1 && alprof!=0.00){rez=alprof/(AccountInfoDouble(ACCOUNT_BALANCE)-alprof)*100;}
            if(rezult==2){rez+=m_ticket.Volume();}      
           }
        }
     }
   return(NormalizeDouble(rez,2)); 
  }
by the way, the number of closed positions is also a problem to find out how many of them have traded
 
TYRBO:

Vladimir, good evening, could you please advise me on how to do a function that calculates the percentage of profit I want to calculate the traded volume and it does not work correctly I think I need to identify the order with the direction out and with them to calculate the volume

I do not understand anything, all the letters are piled up. Pass your code through the code styler.

 
TYRBO:

Vladimir, good evening, could you suggest a function that calculates profit percent, I want to calculate the traded volume and it does not work correctly, I think I need to identify the order with the direction out and with them to calculate the volume.


by the way, it is also a problem with the number of closed positions

Please send the code correctly. I have already corrected you once and put the code correctly.

 
TYRBO:

Vladimir, good evening, could you suggest a function that calculates profit percent, I want to calculate the traded volume and it does not work correctly, I think I need to identify the order with the direction out and with them to calculate the volume.

by the way, the number of closed positions is also a problem

I have submitted your code correctly for the third time. I wonder how many more tries we have to try. :)

Reason: