Download MetaTrader 5

Future highs in backtesting

To add comments, please log in or register
Louis Stoltz
636
Louis Stoltz  

Hi

Im trying to code something for strategy tester but want to get future bars highest

Past bars highest is High[iHighest(NULL,0,MODE_HIGH,40,0)];

But future Im not sure how to get it High[iHighest(NULL,0,MODE_HIGH,40,-40)]; That doesnt work.

Anybody know anything?

Fernando Carreiro
3951
Fernando Carreiro  

Hello "bonechair",

You cannot access the "future" bars as that would be "impossible" in real live trading (unless you have a magic crystal ball).

So in the spirit of things, the code running in the strategy tester cannot access future data even though it technically exists since you are running a back test.

If the code did exist and you did use it, it would serve no purpose as the EA would not be able to run in real-time where no "future" data is available.

If however, you are trying write an EA for statistical analysis of data and outputting processed data and not actually place orders, then just let it advance a few bars and shift back the index point for the reference of the "now" and the "future" values. I hope you understand what I mean. for example, consider High[1] to be the "future" and High[2] to be the "now" and High[3] to be the "past" or something similar in that line of thought.

But, please remember, if it is for an EA that places orders and not statistical analysis, then there is no such thing as "future" bars.

Louis Stoltz
636
Louis Stoltz  

No Im talking strategy tester on history not live trading, I have a different way that works but its too complicated to get the future bars in history.

Im looking for something more simpler with Ihighest

Fernando Carreiro
3951
Fernando Carreiro  
bonechair:

No Im talking strategy tester on history not live trading, I have a different way that works but its too complicated to get the future bars in history.

Im looking for something more simpler with Ihighest



I was also talking about the strategy tester. Remember that it was conceived as way of testing EA's as if they were live trading.

So, with that in mind, it would not make sense for it to get "future" data. To make it more clear - There is no "future" data!!!

Maybe you can describe in more detail or post a snippet of the code, so that we can better understand what it is you are trying to achieve.

Also, if you really need to access all the data, just read a "History File" (.hst) directly and process the data yourself in your own code.

Louis Stoltz
636
Louis Stoltz  

Thanks for replying.

There is this codebase https://www.mql5.com/en/code/9395 for drawing future bars in your tester.

The coding is a bit overkill and wondering if there a two line solution for Ihighest function?

Simon Gniadkowski
Moderator
18056
Simon Gniadkowski  
bonechair:

Thanks for replying.

There is this codebase https://www.mql5.com/en/code/9395 for drawing future bars in your tester.

The coding is a bit overkill and wondering if there a two line solution for Ihighest function?

Overkill ? I must be looking at the wrong code . . . the start() function is less than 50 lines . . .
Fernando Carreiro
3951
Fernando Carreiro  

Sorry, but that is not "future" bars. Your example on the code is exactly what I tried to explain, about how to "shift back the index point". That is why in the code, you referenced, the Author uses the iBarShift() function to get at the data .

In fact, the Author does exactly what you need by using the index shift (see the snippet of his code):

H=iHigh(NULL, pTF,iHighest( NULL ,pTF, MODE_HIGH, K, iB) )


However, as explained, it would only be a theoretical exercise, because once you started using the EA in a live way, that part of the code would not work. The Author himself, says it and I quote:

« It works only in a tester, in a mode of visualisation and on timeframe not less 5M. »


But, hey, if it works for you, who am I to say otherwise.

Good luck on your endeavour!

Ubzen
5390
Ubzen  
RaptorUK: Overkill ? I must be looking at the wrong code . . . the start() function is less than 50 lines . . .
Yep. . .Same reaction I had when I saw the codes .
Fernando Carreiro
3951
Fernando Carreiro  
PS! Just a quick note, you could always just use the "BackToFuture" indicator directly by use iCustom() to get at that Indicators data!!!!
Louis Stoltz
636
Louis Stoltz  

Ye I know that code is awesome but overkill for what I want to do is just get the highest and lowest for 40 bars and then draw lines for something I want to test out.

Ive just put together without the for loop. I was wondering about that Ibarshift and those calculations there made me confused

per = Time[0];

int pTF=PrevPer(Period());
int iB=iBarShift(NULL,pTF, per);
if(iB==0) return;

int K=MathRound(Period()/pTF);

iB=iB-K+1;

The Period division with PrevPer I dont understand that part. I thought you could just use -40 in Ihighest. It seems a long way to find that answer.

Simon Gniadkowski
Moderator
18056
Simon Gniadkowski  
bonechair:

It seems a long way to find that answer.

There are many, many very short ways to get the wrong answer, if you want the correct answer sometimes it takes a few more lines of code.
123
To add comments, please log in or register