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

 
Alexander Antoshkin:

What can you...?

Calculate how many hobbits it takes to change a light bulb?

Send it to freelance? Write "read it there"?

How do I find the coordinate of closing series of orders in the history as in the example (I plan to draw a line at this point)

I've already asked this question on 151 pages of this thread, but no plausible solution has been found .https://www.mql5.com/ru/forum/160683/page151



You should look for a series of orders with the same close bar in the history. The time of this bar will be the one you are looking for.
 
Alexander Antoshkin:

What can you...?

Calculate how many hobbits it takes to change a light bulb?

Send it to freelance? Write "read it there"?

We CAN do a lot of things:)

The hobbit problem has no one-size-fits-all solution...

In case you didn't understand, my answer was from the same video thatVitalie Postolache quoted.

But seriously:

How do I find the coordinate of a deal closing a series of orders in the history as in the example (I plan to draw a line at this point)

I already asked this question on 151 pages of this thread, but no solution has been found. https://www.mql5.com/ru/forum/160683/page151

I have not read the branch by the link. But it would be like this:

Determine the fact of closing of several orders (one or different types) within X points (X points range is needed because in reality all deals may not close at the same price), determine the average closing price and draw a line by it.

 
Artyom Trishkin:
Search the history for a series of orders with the same closing bar. The time of this bar will be the one you are looking for.
This is the same problem as my method of solution: depending on ping and number of orders, all trades on the same candle may not close...
 
Alexey Kozitsyn:
Same problem as my solution method: depending on pings and number of orders, all trades on the same candle may not close...
For M1 I agree. For others it is unlikely. Unless a close order comes before the opening of the candle. There will be two sets of orders. Take the last of two adjacent ones.
 
Artyom Trishkin:
For M1 I agree. For others it is unlikely. If only before the opening of a candlestick an order to close has been received. There will be two sets of orders. Take the last of two adjacent ones.

Little data was given here to decide: several packs may be closed on the same candle (if you check on, say, hourly or daily candlesticks).

 
Vitalie Postolache:


I want parallel red lines, but I want them to intersect, and I want three of them to be green and the rest to be purple )))

Oh, yes, and that one straight line in the shape of a kitten!

Does the problem seem wrong to you?

 
Alexey Kozitsyn:

There is not enough data to decide: several packs may be closed on one candle (if you check, say, hour or daily candlesticks).

In any case the more accurate the better ...

the orders are closed in accordance with the trailing stop condition without a loss

i.e.

if(b+s>0)
{
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
{
tip = OrderType();
OSL = NormalizeDouble(OrderStopLoss(),Digits);
OTP = NormalizeDouble(OrderTakeProfit(),Digits);
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
SL=OSL;
if(tip==OP_BUY)
{
SL=NormalizeDouble(Bid-TrailingStop*Point,Digits);
if(SL>OSL && SL>NLb)
{
if(!OrderModify(OrderTicket(),OOP,SL,0,0,White)) Print("Error Order Modify ",GetLastError());
}
}
if(tip==OP_SELL )
{
SL=NormalizeDouble(Ask+TrailingStop*Point,Digits);
if((SL<OSL || OSL==0) && SL<NLs)
{
if(!OrderModify(OrderTicket(),OOP,SL,0,0,White)) Print("Error Order Modify ",GetLastError());
}

 
Alexey Kozitsyn:
Write your own MA indicator, which would include an additional buffer into which the values are entered when a new bar is formed.

I would like to discuss an algorithm for solving the issue, including for differentmoving average averaging methods.

 
Alexey Kozitsyn:

We CAN do many things:)

Determine the fact of closing several orders (of the same or different types) within X points (X points range is needed because in reality all deals may not close at the same price), determine the average closing price and draw a line by it.

int TotalPos=-1;

void start()
{
  if(OrdersTotal()!=TotalPos) { // не мучаем каждый тик
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
     if(OrderSymbol()==Symbol() && OrderType()<=1) {
      History();
     }
  }}} TotalPos=OrdersTotal(); // запомним количество
//--
} 
 
 void History() {
  string Ticket=(string)OrderTicket();
  color col=Red;
  if(OrderType()==0)col=Blue;
  datetime a=OrderOpenTime();
  double b=OrderOpenPrice();
  datetime c=OrderCloseTime();
  double d=OrderClosePrice();
  double prSep=OrderProfit()+OrderCommission()+OrderSwap();
  double prAll=0;
  int    cn=0;
  string hTicket;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
     if(OrderSymbol()==Symbol() && OrderType()<=1) {
      datetime ct=OrderCloseTime();
      // 60 секунд разницы между закрытием первой и последней в сетке
      if(c<=ct+60 && c>=ct-60) {
        prAll+=OrderProfit()+OrderCommission()+OrderSwap();
        hTicket=(string)OrderTicket();
        cn++;
      }
   }}}
   ObjectCreate(Ticket+'Open',OBJ_ARROW,0,a,b);
   ObjectSet(Ticket+'Open',OBJPROP_COLOR,col);
   ObjectSet(Ticket+'Open',OBJPROP_ARROWCODE,1);
      
   ObjectCreate(Ticket+'Line',OBJ_TREND,0,a,b,c,d);
   ObjectSet(Ticket+'Line',OBJPROP_COLOR,col);
   ObjectSet(Ticket+'Line',OBJPROP_WIDTH,1);
   ObjectSet(Ticket+'Line',OBJPROP_STYLE,STYLE_DOT);
   ObjectSet(Ticket+'Line',OBJPROP_RAY,0);
      
   ObjectCreate(Ticket+'Close',OBJ_ARROW,0,c,d);
   ObjectSet(Ticket+'Close',OBJPROP_COLOR,Green);
   ObjectSet(Ticket+'Close',OBJPROP_ARROWCODE,3);
  
   Ticket=cn>1?hTicket:Ticket;
   ObjectCreate(Ticket+'Profit',OBJ_TEXT,0,c,d);
   ObjectSet(Ticket+'Profit',OBJPROP_ANCHOR,0);
   ObjectSetText(Ticket+'Profit',DoubleToString(prAll,2),10,'Arial',White);
   ObjectSet(Ticket+'Profit',OBJPROP_PRICE1,d);
   ObjectSet(Ticket+'Profit',OBJPROP_TIME1,c+Period()*60*2);

this should be added to the script ...

Taking into account the fact that if a series of Sell orders are closed

ObjectCreate(Ticket+'Debt B',OBJ_HLINE,0,0,d);
ObjectSet(Ticket+'Debt B',OBJPROP_COLOR,LimeGreen);
ObjectSet(Ticket+'Debt B',OBJPROP_WIDTH,1);

if a series of buy orders are closed

ObjectCreate(Ticket+'Debt M',OBJ_HLINE,0,0,d);
ObjectSet(Ticket+'Debt M',OBJPROP_COLOR,Red);
ObjectSet(Ticket+'Debt M',OBJPROP_WIDTH,1);

Can you help?
 
-Aleks-:

I would like to discuss the algorithm for dealing with the issue, including for differentmoving average averaging methods.

Have a look at the file MovingAverages.mqh in the Include folder of the terminal.
Reason: