[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 113

 
IgorM:

Sometimes there are complex calculations or loading of history in init(), or there are a lot of indicators and EAs hanging on the terminal or...

but if the terminal interrupts the code during its initialization, there will be an error in the log like this:" .... timeout in expert ...."

If the log shows no error in the terminal, it means that initialization was successful. The start() function itself is easy to check - write in the first line start(): Print("new tick");


I did so((.

int start()
  {
  Print("start");
  
/*current_values_from_MT(CUR, CUR_BUF);
current_values_from_MT(MAIN, MAIN_BUF);*/

  


   return(0);
  }

Yes, I'm rocking a lot of information, calculations too, experimenting with ticks...

Calculation takes 2 - 3 minutes, MT "doesn't hang", everything works typically, messages from Print() and Alert are displayed and then everything))

Looked at all the messages from MT, I could not find any errors...

Please assist.

 
BBSL:

Calculation takes 2 - 3 minutes, MT does not "hang", everything works typically, Print() and Alert messages are displayed and then everything))

if Print() is printed, start() definitely works, but I'm confused by your statement that the calculation takes 2-3 minutes - with such a load on the terminal you need to interrupt the calculations using the function sleep() otherwise the terminal will definitely hang.

Since MT4 has no debugger, insert Print() into questionable code sections and catch the code sections and conditions that failed or did not fail.

 
I need to fix the fact of triggering of the open orders by TakeProfit or StopLoss, and the values of TakeProfit and StopLoss are not of interest to me.
 
Jaguar1974:

How do I check if an order is triggered by TakeProfit or StopLoss? Thank you for your reply!

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает флаг закрытия последней позиции по стопу.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isCloseLastPosByStop(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   ocp, osl;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo(sy, MODE_DIGITS);
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    osl=NormalizeDouble(OrderStopLoss(), dg);
    if (ocp==osl) return(True);
  }
  return(False);
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает флаг закрытия последней позиции по тейку.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isCloseLastPosByTake(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   ocp, otp;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo(sy, MODE_DIGITS);
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    otp=NormalizeDouble(OrderTakeProfit(), dg);
    if (ocp==otp) return(True);
  }
  return(False);
}
Familiarise yourself with the code of both functions and merge them into one to optimise for speed of execution and for your specific tasks...
 
eddy:
Sayod ,what timeframe have you traded on and with what parameters?


What's the difference or you have it reversed and want to test it?

Traded on h1 by default,

Pip step - 30

LotExpo - 1.59

I think the parameters don't matter too much if the idea has been implemented, I think the Expert Advisor will be good with any parameters, IMHO.

 
Jaguar1974:
I need to commit the fact of the open orders triggering by TakeProfit or StopLoss. I am not interested in the actual values of TakeProfit and StopLoss.

If you just want to register the fact of the order being triggered, then you can memorize the number of orders on the previous tick and compare it with the number of orders on the next tick - if the number of orders has changed, it means ....
 
kiimar:
The terminal closed the losing order with the comment "so:19.5%/28.4/145.8". What does this mean?
It means that when the free margin level of 19.5% was reached, a stopout occurred and the losing trade was closed according to the rules.
 
IgorM:

if Print() prints out, then surely you have start() working, but I am confused by your statement that the calculation takes 2-3 minutes - at such a load of the terminal you need to interrupt the calculations using the function sleep(), otherwise the terminal will definitely hang

Since MT4 has no debugger, insert Print() into doubtful code sections and catch the code sections and conditions that failed or did not fail.


Sorry, I've got it wrong, Print only works in init. I cannot get into start))

Yes, at the end of each function, I put print with a message about it, to check if everything is ok. And all messages (all functions) worked 100% until the end of the init, I can't go to start!

Thanks in advance for the answer!

 
Thanks, I still have a lot to learn.
artmedia70:
Familiarise yourself with the code of both functions and merge them into one to optimise for speed of execution and for your specific tasks...
 
BBSL:


Sorry, I misspoke, Print only works in inite. I can't get into start))

Yes, at the end of each function, I insert a print with a message about it to check if everything is ok. And all messages (all functions) have worked 100% until the end of the init, I can't go to start!

Thanks in advance for the answer!

So you frankly don't have a tick in the terminal. I.e. either it's not connected, or you're working on an offline chart, or check IsExpertEnabled() in the init and if it's not allowed, then enable EAs.

Reason: