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

 

Hello I am getting the data on the closing of the hour candlesticks, I draw it, all is normal, I want to get the data for the N-th period ago, writes array out of range

I tried to use the indicator buffer from the array, please advise how to get the data for the previous period

{
 


if(prev_calculated<1) limit=rates_total-1;
if(prev_calculated>0)limit=rates_total-prev_calculated;
for(i=limit; i>=0; i--)
{  
int yesterday_weekday = TimeHour(iTime(Symbol(),0,i+1))-TimeHour(iTime(Symbol(),0,i));
if(yesterday_weekday!=0)  
  {
P=C; 
T = iTime(NULL,0,i+1); 
shift=iBarShift(NULL,PeriodGR,T); 
C= iClose(NULL,PeriodGR,shift);   
CB[n]=C;n++; 

 }
 CC[i]=C; 
 Comment(StringFormat("CC[i]=%G\r\nCB[n-2]=%G\r\n",CC[i],CB[n-2])); 
  }
   return(rates_total);
  }
 
PokrovMT5:

Good afternoon! I get data on the closing of hourly candlesticks, I draw it, everything is OK, I want to get the data for the N-th period ago, writes an empty array, I tried to use the indicator buffer from the array, advise how to get data for the previous period

Maybe this will help

https://www.mql5.com/ru/code/7297

https://www.mql5.com/ru/code/20343

TZ-Breaktout
TZ-Breaktout
  • votes: 2
  • 2007.09.14
  • Scriptor
  • www.mql5.com
Индикатор TZ-Breaktout.
 
PokrovMT5:

Hello I am getting the data on the closing of the hour candlesticks, I draw it, all is normal, I want to get the data for the N-th period back, writes array out of range

I tried to use the indicator buffer from the array, please advise how to get the data for the previous period

limit=rates_total-1;

Your limit points to the very first bar in the history. But you want i+1 - that's why i is out of range.

Try

limit=rates_total-2;

... although it's unlikely to help - there are probably many more calculation values that you don't check...

 
Hello. I have a question, the indicator variable limit in mql4 shows 3555 bars for gold by day, while mql5 shows half of it? Where to place quotes? Another question please, forlimit=rates_total-2; that was discussed above, in my variant there is no array overflow only whenlimit=rates_total-5; the program works. I also noticed that in mql5 the code compilation is slowing down significantly, the process takes about 13 seconds, is this normal? Thank you.

 
mwwm:
Hello. My question, may be the indicator variable limit in mql4 shows 3555 bars daily for gold and mql5 shows twice less? Where to place quotes? Another question please, forlimit=rates_total-2; that was discussed above, in my variant there is no array overflow only whenlimit=rates_total-5; the program works. Also I've noticed that in mql5 the code compilation is slowing down significantly, the process takes 13 seconds, is it normal? Thank you.

In MT5, quotes are downloaded from the server: what's there is there...

About limit you don't have to guess and tweak, and you have to accurately calculate - from which variables the offset depends, and take one unit from rates_total and the values of these variables (if they are not calculated). If the variables are calculated, you should control the value of the loop index and, if it is greater than rates_total-1, skip this iteration (continue)

 

Hello, can someone tell me if anyone knows, I load tick data to test with 99% as it should be, everything works fine for 30 min chart, but as soon as I load H4 data and try to run an EA on it in the tester, - does not work, the tester gives out 2018.04.05 16:41:08.576 TestGenerator: file "C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\7E781795884A398A87F33ED1B942D689\tester\history\USDJPY240_0.fxt" cannot open [5]

And 2018.04.05 16:41:08.535 TestGenerator: file "C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\7E781795884A398A87F33ED1B942D689\tester\history\USDJPY240_0.fxt" is read-only

what could be the reason??????
 
pryn:

Hello, can someone tell me if anyone knows, I load tick data to test with 99% as it should be, everything works fine for 30 min chart, but as soon as I load H4 data and try to run an EA on it in the tester, - does not work, the tester gives out 2018.04.05 16:41:08.576 TestGenerator: file "C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\7E781795884A398A87F33ED1B942D689\tester\history\USDJPY240_0.fxt" cannot open [5]

And 2018.04.05 16:41:08.535 TestGenerator: file "C:\Users\user\AppData\Roaming\MetaQuotes\Terminal\7E781795884A398A87F33ED1B942D689\tester\history\USDJPY240_0.fxt" is read-only

what could be the reason??????
No need to multiply your questions please.
 
Artyom Trishkin ...Ifthe current time is longer, then save it in a variable for checking...

Thank you, found what I was looking for.

Another question - I close a position partially, how do I take this closed profit or loss into account when calculating the current profit.

 
PolarSeaman:

Thank you, I found what I was looking for.

Another question - I close a position partially, how do I take this closed profit or loss into account when calculating the current profit.

Exactly the same way as for calculation of the complete closing. The position is divided: the closed part goes to history and the remaining part gets a new ticket and remains in the market.

 
Artyom Trishkin:

a closed part goes into the history.

How do I know that in the history of this particular position a part is closed?

I opened a position with 1.0 lot, closed it with 0.5, and with 10$ loss. Later I closed another 0.25 with 5$ profit. I will close it all at 50$ profit. In fact, right now I have $50 profit.

if (OrderProfit()+OrderSwap()>=50) ClosePosBySelect();

How do I close -$10 and +$5 in the calculation of the current profit? To close at $55 profit

Reason: