Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 137

 
artmedia70:
Just keep in mind that the variable is reinitialised on restart. So this approach is acceptable for a tester, but not for real trading.


Thanks for the information, what to do then? Should I just write the value into GV ??? Or is there some other option for real trade...

 
ALXIMIKS:

Thanks for the information, what should I do then? Score the value in GV ??? Or is there some other option for real...
Forget the global flags. I don't know why you need flags and what they indicate. That's why it's hard to advise in relation to your situation.
 
Zolotai:
Folks, could you suggest an indicator? It's based on two slides. And when it crosses it gives out the direction as arrows. Can't find it, thanks.
i-PSI@MA_Signal from here.
 
ALXIMIKS:

Good afternoon, if it's not too difficult, please advise a newbie:

1) How to declare an array of size equal to the value of some variable? (if i=7 declare array double Muss[7] and so on);

already answered

2) Why is an array in a user function considered declared and used adequately if the condition is always false?

while (false){

Alert("aaaaaaaaaaa" );

static double Buf_max [9000000];

static double Buf_min [9000000];}

because it was declared as static. In MQL, all static variables are initialized before calling the init() function

3) Is there a difference in a user function and in general between a simple array and a static array?

a simple array will be initialised the first time you enter the function where it's declared. However, on exit, if you've resized it before, the new value won't be reset, and the next time the function is called, the array will be the same size as we left it last time.

That is, by and large, the difference between simple and static is only in the moment of initialization.

 
What can be done on error "1"-->(no error, but result unknown) ?
 

I've been writing a function here to delete pending orders. But for some reason it doesn't delete them. Here is the code:

void DeletePendingOrders()
{
    int NumberOfTry = 0,
        err,
        ticket;

   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() > 1)
      {
         ticket = OrderTicket();
      
         while (NumberOfTry < 3)
         {
            while (!IsTradeAllowed()) Sleep(5000);
      
            if (OrderDelete(ticket, Red))
                NumberOfTry = 3;
            else
                err = GetLastError();
      
            if (err > 0)
            { 
              Print(NumberOfTry," #",ticket," Error modifing order: (", err , ") ");
              Sleep(5000); RefreshRates(); NumberOfTry++;
            }
         }
      }
   }
}

Why doesn't it work properly? I understand that it can be rewritten differently, but I want to understand why this code does not perform its purpose.

 
hoz:

I've been writing a function here to delete pending orders. But for some reason it doesn't delete them. Here is the code:

Why doesn't it work properly? I understand that it can be rewritten differently, but I want to understand why this code does not work as intended.

I would insert one line, so as not to change the code in particular:

            while (!IsTradeAllowed()) Sleep(5000);
            err=0;
            if (OrderDelete(ticket, Red))
                NumberOfTry = 3;
            else
                err = GetLastError();
      
            if (err > 0)
 
Sepulca:

I would have inserted one line so as not to change the code in particular:


And what will this give us? Still no orders closed and no errors.

The code has been changed:

void DeletePendingOrders()
{
    int NumberOfTry = 0,
        err,
        ticket;

   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() > 1)
      {
         ticket = OrderTicket();
      
         while (NumberOfTry < 3)
         {
            while (!IsTradeAllowed()) Sleep(5000);
                err = 0;
              Print("IsTradeAllowed() = ", IsTradeAllowed());
              Print("err = ", err);

            if (OrderDelete(ticket, Red))
            {
                NumberOfTry = 3;
                Print("NumberOfTry", NumberOfTry);
            }
            else
            {
                err = GetLastError();
                Print("err = ", err);
            }
      
            if (err > 0)
            { 
              Print(NumberOfTry," #",ticket," Error modifing order: (", err , ") ");
              Sleep(5000); RefreshRates(); NumberOfTry++;
            }
         }
      }
   }
}

The right part of the logbook:

2013.09.11 22:24:19     2012.01.02 08:05  Perevorot EURUSD,M5: modify #10 sell stop 0.01 EURUSD at 1.29279 sl: 0.00000 tp: 1.29179 ok
2013.09.11 22:24:19     2012.01.02 08:05  Perevorot EURUSD,M5: open #10 sell stop 0.01 EURUSD at 1.29279 ok
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: Ôóíêöèÿ DeletePendingOrders çàâåðøåíà
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: NumberOfTry3
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: delete #9 sell stop 0.64 EURUSD at 1.29279 sl: 0.00000 tp: 1.29179 ok
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: err = 0
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: IsTradeAllowed() = 1
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: Ôóíêöèÿ ClosePosBySortLots çàêðûëà âñå ðûíî÷íûå îðäåðà
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: close #3 sell 0.01 EURUSD at 1.29303 tp: 1.29203 at price 1.29487
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: close #4 buy 0.02 EURUSD at 1.29403 tp: 1.29503 at price 1.29480
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: close #5 sell 0.04 EURUSD at 1.29286 tp: 1.29186 at price 1.29487
2013.09.11 22:24:19     2012.01.02 08:02  Perevorot EURUSD,M5: close #6 buy 0.08 EURUSD at 1.29386 tp: 1.29486 at price 1.29480
It turns out that the order is deleted. But one. There was another one, another one. But it was not deleted. But the cycle is for all the orders.
 

Watch your NumberOfTry variable

it must be zeroed for each ticket, otherwise it will be assigned a value of 3 or more and further conditions will not be executed for all tickets.

only one will satisfy the condition

 
ALXIMIKS:

Watch your NumberOfTry variable

it must be zeroed for each ticket, otherwise it will be set to 3 or more and then the conditions will not be executed for all tickets.

Is there an implementation?
Reason: