Download MetaTrader 5
To add comments, please log in or register
Any questions regarding MQL5 Cloud Network? FAQ will help you!
Tim Niko Tegtmeyer
331
Tim Niko Tegtmeyer 2016.10.29 22:58 

Hello everyone,

I wrote an indicator that has input variables for the name of multiple symbols. Depending on the name you type, the indicator will draw a line for one symbol or another... My problem is that sometimes, on some symbols the indicator cant get data. I think it has to do with my fxt files, or hst, I am really not sure! The indicator gets the iBarShift for the symbol and works great. It is just that sometimes, or better I say on some symbols, it wont work...

Here some code:

for(i=pos; i<rates_total && !IsStopped(); i++){

for(int e=i; e>(i-inpPeriod); e--){

shift = iBarShift(symbol, 0, time[rates_total-1-e], true);

double tmpCLOSE = iClose(symbol, 0, shift);

}

}

and so on...

I would accept the fact that my code is totally wrong, but because it works on some symbols, I seems to me that thats not the case. I dont need to get data for bar 0. I know that this can sometimes go wrong becuase ticks come in asynchronously. Even when I set the shhift manually to be greater than 0 it wont work.

Has anybody some idea on how to get to the problem?

Thank you ad have a good night.

Mladen Rakic
13542
Mladen Rakic 2016.10.29 23:53  
Tim Niko Tegtmeyer:

Hello everyone,

I wrote an indicator that has input variables for the name of multiple symbols. Depending on the name you type, the indicator will draw a line for one symbol or another... My problem is that sometimes, on some symbols the indicator cant get data. I think it has to do with my fxt files, or hst, I am really not sure! The indicator gets the iBarShift for the symbol and works great. It is just that sometimes, or better I say on some symbols, it wont work...

Here some code:

for(i=pos; i<rates_total && !IsStopped(); i++){

for(int e=i; e>(i-inpPeriod); e--){

shift = iBarShift(symbol, 0, time[rates_total-1-e], true);

double tmpCLOSE = iClose(symbol, 0, shift);

}

}

and so on...

I would accept the fact that my code is totally wrong, but because it works on some symbols, I seems to me that thats not the case. I dont need to get data for bar 0. I know that this can sometimes go wrong becuase ticks come in asynchronously. Even when I set the shhift manually to be greater than 0 it wont work.

Has anybody some idea on how to get to the problem?

Thank you ad have a good night.

Not possible to tell anything from that code snippet

You should post the complete code

Tim Niko Tegtmeyer
331
Tim Niko Tegtmeyer 2016.10.30 09:13  

Hello,

I can post some more code, but the indicator really is a copy of RSI, I only changed some lines. The relevant code where I have the problem is the one I posted:

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[])
{

int    i,pos;
double closePrice = 0;
double shift = 0;
for(i=pos; i<rates_total && !IsStopped(); i++){
for(int e=i; e>(i-inpPeriod); e--){
shift = iBarShift(symbol, 0, time[rates_total-1-e], true);


ExtBuffer_1[i] = NormalizeDouble(closePrice, 1);
return(rates_total);

}


I debugged and I know that iBarShift sometimes returns -1, but I dont know why it works sometimes and sometimes not. I know what -1 means, but why my terminal has no data for some period or some symbols when I can test the symbols and open live charts with all the data there?


Regards

Mladen Rakic
13542
Mladen Rakic 2016.10.30 15:44  
Tim Niko Tegtmeyer:

Hello,

I can post some more code, but the indicator really is a copy of RSI, I only changed some lines. The relevant code where I have the problem is the one I posted:

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[])
{

int    i,pos;
double closePrice = 0;
double shift = 0;
for(i=pos; i<rates_total && !IsStopped(); i++){
for(int e=i; e>(i-inpPeriod); e--){
shift = iBarShift(symbol, 0, time[rates_total-1-e], true);


ExtBuffer_1[i] = NormalizeDouble(closePrice, 1);
return(rates_total);

}


I debugged and I know that iBarShift sometimes returns -1, but I dont know why it works sometimes and sometimes not. I know what -1 means, but why my terminal has no data for some period or some symbols when I can test the symbols and open live charts with all the data there?


Regards

Judging from your usage of iBarShift() and iClose() I am assuming that you are trying to code MT4 code.

In that case use this :

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrRed
#property strict

extern string symbol=""; // Symbol to use

double buffer[];
bool   returnBars;
int OnInit()
{
   SetIndexBuffer(0,buffer);
   returnBars =   (symbol=="returnBars");
   if (symbol=="") symbol=_Symbol;
      IndicatorShortName(" copy for "+symbol);
   return(0);
}
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[])
{
   int counted_bars = prev_calculated;
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1);
           if (returnBars) { buffer[0] = limit; return(rates_total); }
           if (symbol!=_Symbol) limit = (int)MathMax(limit,MathMin(rates_total-1,iCustom(symbol,0,WindowExpertName(),"returnBars",0,0)));

   //
   //
   //
   //
   //

   for(int i = limit; i >= 0; i--) buffer[i] = iClose(symbol,0,iBarShift(symbol,0,time[i]));
   return(rates_total);
}

Replace the iClose() with any call to any indicator and it will work

PS: using a multi symbol is, more or less, the same as using multi time frame : you always have to check the availability of other symbol data. That is why the example is calling itself to check how many bars it must update when the symbol is not the same as the chart symbol

Tim Niko Tegtmeyer
331
Tim Niko Tegtmeyer 2016.10.30 17:08  
Mladen Rakic:

Judging from your usage of iBarShift() and iClose() I am assuming that you are trying to code MT4 code.

In that case use this :

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrRed
#property strict

extern string symbol=""; // Symbol to use

double buffer[];
bool   returnBars;
int OnInit()
{
   SetIndexBuffer(0,buffer);
   returnBars =   (symbol=="returnBars");
   if (symbol=="") symbol=_Symbol;
      IndicatorShortName(" copy for "+symbol);
   return(0);
}
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[])
{
   int counted_bars = prev_calculated;
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1);
           if (returnBars) { buffer[0] = limit; return(rates_total); }
           if (symbol!=_Symbol) limit = (int)MathMax(limit,MathMin(rates_total-1,iCustom(symbol,0,WindowExpertName(),"returnBars",0,0)));

   //
   //
   //
   //
   //

   for(int i = limit; i >= 0; i--) buffer[i] = iClose(symbol,0,iBarShift(symbol,0,time[i]));
   return(rates_total);
}

Replace the iClose() with any call to any indicator and it will work

PS: using a multi symbol is, more or less, the same as using multi time frame : you always have to check the availability of other symbol data. That is why the example is calling itself to check how many bars it must update when the symbol is not the same as the chart symbol


Hey Mladen Rakic, thank you for the answer!

I tried your code but I get the same results.

On current and onemore symbol it works like it is supposed, but on some others not!

It seems that it has nothing to do with the code, because it works sometimes. Also I thought that my code works as long as it gets data. If iClose returns 0, I could just stop drawing the indicator or give it some value.

Before testing, I run backtests on all symbols I will use and I verify that charts have enough data. Also I check that I have the hst fxt files in my folder (also checked history center). So I just dont get why some symbols wont work :(

Can you get iClose on other symbols with your code? If yes, my problem should be somewhere in my terminal.


Thank you and regards

Mladen Rakic
13542
Mladen Rakic 2016.10.30 17:32  
Tim Niko Tegtmeyer:

Hey Mladen Rakic, thank you for the answer!

I tried your code but I get the same results.

On current and onemore symbol it works like it is supposed, but on some others not!

It seems that it has nothing to do with the code, because it works sometimes. Also I thought that my code works as long as it gets data. If iClose returns 0, I could just stop drawing the indicator or give it some value.

Before testing, I run backtests on all symbols I will use and I verify that charts have enough data. Also I check that I have the hst fxt files in my folder (also checked history center). So I just dont get why some symbols wont work :(

Can you get iClose on other symbols with your code? If yes, my problem should be somewhere in my terminal.


Thank you and regards

It works as it is supposed to work for me (as long as I enter a valid symbol name in the symbol parameter) - did not find a single symbol that did not work OK
Tim Niko Tegtmeyer
331
Tim Niko Tegtmeyer 2016.10.31 08:10  
Mladen Rakic:
It works as it is supposed to work for me (as long as I enter a valid symbol name in the symbol parameter) - did not find a single symbol that did not work OK

Thank you, you are right!

My problem was normalizedouble with current digits...

Have a nice day :)

Tim Niko Tegtmeyer
331
Tim Niko Tegtmeyer 2016.10.31 20:27  

Ohh, still the problem that it doesnt work in strategy tester :( Only with current symbol.

Thank you anyway

Mladen Rakic
13542
Mladen Rakic 2016.10.31 21:05  
Tim Niko Tegtmeyer:

Ohh, still the problem that it doesnt work in strategy tester :( Only with current symbol.

Thank you anyway

I am afraid I fail to understand your posts.

What exactly are you looking for? What you are describing is not an issue of the code. The code from that example is working as it is supposed to work. If you are looking to develop something that will be working in multi symbol environment testing I strongly recommend that you shift to mt5 (since mt5 provides multi symbol testing environment too - the thing that mt4 is unaware of - and that has been discussed and clarified in various posts of this forum long time ago - see these example results of the "multi symbol testing" query : https://www.mql5.com/en/search#!keyword=multi%20symbol%20testing or see this thread for a clarification on what you can and what you can not do regarding that in metatrader 4 : https://www.mql5.com/en/forum/116112) But if you do (shift to mt5) expect a different coding challenges from those you might have found in your mt4 usage so far.

/
To add comments, please log in or register