Questions from Beginners MQL5 MT5 MetaTrader 5 - page 798

 

Hello! I need your help, forum members. I am writing an indicator. I need an opening time of the bar to be processed. It would seem that this time should be stored in time[], but there is some nonsense.

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---check for rates total


   if(rates_total<2)
      return(0);
//--- starting work
   int start=prev_calculated-1;
//--- correct position
   if(start<1) start=1;
//--- main cycle

CalculateVolume(start,rates_total,time);


//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CalculateVolume(const int nPosition,
                     const int nRatesCount,
                     const long &tim[],
                     )
  {
  
MqlDateTime dat1;


for(int j=nPosition;j<nRatesCount && !IsStopped();j++)
{
    TimeToStruct(tim[j],dat1);

    Print("год ",dat1.year," ",dat1.day," ",dat1.hour," ",dat1.min)


 }
} 

2017.11.20 17:48:01.590 (RTS-12.17,M1) year 2016 29 15 26

2017.11.20 17:48:01.734 (RTS-12.17,M1) year 2016 29 15 27

2017.11.20 17:48:01.878 (RTS-12.17,M1) year 2016 29 15 29

2017.11.20 17:48:02.022 (RTS-12.17,M1) year 2016 29 15 33

2017.11.20 17:48:02.165 (RTS-12.17,M1) year 2016 29 15 45

2017.11.20 17:48:02.310 (RTS-12.17,M1) year 2016 29 21 12

2017.11.20 17:48:02.454 (RTS-12.17,M1) year 2016 1 20 54

2017.11.20 17:48:02.599 (RTS-12.17,M1) year 2016 2 12 52

2017.11.20 17:48:02.743 (RTS-12.17,M1) year 2016 2 22 28

2017.11.20 17:48:02.887 (RTS-12.17,M1) year 2016 2 23 20

2017.11.20 17:48:03.031 (RTS-12.17,M1) year 2016 3 11 47

2017.11.20 17:48:03.175 (RTS-12.17,M1) year 2016 3 22 34

2017.11.20 17:48:03.320 (RTS-12.17,M1) year 2016 3 22 35

2017.11.20 17:48:03.463 (RTS-12.17,M1) year 2016 4 21 56

2017.11.20 17:48:03.609 (RTS-12.17,M1) year 2016 4 23 32

It feels like there are only a few bars per day. Can you give me a hint plz, my brain is already screwed up.

 
fxsaber:

Yes, but crooked.

pivomoe:
At first glance CopyTick works in the tester. Are there any known bugs in CopyTicks operation in the tester ? CopyTicksRange in real life works without bugs ?

In next build developers will make correct display of TRADE flags in the tester.

fxsaber:

There is a bug with tick times in the tester. We have to subtract a certain value each time. SD is aware of the problem.

Can you elaborate on this ?
 
I am studying the structure of trade request (MqlTradeRequest) in different variants. I took the ready-made my_first_ea.mq5 Expert Advisor from https://www.mql5.com/ru/articles/100 and tried to change the condition to open a position at SAR crossing in the source code - it worked. Then I added trailing code (change/modify position by SAR) from MQL5 using MqlTradeRequest structure. But it produced error [Invalid stops]. I think there is something wrong with the request. In short, I got stuck in studying position modification. I don't really understand what I am doing wrong.
Files:
SAR_SAR.mq5  27 kb
 
Alexey Kozitsyn:

Can you elaborate on that?

void OnTick()
{
  MqlTick Ticks[];
  
  if (CopyTicksRange(_Symbol, Ticks) != -1)
  {
    ArrayPrint(Ticks);              
    
    ExpertRemove();
  }
}
 
Thanks for your help, so many willing to help!!!!!!!!!!!! I'm tired of reading the comments on my code..............
 
DCodec:
Thanks for your help, so many willing to help!!!!!!!!!!!! I'm tired of reading the comments on my code..............
No code, no comments.
 

Please advise how to find out the price step (in the "Teak size" specification)?

 
Aleksey Vyazmikin:

Please advise how to find out the price step (in the "Teak size" specification)?

ht

 
Vladislav Andruschenko:
ht


Thank you! I searched and couldn't find it...

Then the next question, let's say the step is 25, then how to arrange rounding to a number divisible by 25, maybe there is a function?

 
Aleksey Vyazmikin:

Thank you! I searched and couldn't find it...

Then the next question, let's say the step is 25, then how to arrange rounding to a number divisible by 25, maybe there is a function?


I made a function, it seems to work

//+------------------------------------------------------------------+
//|Функция округления числа до кратного целого                       |
//+------------------------------------------------------------------+
double Okr(double cifra)
  {
     double TickSize=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
     double Okruglenie=NormalizeDouble(cifra/TickSize,_Digits)*TickSize;
     Print ("До кратного округления=",DoubleToString(cifra,_Digits), " После кратного округления=",DoubleToString(Okruglenie,_Digits));
     return(Okruglenie);
  }