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

 
Alexey Viktorov #:

Valery, pay attention to the line

in my code... I've been using hex functions for a while now, but a similar function

gave a stale 0.

So, think where the cockroaches are... And since mt4 refuses to support it, you can assume that it will never be fixed...

Everything else has to be checked. I haven't bothered with it for so long that I don't even want to remember.

Hmmm... The time is emulated) I'll have to get into it)

int sd;
/*******************Expert initialization function*******************/
int OnInit()
 {
  sd = (int)MarketInfo("EURJPY", MODE_DIGITS);
  return(INIT_SUCCEEDED);
 }/******************************************************************/

/************************Expert tick function************************/
void OnTick()
 {
  datetime lt = iTime(_Symbol, PERIOD_M15, 0);
  static datetime ct = 0;
  if(ct != lt)
  {
   ct = lt;
   Print(DoubleToString(iMA("EURJPY", PERIOD_M15, 21, 0, MODE_SMA, PRICE_CLOSE, 0), sd),
    " Time[0] ",TimeToStr( Time[0])," iTime(EURJPY,0,0) ",TimeToStr(iTime("EURJPY",0,0)));
  }

Result

2021.09.21 15:30:48.696 2021.08.13 20:15:00  testMulti EURUSD,M15: 129.482 Time[0] 2021.08.13 20:15 iTime(EURJPY,0,0) 2021.08.13 20:15
2021.09.21 15:30:48.632 2021.08.13 20:00:00  testMulti EURUSD,M15: 129.495 Time[0] 2021.08.13 20:00 iTime(EURJPY,0,0) 2021.08.13 20:00
2021.09.21 15:30:48.568 2021.08.13 19:45:00  testMulti EURUSD,M15: 129.512 Time[0] 2021.08.13 19:45 iTime(EURJPY,0,0) 2021.08.13 19:45
2021.09.21 15:30:48.504 2021.08.13 19:30:00  testMulti EURUSD,M15: 129.527 Time[0] 2021.08.13 19:30 iTime(EURJPY,0,0) 2021.08.13 19:30
2021.09.21 15:30:48.440 2021.08.13 19:15:00  testMulti EURUSD,M15: 129.539 Time[0] 2021.08.13 19:15 iTime(EURJPY,0,0) 2021.08.13 19:15

ZZY works on getting bar data from other characters)))) But the story needs to be loaded specifically, going outside the array only so on an unloaded instrument or requesting data from a distant bar.

ZS ZS

Really works!!! I had to upload the quote archives of all !!! necessary currency pairs and it works on a minute from June of 21, on the older and later starts)

 
giros #:

Can you suggest where I can learn MQL5 (in Russian)?

Here. I haven't read anything else.
Документация по MQL5 - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
Документация по MQL5 - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
  • www.mql5.com
Документация по MQL5 - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 


double FindPenultBuyPrice()
{
   int oldticket;
   double oldopenprice=0;
   ticket=0;
   
   for(int i=OrdersTotal()- 2 ; i>=0; i--)
   {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
         {
            oldticket = OrderTicket();
            if (oldticket > ticket)
            {
               ticket = oldticket;
               oldopenprice = OrderOpenPrice();
            }
         }
      }
   }
   return(oldopenprice);
}

Hello. Trying to find the opening price of the penultimate order, but it works fine if there are no Sell orders, Can you tell me what the error is? I think it counts them too. MQL4

 
makssub #:


Hello. Trying to find the opening price of the penultimate order, but it works fine if there are no Sell orders, Can you tell me what the error is? I think it counts them too. MQL4

double FindPenultBuyPrice()
{
   int oldticket;
   double oldopenprice=0;
   ticket=0;
   
   for(int i=OrdersTotal()- 2 ; i>=0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) // внимательней к копипасту) цикл по i а перебираешь cnt))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
         {
            oldticket = OrderTicket();
            if (oldticket > ticket)
            {
               ticket = oldticket;
               oldopenprice = OrderOpenPrice();
            }
         }
      }
   }
   return(oldopenprice);
}
 
Valeriy Yastremskiy #:


double FindPenultBuyPrice()
{
   int oldticket;
   double oldopenprice=0;
   ticket=0;
   
   for(int cnt=OrdersTotal()- 2 ; cnt>=0; cnt--)
   {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
         {
            oldticket = OrderTicket();
            if (oldticket > ticket)
            {
               ticket = oldticket;
               oldopenprice = OrderOpenPrice();
            }
         }
      }
   }
   return(oldopenprice);
}

Thank you. Re-checked, still counts Sell too(

 
makssub #:


Thank you. Re-checked, still counts Sell too(

Probably because you're subtracting from the total number of orders

OrdersTotal()- 2 

and only look in

OP_BUY
 
makssub #:


Thank you. Re-checked, still counts Sell too(

Unprint before the second if and inside the second if the number, ticket and order type.

double FindPenultBuyPrice()
{
   int oldticket;
   double oldopenprice=0;
   ticket=0;
   
   for(int cnt=OrdersTotal()- 2 ; cnt>=0; cnt--)
   {
    if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
Print("Print 1 "," cnt ",cnt," OrderTicket() ",OrderTicket()," OrderType() ",OrderType());
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
         {
Print("Print 2 "," cnt ",cnt," OrderTicket() ",OrderTicket()," OrderType() ",OrderType());
            oldticket = OrderTicket();
            if (oldticket > ticket)
            {
               ticket = oldticket;
               oldopenprice = OrderOpenPrice();
            }
         }
      }
   }
   return(oldopenprice);
}
 
 private:
   CPoint             *startPoint;
   CPoint             *endPoint;

There are two constructors. When I call the first one from the second one and set values for the variables above, when I return from it to the second one these variables go to NULL.
But if I just copy the code from the first constructor to the second one and don't call it, everything works. What is the problem?

CWave::CWave(string namePref,
             double startPrice,
             datetime startTime,
             double endPrice,
             datetime endTime)
  {
   prevWave = NULL;
   nextWave = NULL;
   name = namePref+"_"+TimeToString(startTime, TIME_DATE|TIME_MINUTES);
   startPoint = new CPoint(startPrice, startTime);
   endPoint = new CPoint(endPrice, endTime);
   dir = startPrice < endPrice ? true : false;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CWave::CWave(string namePref,
             double startPrice,
             datetime startTime,
             double endPrice,
             datetime endTime,
             CWave *prevWave)
  {
   CWave(namePref, startPrice, startTime, endPrice, endTime);
   this.prevWave = prevWave;
   prevWave.nextWave = &this;
  }
 
Roman Sharanov NULL.
But if I just copy the code from the first constructor to the second one and don't call it, everything works. What is the problem?


The problem is in MQL.

In such situations, I put initialization in separate method which I pull from different constructors.

---

There is also a problem with calling the parent constructor.

 
Valeriy Yastremskiy #:

Print before the second if and inside the second if the number, ticket and order type.

Thank you. I'll check it out later today.

Reason: