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

 
BeerGod:

Translate the variable to be mapped to a print or comment in string DoubleToStr( double value, int digits) and set the desired precision.

https://docs.mql4.com/ru/convert/DoubleToStr

https://docs.mql4.com/ru/common/comment


Ok, thanks. I was also thinking of doing it that way, or building through ObjecCreate()...
 
okvseok:

please suggest a function that counts the number of losing orders (from the last one) to the last take profit...

Thank you!

You could try it like this:
//+----------------------------------------------------------------------------+
// Убыточно ли закрылся последний ордер, и подсчет количества
int fHistory(){
  int loss = 0;
  for(int i=OrdersHistoryTotal()-1; i >= 0; i--){               // Выборка в истории
     if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true){    // Если есть следующий в истории
        if(OrderMagicNumber()!=magN) continue;                // Ордера не нашего эксперта

        if(OrderProfit() < 0 ) loss = loss++;                 // Если убыток по посл.ордеру - считаем
        
        if(OrderProfit() > 0 ) return(loss);                  // Если прибыль, вернем количество убыточных
     }
  }
  return(-1);
}
 

how many times do I need to callOrderSelect before using OrderProfit(), OrderType() etc. ? is one time inside Start enough or does each time before using OrderProfit, OrderType etc...I need to callOrderSelect ?

and does OrderSelect have to be called immediately before OrderProfit or can it be called anywhere at the beginning, just as long as it is ??

 
hoz:

I wrote the question, but no one seemed to notice. I didn't want to write such a long question here so as not to confuse everyone. Please note...

https://www.mql5.com/ru/forum/142983

Try it this way:

int OrderCloseCount(double ordOpPrice, datetime ordOpTime)
{
  // slippage= Взять из OrderSend
  int timePlusMinus=20; // Пусть будет 20 сек.
  int count = 0;
  
  for (int i = OrdersHistoryTotal() - 1; i >= 0 ; i--)
  {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
      if (OrderSymbol() != Symbol()) continue;
          if (MathAbs(OrderOpenPrice()-ordOpPrice) <= slippage*Point && MathAbs(OrderOpenTime()-ordOpTime))< timePlusMinus)
              count++;
  }
  
   return (count);
}

Because there's no guarantee that your orders opened at exactly the same price and at exactly the same time.

 
hoz:

I wrote the question, but no one seemed to notice. I didn't want to write such a long question here so as not to confuse everyone. Please note...

https://www.mql5.com/ru/forum/142983

I have already given you a rough algorithm in that thread (slightly corrected it here for better understanding of some nuances) and there's no need to start a vegetable garden:


The algorithm is as simple as a bagel.

The partial closing does not change the Magic. The ticket changes, but the Magic does not.

There's an open pose and levels where this pose should be partially closed.

Suppose Level1, Level2 and Level3.

If the Buy position is in profit and Bid >= Level1 && Bid< Level2 ---> we close the first part of the position (with the lot that is smaller than the lot of this position, provided that the remaining lot is not less than the minimum lot), then:

If Bid >= Level2 && Bid< Level3 ---> close the second part of the position (by a lot smaller than the lot of this position, provided that the remaining lot is not less than the minimum lot), further:

If Bid >= Level3 && Bid<Level4 ---> close the third part of the position (by a lot smaller than the lot of this position, provided that the remaining lot is not less than the minimum lot), further:

1. If at the partial closing at the level Bid>=LevelX the lot has become less than the minimum lot ---> close the whole position

2) If after the third closing at the level Bid>=Level3 there is still a position, either accompany the remaining position with a trawl after Level4 is passed, or close it all at once.

That is all.

For Sell, we look at Ask: Ask<=Level1 && Ask>Level2 ... etc. ...

Do a loop on all our positions, select each of them by index, calculate its levels and closing lots for the selected position and enjoy the working algorithm ... :)

At the same time there is no need to store in the EA's memory (in variables) values of these levels, which is very convenient - if the EA for some reason finishes its work, then after the resumption it will not lose data on levels - it will recalculate them for each position on the fly.

One more thing: after a partial closing, do not forget to retrace the protective stop. After closing at level1 - stop at breakeven, after closing at level2 - stop at level1, after closing at level 3 - stop at level2, etc...


 
Hi all, does anyone have an example of an Expert Advisor using a custom indicator?
 
dimarik0000:
Hi all! Does anyone have an example of an EA using a custom indicator?
What is the problem?
 
artmedia70:
What is the problem?


I read the article on transferring a custom indicator to the Expert Advisor code and got confused. Should I do it or is it enough to specify certain parameters of the indicator in the code?
 
dimarik0000:

I read the article about porting a custom indicator into the Expert Advisor code and I am confused, should I do it or it is enough to specify only some specific indicator parameters in the code?
If you don't have much experience, you had better use iCustom() or thoroughly study and understand the working principle of the indicator before adding its logic to the Expert Advisor.
 

713
borilunad 15.01.2013 12:10

Could you please solve one mystery: Why when I inserted this function || isCloseLastPosByTake() == True || the expert in the tester started to slow down very much, times 10! This is one of the 4 mutually exclusive conditions, so I can't use the if chain as in summed conditions to make the code run faster. What can you advise me? Thank you in advance for your advice!