iClose returning wrong value - page 3

 

Hi, I have the exact same issue as Douglas with iTime; for example "iTime(XPDUSD,5) Failed: 0".

I am trying using the strategy tester on a 1H tf and call a custom indicator to return a value based on the 5 min tf of the same XPDUSD chart the tester is running on.

The indicator then returns an empty value and this is in the line after I try to download history with the result of "iTime(XPDUSD,5) Failed: 0" but sometimes iTime does not fail, irregularly,  and the indicator now has history to then actually return a value.

I have tried both the code suggested by Petr Nosek & whroeder1 but with the same result unfortunately.

Could I be missing something obvious or is this a common problem when running strategy tester with icustom calls on separate time-frames ?

Having a hard time finding better threads about the topic other then this where you all have provided great info.

 

Hi,


I'm facing a similar problem so I thought I'd post it here. I'm trying to get the previous value for the current symbol and timeframe for an EA. The EA is executing an indicator I have created. While the indicator is working perfect the EA is 100% wrong.

The EA always returns the current price for Close[i] and Close[i+1], or iClose(_Symbol, 0, i) and iClose(_Symbol, 0, i + 1)


Top window is from the Indicator (you can see the Close[1] is the price of the next row

and bottom window is from the EA where the prices are the same:

bb



Here's the code:

   string priceFormat=StringFormat("%%.%df",SymbolInfoInteger(_Symbol,SYMBOL_DIGITS));
   printf("Close[0]="+priceFormat+" Close[1]="+priceFormat,
      Close[i],
      Close[i + 1]
      );
 

antaransi:

...While the indicator is working perfect the EA is 100% wrong.

The EA always returns the current price for Close[i] and Close[i+1], or iClose(_Symbol, 0, i) and iClose(_Symbol, 0, i + 1)

My guess is that i is pointing to some place in the past, probably night hours. Why do you even use i when you are just concerend with Close[0] and Close[1]? Try i=0; or remove it entirely from your printf statement, then check again.

 
lippmaje:

My guess is that i is pointing to some place in the past, probably night hours. Why do you even use i when you are just concerend with Close[0] and Close[1]? Try i=0; or remove it entirely from your printf statement, then check again.

Thank you for your reply,


I've tried that as well. Does not work. The dates are valid - you can see them on the left and this goes on for any date! Close[0] is always the same value as Close[1].

I don't have much experience with MQL, so I was wondering if this is the way that EAs are supposed to work.

 
Close[0] is always equal to the latest Bid. I guess your printf is executed exactly on open of a new bar, as the time stamps indicate. In this case, you are logging the close of the last bar plus the actual bid. Both are just a tick apart. Try Close[2] and Close[1].
 
lippmaje:
Close[0] is always equal to the latest Bid. I guess your printf is executed exactly on open of a new bar, as the time stamps indicate. In this case, you are logging the close of the last bar plus the actual bid. Both are just a tick apart. Try Close[2] and Close[1].

I appreciate the response. I did just that and now everything seems to work just fine. Every platform something new to learn.


Thanks again for your response.

 

Hi there, so sorry if i recall this post but I'm facing a similar situation to some extent: no code to post now, my idea is to sum momentum of different but correlated pairs, 1h TF, calculating Mom. with iClose(i) - iClose(i+1) of each pair; the result is then to be put on an array.

Tried to code without normalization(I'm new on MQL4, forgive me..) and obviously many operations returned error; I believe the concept is to normalize in order to sum “apples” with “apples” isn’t it? 

Any help and examples of code will be much appreciated, thank you very much.👍🏼

 

I know its an old thread, but might be helpful.

I made the following little trick to solve the problem:

double x=iClose(Symbol(),PERIOD_H1,1);
Sleep(1);
x=iClose(Symbol(),PERIOD_H1,1);

When the function is first called, the values are refreshed. At the second call it seems to gives correct value all the time.