[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 898

 
Dimka-novitsek:
Same situation.
Show the code
 
arvis:
How can I set the indicator to count profit in pips from a certain time in MT4?

If you want it to be based on time, this is how it will be when the price closes, and if you want it to count points from 21:00, then you have to play with time and there is nothing complicated about it.

 double Profit; // или double Profit = 0;

 int start {

 double PrevCl

 double CurrCl

PrevCl = iClose(Symbol(), 0, 2);
CurrCl = iClose(Symbol(), 0, 1);

if (PrevCl > CurrCl){ 

if (Ask > signal) {

 Profit = (Ask - signal);

return (Profit); 

} 

 if (Bid < signal) {

 Profit = (signal - Bid);

return (Profit); 

    }
  } 
}
 

Please advise how to make the following code correct:

double LastOpenOrder() {
   double l_ord_open_price_8;
   int l_ticket_24;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) {
      OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_open_price_8 = OrderOpenPrice();
            ld_unused_0 = l_ord_open_price_8;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_open_price_8);
}

So that I can do like this:

if (LastOpenOrder - Bid >= 25 * Point) CloseOrder;

That is to close only this last open order, do not touch the others!

Thanks in advance.

 

How do I correctly write in my EA and get indicator result in it?

double ROC = iCustom(NULL,0, "ROC",12,0,0); - no data output.

double ROC = iCustom(NULL,0, "ROC",12,0,0,0); - the data is not printed.

double ROC = iCustom(NULL,0, "ROC",12,0,0,0,0); - the data is not printed.

Indicator: https://www.mql5.com/ru/code/9340

 
DhP:

How do I correctly write in my EA and get indicator result in it?

double ROC = iCustom(NULL,0, "ROC",12,0,0); - no data output.

double ROC = iCustom(NULL,0, "ROC",12,0,0,0); - the data is not printed.

double ROC = iCustom(NULL,0, "ROC",12,0,0,0,0); - the data is not printed.

Indicator: https://www.mql5.com/ru/code/9340

The correct way would be like this:

double ROC = iCustom(NULL,0,"ROC",0,0);

but I can't understand what you're going to do with it. well, maybe I don't need to understand it )

 
belck:

If you want to use time, this is how it will be when the price closes, and if you want to use 21:00, then you have to play with time and there is nothing complicated about it.


Thanks for the help, belck.

Tell me, how can you calculate the same profit amount in pips, if you trade on several pairs? Besides, you have to take into account closed deals.

 
arvis:


Thanks for your help, belck.

How do I calculate the same profit in pips if I trade on several pairs? Besides, you have to take into account closed trades as well.

It is difficult for me to answer this question.

But I can tell one thing that all this should be called.

 int start {

 double PrevCl

 double CurrCl

PrevCl = iClose(Symbol(), 0, 2); // то тут указываете какая валютная пара и по желанию период : PrevCl = iClose("EURUSD", PERIOD_H1, 2);
CurrCl = iClose(Symbol(), 0, 1); // тут так же

if (PrevCl > CurrCl){ 

if (Ask > signal) {

 Profit = (Ask - signal);

return (Profit); 

} 

 if (Bid < signal) {

 Profit = (signal - Bid);

return (Profit); 

    }
  } 
}

the price of the last open order is called like this:

double LastOpenOrder() {
   double l_ord_open_price_8;
   int l_ticket_24;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) {
      OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_open_price_8 = OrderOpenPrice();
            ld_unused_0 = l_ord_open_price_8;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_open_price_8);
}
 
Everything is more or less clear. Thank you very much for your time, belck.
 
arvis:


Thanks for the help, belck.

How do I calculate the same profit in pips if I trade on several pairs? I have already started to do it this way, but I'm not sure how to do it.

I started to do it this way, but I now understand that I got confused:

double LastOpenPriceCloseOrder() {
   double l_ord_open_price_8;
   int l_ticket_24;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersHistoryTotal( )  - 1; l_pos_16 >= 0; l_pos_16--) {
      OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_open_price_8 = OrderOpenPrice();
            ld_unused_0 = l_ord_open_price_8;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_open_price_8);
}

и

double LastClosePriceCloseOrder() {
   double l_ord_open_price_8;
   int l_ticket_24;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersHistoryTotal( )  - 1; l_pos_16 >= 0; l_pos_16--) {
      OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_open_price_8 = OrderClosePrice();
            ld_unused_0 = l_ord_open_price_8;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_open_price_8);
}
 

This is the criteria I am stumped on:

- If there was more than one order closed, their total number of profitable pips should be counted, but it is pips that should be counted.

Please advise how to proceed correctly in this code:

LastBuyPrice = FindLastBuyPrice();     

if (Ask - LastBuyPrice >= 25 * Point) {
      for (int l_pos_16 = OrdersTotal()  - 1; l_pos_16 >= 0; l_pos_16--) {
 OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumberBuy) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberBuy && OrderType() == OP_BUY) {
         CloseThisSymbolAll();
         Print("Closed All due to Stop Out");
         }
       }
     }


double FindLastBuyPrice() {
   double l_ord_open_price_8;
   int l_ticket_24;
   double ld_unused_0 = 0;
   int l_ticket_20 = 0;
   for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) {
      OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumberBuy) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumberBuy && OrderType() == OP_BUY) {
         l_ticket_24 = OrderTicket();
         if (l_ticket_24 > l_ticket_20) {
            l_ord_open_price_8 = OrderOpenPrice();
            ld_unused_0 = l_ord_open_price_8;
            l_ticket_20 = l_ticket_24;
         }
      }
   }
   return (l_ord_open_price_8);
}
Reason: