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

 
законопослушный гражданин #:

made. absolutely no different from the previous magazine.

no errors, or anything else.

There shouldn't be any errors, show the log
 
for(int i = 0; i <= OrdersTotal(); i++)
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
            return(false);

Don't you need brackets for the loop? It seems that only when there is not more than one line you don't need them.

UPD:
Ah got it, there is one line.

 
MakarFX #:
There shouldn't be any errors, show the log

here are the last pages of the logbook from MT4.

is this log needed?

Files:
0w11cw.txt  30 kb
 
Oh, sorry. Got the comparison and assignment mixed up. It's all right now. I've been going crazy ever since I sat down to write. I'm writing badly and getting stressed out, and my head doesn't work at all, though I knew that, of course.
 
законопослушный гражданин #:

here are the last pages of the logbook from MT4.

is this log needed?

Here is the answer in your log)

The function bCheckOrders() after opening an order gives out that there are no orders, so they keep opening

 
pribludilsa #:
And my head doesn't work at all, though I knew that, of course.

You have a funny way of putting it)))

 
MakarFX #:

You have a funny way of putting it)))

I mean, knew how to write assignment and comparison, but got confused anyway. Confused.
 
pribludilsa #:
I mean, knew how to write assignment and comparison, but still got confused. Messed up.

That's not what I mean...

pribludilsa #:
and my head doesn't work at all, although I knew that of course.

 
MakarFX #:

Here is the answer in your log)

The bCheckOrders() function after opening an order gives out that there are no orders, so it keeps opening

Oh my god. Where does it say that?

maybe i did not read the log correctly?

The functionbCheckOrders()after opening an order prints that there is no order, therefore opening continues - by void OnTick() - I understand that this is not true.

until the order is closed bCheckOrders() - can not give out that there is no order.

 
законопослушный гражданин #:

Oh, shit. Where does it say that?

maybe i did not read the log correctly?

The functionbCheckOrders()after opening an order gives out that there is no order, therefore the opening continues - by void OnTick() - I understand that this is not true.

until the order is closed bCheckOrders()-can not show absence of an order.

bCheckOrders() does not work correctly!

I already wrote you a function for counting orders.

Just do it like this and it should work.

Instead of bCheckOrders(), put this function

//+------------------------------------------------------------------+
//| Подсчет открытых ордеров                                         |
//+------------------------------------------------------------------+
int CountOrders() 
  {
   int cnt=0;
   int i=OrdersTotal()-1;
   for(int pos=i;pos>=0;pos--)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol)
           {
            if(OrderMagicNumber()==Magic) cnt++;
           }
        }
     }
   return(cnt);
  }

And in OnTick(), instead of bCheckOrders(), write this

//+------------------------------------------------------------------+
void OnTick()
  {
// Получим значение индикатора
   dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.

// Если нет открытых ордеров, то входим в условие
   if(CountOrders()==0)
     {
// Если появился сигнал на покупку, то откроем ордер на покупку
      if(bSignalBuy() == true)
         vOrderOpenBuy();

// Если появился сигнал на продажу, то откроем ордер на продажу
      if(bSignalSell() == true)
         vOrderOpenSell();
     }
// Проверяем, вышел ли текущий баланс по открытому ордеру за вилку из внешних переменных CountLoss и CountProfit

  if(GetProfitFromStart()>CountProfit || GetProfitFromStart()<CountLoss*-1)
     {
// Если да, то закроем ордер по текущей цене, не дожидаясь стопа или тейка
      CloseOrder();
     }
DrawLABEL("lab_Take",1,5,0,Color(GetProfitFromStart()>0,Lime,Red),StringConcatenate("Profit: ",DoubleToStr(GetProfitFromStart(),2),AC));
  }
Reason: