Could someone help me with my EA

 

Hello mql4 community, here is my first EA and i have a few problem with it althought it is very simple. the idea is to open a position when high or low of the previous hour is broken.

Can someone have a look on it and tell me why when backtesting it does not open a trade.

thank in advance

 
logan113 wrote >>

Hello mql4 community, here is my first EA and i have a few problem with it althought it is very simple. the idea is to open a position when high or low of the previous hour is broken.

Can someone have a look on it and tell me why when backtesting it does not open a trade.

thank in advance

Hi Logan113, I recommend that you study CodersGuru EA to start with. I would foward it to you but I only have the PDF file format and this site will not accept the PDF format. Look for it here https://www.forex-tsd.com/

 
tigger wrote >>

Hi Logan113, I recommend that you study CodersGuru EA to start with. I would foward it to you but I only have the PDF file format and this site will not accept the PDF format. Look for it here https://www.forex-tsd.com/

ok i'll have a look right now. thank you very much.

Anyone else please??

 
logan113 wrote >>

ok i'll have a look right now. thank you very much.

Anyone else please?

anyone to have a look on this please
 

I can see what is happening.

If you look at the journal output you'll probably see that you are getting error 130 (invalid stops).

The reason is that you have coded the stops in the OrderSend() to be relative values.

These need to be absolute prices so you need to factor the entry price into the calculation.

In other words rather than telling OrderSend() to open a trade with a stop of 50 pips, you need to first calculate what that exit price will be.


It would help if you built into your code some error processing (reporting and handling), not least so we don't have to resort to guesswork to solve your problems.


CB

 
cloudbreaker wrote >>

I can see what is happening.

If you look at the journal output you'll probably see that you are getting error 130 (invalid stops).

The reason is that you have coded the stops in the OrderSend() to be relative values.

These need to be absolute prices so you need to factor the entry price into the calculation.

In other words rather than telling OrderSend() to open a trade with a stop of 50 pips, you need to first calculate what that exit price will be.

It would help if you built into your code some error processing (reporting and handling), not least so we don't have to resort to guesswork to solve your problems.

CB

A great thank to you cloudbreaker, it's not so easy to catch tese kind of mitakes when your a "noob" :) .Do You mean to put getlasterror() for example after each important function?

cloudbreaker wrote >>

It would help if you built into your code some error processing (reporting and handling), not least so we don't have to resort to guesswork to solve your problems.

CB

Do You mean to put getlasterror() after each important function? for example after this ordersend()?

thank you again :)

 

Yep, you can use Print() or SendMail() for example to deliver the response from GetLastError(). And you can also programmatically handle the error as well as just reporting it.

Just remember that after you access the GetLastError() function once, it zeroes itself.


CB

Reason: