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

 
MakarFX #:

You have the condition to open two at once if there are no open ones.

What's that?

double GetLotSize()
  {
   double Ls=0;
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL) {Ls=OrderLots();}
           }
        }
     }
   return Ls;
  }    

This thing counts the current lot.

This parameter is set in the settings: LotControl

respectively, when: GetLotSize()>LotControl - I need it to open vOrderOpenSell() on bSignalBuy() signal.

Yes, I know that both orders are opened by the condition. I wrote it that way in the beginning. But how should I make vOrderOpenBuy() not open?

 
Mihail Matkovskij #:

If the robot has already entered the market in one direction, it does not enter again in the same direction. Is this how your entry algorithm works?

If this condition ismet, it triggers

After

And also when there is a sell signal.

Then, the reason for entering in the opposite direction is because the condition is triggered

Yes. That's what I need. BUT it needs to stop/exclude a forward entry by this condition:

GetLotSize()>LotControl
 
Kedrov #:

Thank you, Makar, for messing with me!

Here's a screenshot.

Yes, you made a mess)

Now in each folder, one by one, rename folders Experts to _Experts and Indicators to _Indicators.

Renamed in one folder - start terminal, if it didn't help - rename it back and go to the next folder.

P.S. The first time the terminal will take a little longer to start than usual.

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

this thing counts the current lot size

this parameter is set in settings: LotControl

respectively, when: GetLotSize()>LotControl - I need vOrderOpenSell() to happen upon signal bSignalBuy().

Yes, I know that both orders are opened by the condition. I wrote it that way in the beginning. But how should I make vOrderOpenBuy() not open?

        if((bSignalBuy() == true)&&(GetLotSize()>LotControl))
           vOrderOpenSell();
        else
        if(bSignalBuy() == true)
           vOrderOpenBuy();
         
 
законопослушный гражданин #:

yes. that's what i need. BUT it needs to stop/exclude forward entry by this condition:

I'm confused by this condition

// Если нет открытых ордеров, то входим в условие
      if(CountOrders()==0)
     {

with this condition

GetLotSize()=0
 
MakarFX #:

Thank you. Corrected. I'll be thinking about it.

 
MakarFX #:

I'm confused by this condition

With that condition.

it looks like you're right.

Right:

 if((bSignalBuy() == true)&&(GetLotSize()>LotControl))
         vOrderOpenSell();
         else
         if(bSignalBuy() == true)
         vOrderOpenBuy();

does not react at all to the condition (GetLotSize()>LotControl)

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

it looks like you're right.

Right:

doesn't react at all to the condition (GetLotSize()>LotControl)

GetLotSize() must be taken from the last closed one, then at

// Если нет открытых ордеров, то входим в условие
      if(CountOrders()==0)
     {

(GetLotSize()>LotControl) will work
 
MakarFX #:

GetLotSize() should be taken from the last closed one, then at

(GetLotSize()>LotControl) will work

thanks a lot!

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

yes. that's what i need. BUT in doing so, you need to stop/exclude forward entry by this condition:

if (bSignalBuy()) {
  if (GetLotSize() > LotControl)
    vOrderOpenSell();
  else
    vOrderOpenBuy();
}
double GetLotSize()
  {
   double Ls=0;
   datetime last = 0, openTime;
   for (int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if (OrderSelect(pos, SELECT_BY_POS, MODE_TRADES))
        {
         if (OrderSymbol() == _Symbol && OrderMagicNumber() == Magic)
           {
             if(OrderType() == OP_BUY || OrderType() == OP_SELL) {
               if ((openTime = OrderOpenTime()) > last) {
                 last = openTime;
                 Ls = OrderLots();
               }
             }
           }
        }
     }
   return Ls;
  }