Questions from Beginners MQL5 MT5 MetaTrader 5 - page 834

 
Pavel Nikiforov:
Please explain what the problem is. The function is supposed to look through all open positions and calculate the number of positions with a given magic number. In fact it only picks one from the list opened by another EA with the same Ticket and Magik and therefore count is always =0.

I've figured it out myself, the selection has to be done viaPositionGetSymbol:

//+------------------------------------------------------------------+
int OpenPositions()//проверка открытых позиций по Magic number 
  {
   int count=0;
     for(int z=PositionsTotal()-1; z>=0; z --) // Перебор всех позиций
     {
       if(PositionGetSymbol(z)!=_Symbol) // Найдена позиция с заданным символом
        {
         Print(__FUNCSIG__" позиция не выбрана ",GetLastError()); continue;
        }
      long  ticket = PositionGetInteger(POSITION_TICKET);
            Print(__FUNCSIG__" ТИКЕТ ", IntegerToString(ticket));
      ulong myMN=PositionGetInteger(POSITION_MAGIC);
            Print(__FUNCSIG__" МАГИК ", IntegerToString(myMN));
      if(myMN==Magic)
            count++;
     }
   return(count);
  }
//+------------------------------------------------------------------+
 
Pavel Nikiforov:

I've figured it out myself, the selection has to be made usingPositionGetSymbol:

Not well figured out. You have to select on the hadge account using the PositionGetTicket(i) function and then check the symbol and the magik.

Документация по MQL5: Торговые функции / PositionGetTicket
Документация по MQL5: Торговые функции / PositionGetTicket
  • www.mql5.com
Торговые функции / PositionGetTicket - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 
Alexey Viktorov:

It's not good to figure it out. You have to select on the hadge account with the PositionGetTicket(i) function and then check the symbol and magik.

Yeah, that's better, the other functions were glitchy in the demo too, but now it works.

 

Hello, could you advise me on this indicator https://www.mql5.com/ru/forum/94447#comment_6780067

It puts red and blue circles on the chart when the price changes drastically, i.e. when the price changes 4 pips or more,

I need these signals to go only when the price changes by 10 pips or more

Files:
1.png  48 kb
 
yesterday35:

Hello, could you advise me on this indicator https://www.mql5.com/ru/forum/94447#comment_6780067

It puts red and blue circles on the chart when the price changes drastically, i.e. when the price changes 4 pips or more,

I want these signals to go only when the price changes by 10 pips or more.

This indicator calculates not pips, but sigma or RMS (root-mean-square deviation). On a sample of the last N ticks (50 by default). It builds a channel of 3 sigmas. If price has jumped out of the channel, it will mark this place. But the main problem is that the initial price series has not normal distribution with very heavy tails. In fact, this indicator is a toy-help.

 

Hello.

I'm writing a small program. I'm faced with a completely unintelligible situation.

In my code, there are these two lines. They are at the very end of OnTester() and are not in the loop.

Print("Мат ожидание ставки  ",MatOgidanieStavk(KKef,VVer,Stavka)," Ставка ",Stavka);
Print("Ставка =",Stavka);

And here is an unexpected result of executing these lines.

Мат ожидание ставки  447.0461599959392 Ставка -1.0
Ставка =3912.820000338397

Here is the definition of theMatOgidanieStavk function

double MatOgidanieStavk(double Kef,double Ver,double &BestStavka)
{
 .......... 
   BestStavka=-1;// Первое обращении к этой переменой.
............
return MatOgidanie;
}
 
pivomoe:

Hello.

I'm writing a small program. I'm faced with a completely unintelligible situation.

In my code, there are these two lines. They are at the very end of OnTester() and are not in the loop.

And here is an unexpected result of executing these lines.

Here is the definition of theMatOgidanieStavk function

Stavka is initialized before the print?

how is it determined that the call is the first inside the function?

what result did you expect?

 

Thank you. I solved the problem.

It turned out that theStavka variable before Print. was equal to -1. Its value was passed into the Print function and saved as a copy. My functionMatOgidanieStavk changed theStavkavariable itself, not its copy that will print.

 
That's how it should be.

2795/2797 will be 0. Because rounding is not performed. Either s3 = (double)s2/s1; or select double for s2 and s1

Reason: