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

 
How many test cycles can a hard disk drive withstand? In the sense of how quickly it will die? Have there been any such cases?
 
macleta:

Hi. I want to close differently directed positions when profit =0 Different number of buy and sell positions, different lot sizes.

What is wrong with the average price search function, i.e. the zero profit point?

double AveroProf(string sy="", int op=-1, int mn1=-1) 
   {
 

   double Buylots=0;
   double Buysum=0;
   double Selllots=0;
   double Sellsum=0;
 
   double zeroprice=0;
 
   for (int i=0; i<OrdersTotal(); i++)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderMagicNumber()!=mn1) continue;
      if (OrderType()==OP_BUY)
      {
       Buylots+=OrderLots();
       Buysum+=OrderLots()*OrderOpenPrice();
      }
      if (OrderType()==OP_SELL)
      {
       Selllots+=OrderLots();
       Sellsum+=OrderLots()*OrderOpenPrice();
      }
   
   }
   if ((Buylots-Selllots)>0)
   zeroprice=NormalizeDouble((Buysum - Sellsum)/(Buylots - Selllots),_Digits);

   return( zeroprice);
   }
 
Vladimir Pastushak:

I believe this code only works for differently directed 2 orders

If there will be multiple Buy and Sell orders and all with different open prices, it seems this does not work - you need to take into account the profit of the order and the point value in the currency

i have looked at what i have at hand, i did not find anything, but i do know that i have tested this code

it seems there is an indicator in QB that correctly calculates levels for differently directed orders - I looked for and found it last year

 
macleta:

Hello, I want to close differently directed positions when profit =0 Different number of buy and sell positions, different lot sizes.

What is wrong with the average price search function, i.e. the zero profit point?

If you want to put stops, it's better not to do this on multidirectional positions. Although with a tight spread, of course, it might work fine. But even these brokerage companies have moments when the spread jumps. That is why the best variant is to calculate profit and close positions when it is a little bit more than 0(slippage is still considered). That is, work with the current market moment.
Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
Igor Makanu:

I believe this code only works for differently directed 2 orders

If there will be multiple Buy and Sell orders and all with different open prices, it seems this does not work - you need to take into account the profit of the order and the point value in the currency

i have looked at what i have at hand, i did not find anything, but i do know that i have tested this code

it seems there is an indicator in QB that calculates correct levels for opposite orders - i searched last year and found it

Then you didn't check it properly... This is a classic 100% calculation 0

 
Vladimir Pastushak:

Then you haven't checked it properly... This is a classic 100% calculation 0

Well, I'm not even going to argue, come back to earth, try to check where you will have a breakeven level if you put it from top to bottom on the chart

1. Buy - Buy - Buy - Sell - Sell - Sell

2. buy - sell - sell - sell - buy - buy

this is the correct calculationhttps://www.mql5.com/ru/code/10007 version 2 , this is the calculation to use

      if(BuyLots>0) BuyPrice = Bid - ((BuyProfit + SellProfit - MyProfit) / (TickValue * BuyLots) * Point); //уровень безубытка для всех BUY ордеров
      if(SellLots>0) SellPrice = Ask + ((SellProfit + BuyProfit - MyProfit) / (TickValue * SellLots) * Point); //уровень безубытка для всех SELL ордеров


better check your classic calculation

 
Are the quotes stored in the tester/history folder?
 

Hi, help a beginner with a simple task. The indicator in a separate window shows fractional numbers 0.123456 1.123456 and I need integers like 123 1123

Anybody care to give me a hint on how to fix this?

 
potom:

Hi, help a beginner with a simple task. The indicator in a separate window shows fractional numbers 0.123456 1.123456 and I need integers like 123 1123

Anybody care to give me a hint on how to fix this?

int value = (int) 0.12456789*1000000;

The easiest thing I could think of)

 
Konstantin Nikitin:
If you want to put stops, it's better not to do it on multidirectional positions. This is a very good idea to place stops on these positions. But even these brokerage companies have moments when the spread jumps. That is why the best variant is to calculate profit and close positions when it is a bit more than 0 (slippage is still considered). That is, work with the current market moment.

Trying pyramiding, building up with a smaller lot on the trend but with opposing open.

Thanks to everyone who helped.

Reason: