[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 383

 
7777877:

Good afternoon. I have the following question. TheMQL4book located at MQL4.community, in the "Simple MQL Programs " section, contains an example of tradingexpert.mq4 with the following content (see attached file). External variables extern double StopLoss =200 and extern double TakeProfit =39 are declared in block 1-2. Block 8-9 calls of the New_Stop(StopLoss) and New_Stop(TakeProfit) functions are used to calculate SL and TP parameters. There is a description of the function in block 11-12.

Question: The formal parameter of New_Stop function has int type(int Parametr), while the parameters passed in function call New_Stop(StopLoss)(New_Stop(TakeProfit)) have double type... In MQL4 book, found at MQL4.community in chapter "Language Fundamentals" in section "Functions", subsection "Function Properties" says "The number, type and order of parameters passed in a function call must match the number, type and order of formal parameters passed in the function description (the exception is a function call that has default parameters - see Function Call and Function Description and Return Operator. How to explain this contradiction: according to the latter, when declaring StopLoss and TakeProfit variables, I should have indicated int type, not double(the compiler gives no error)?

Thanks in advance for the answer, not to litter the forum.

The external parameters (extern double StopLoss =200; extern double TakeProfit =39; ), in principle, should be of integer type (more exactly, according to author's idea - it is a value in points). When calling the function, the implicit type conversion is used. The floating-point type is converted to integer type with loss of precision. In this case it doesn't matter: the size of stop and profit as intended is set in pips - it is always integer.

IMHO, the example code is poorly written.

Using the absolute value of constants is a very bad and wrong style, with mnemonic names.

         if (OrderType()>1)                     // Попался отложенный
           {
 

The worst implementation of the order enumeration: it's hard to think of a more "retarded" one. It seems to be deliberately slow: extra calculations, unnecessary function calls - the most expensive operation in terms of time, and on each iteration of the loop. And this despite the fact that the number of orders does not change inside the loop.

   for(int i=1; i<=OrdersTotal(); i++)          // Цикл перебора ордер
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:
 
Sorry, but I used to work on Rumuse and now I'm learning MT4. I'm still a "Dummie" here . 11 .09 . I can't start the quotes. Please tell me what is wrong. I will be glad to help you.
 
vitor:
Sorry, but I used to work on Rumuse and now I'm learning MT4. I'm still a "Dummie" here . 11 .09 . I can't start the quotes. Please tell me what is wrong. I will be glad to help you.
Open a new demo account, if that doesn't work reinstall the terminal.
 
Hi, can you tell me how to disable an EA if an order opened by the same EA is closed by a trader, or by SL or TP.
 
eropov:
Hello, can you tell me how to disable an EA if an order opened by the same EA is closed by a trader or by SL or TP.
You see, that's what advisors are, you don't have to advise them... and if an order is open, don't worry, Uncle Kolya will come and close everything.
 

BeerGod

Понимаете, советники на то и советники, что не нужно им советовать... а если ордер открыт, то не переживайте, дядя Коля прийдет и всё закроет.

So it is not possible to stop the EA working?

 
eropov:

BeerGod

So it is not possible to stop the EA?

Disable the EA by pressing the button in the terminal, and the order cannot be rolled back of course, close it manually.


 

BeerGod

Disable the EA by pressing the button in the terminal and the order cannot be rolled back, of course, close it manually.

I am writing an owl which opens an order with SL and TP.

I need a condition that if an order is closed by TP or closed by a trader I have to stop the EA. How to implement this programmatically?

 

Help me solve the problem, why if the loop has only 2 passes i first equals 0 and then immediately equals 4?

for(i=0,g=0,c=0;i<OrdersTotal();i++)
    {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;
    if(OrderMagicNumber() == MasterMagicNumber)
      {
      starttime = OrderOpenTime();
      ArrayResize(prices,ArraySize(prices)+TradesCount);
      if(OrderSelect(i+1,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber() == MasterMagicNumber) endtime = OrderOpenTime();
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      times[i] = starttime;
      times[i+1] = endtime;
      tickets[i] = OrderTicket();
      symbol = OrderSymbol();
      Alert(i);
      while(g < TradesCount*(i+1))
        {
        if(OrderType() == OP_BUY)
          {
          if(g == TradesCount*i)
            {
            prices[g] = OrderOpenPrice()-LowOpen*Point;
            }else
            {
            prices[g] = prices[g-1]-step*Point;
            }
          }
        if(OrderType() == OP_SELL)
          {
          if(g == TradesCount*i)
            {
            prices[g] = OrderOpenPrice()+HighOpen*Point;
            }else
            {
            prices[g] = prices[g-1]+step*Point;
            }
          }
        g++;
        }
      }
    }

From this script the alert outputs 0, 4.

 
Помогите решить задачу, почему если в цикле всего 2 прохода i сначала равна 0, а затем сразу равна 4?

As far as I understand the code

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;

does a break, which means we go to the beginning of the loop and increase i according to the loop condition

probably like this

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) {i--; break; }

Reason: