[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 132

 
Sergey_Rogozin:

Then I guess that's it:

Is that right?

int start()
 {
   ArrayResize(ValueArr,size);
   ValueArr[size-1] = GetValue();
   size++;
   return();
 }
 
alsu:

Now I get it.

Thank you.

 
IgorM:

there is no such built-in function, you have to write it yourself, I showed an example here:https://www.mql5.com/ru/forum/131277/page113


thanks

 
IgorM:

There is no such a built-in function, you have to write it yourself, I showed an example here:https://www.mql5.com/ru/forum/131277/page113

And how to prescribe that the Expert Advisor has only this one condition for opening trades.
 

alsu:

int start()
 {
   ArrayResize(ValueArr,size);
   ValueArr[size-1] = GetValue();
   size++;
   return();
 }

Then you don't need size-1, otherwise the first run will index 0-1 and the array size will be zero.

Then it should be like this:

int start()
 {
   size++;
   ArrayResize(ValueArr,size);
   ValueArr[size-1] = GetValue();
   return();
 }
 
artmedia70:

Then you don't need size-1, otherwise the indexing will be 0-1 and the array size will be zero on the first run.

Then it goes like this:



There initialization at the beginning of the program int size=1;

 
IgorM:

there is no such a built-in function, you have to write it yourself, I showed an example here:https://www.mql5.com/ru/forum/131277/page113

Why when I attach this code it opens an unbelievably large number of trades?
 
alsu:

There's an initialisation at the beginning of the program int size=1;


Didn't catch it... I only remember the first one, where size was originally zero.
 
sto_mat:

Why is it that when I attach this code it opens an unbelievably large number of trades?


It can't be, because in the code:

double history(){
int time = 0;double profit = 0;//обьявляем необходимые нам переменные куда мы положим интересующие нас характеристики ордера
for(int i = OrdersHistoryTotal();i>=0;i--){// Перебираем все закрытые ордера
  if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){//если ордер с таким номером (i) в списке закрытых ордеров есть ( не путать с тикетом)
    if(OrderSymbol() == Symbol()){//если выбранный ордер был открыт по нашей валютной паре
      if(time<OrderCloseTime()){//(сравниваем его с хранящимся в пероеменной time) 
        time=OrderCloseTime();//если время закрытия ордера больше - ложим его в переменную
        profit=OrderProfit();//и заодно запоминаем прибыль ордера
      }
    }
  }
}
//по окончании этой процедуры в наших переменных будут сидет наибольшее время закрытия, и его профит. Или по нулям если история чистая.
//теперь мы можем выставлять условия в зависимости от результата процедуры
   
if(profit == 0 &&time == 0){//действия если история чистая

}
if(profit >= 0){//действия если последний ордер был прибыльным, или нулевым

}
if(profit <  0 ){//действия если последний ордер был убыточным

}
return(0);
}


no trades https://book.mql4.com/ru/trading/ordersend

 
IgorM:


it can't be the same because in the code:

no trades https://book.mql4.com/ru/trading/ordersend


I've inserted

if(profit == 0 &&time == 0){//actions if history is clean

OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,Bid-6*Point);


return;
}
if(profit >= 0){// action if last order was profitable, or zero

OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-12*Point,Bid+12*Point);


return;
}
if(profit < 0 ){//actions if(profit < 0 ){/actions if last order was unprofitable

OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Bid+15*Point,Bid-15*Point);


return;
}
return(0);
}

Reason: