My EA not taking trades - page 2

 
Daniel Matthew #: I appreciate the responses because of course you don't have to. But you say i'm ignoring steps. I've not ignored any step. If a change is not made to your standard then it's because I didn't understand what you were refering to. And regarding 1.1 1.2 1.7 I still don't know what that is. I feel I have to guess what you're referring to rather than gaining knowledge for me to move forward and fix this code. It seems like a riddle instead of being told what part of my code is wrong and what changes should be made. Can the instructions be clearer please.

Point 1.1:

When attaching source code file, attach the actual file like "file.mq4" or "file.mq5". Don't attach a text file like "file.txt".

Point 1.2:

Be clear about which language you are using and what platform. Are you coding in MQL4 for MetaTrader 4 or are you coding in MQL5 for MetaTrader 5?

The fact that you attached the code as a text file "file.txt" and not "file.mq4" or "file.mq5" , makes us have to try guess from the code functionality, but that is not always clear.

This website and forum is dedicated to MQL5 and MetaTrader 5, because the old MetaTrader 4 is no longer being actively developed (getting near to a decade). So, on this forum, all questions related to MQL4/MetaTrader 4 should be place in the only available section for it.

Point 1.7:

A crossover cannot just be detected by comparing the current fast and slow values. That just tells you which one is above or below, but it does not tell you if a crossover occurred. To do that you have to consider how they were in the previous bar compared to the current bar (and even that sometimes fails, requiring you to keep track of even earlier data, or keeping a running state of the trend or slope).

If you believe the answers are somehow "riddles", then that is exactly the point. They are to serve as hints, advice and guidance but not as final solutions spoon-fed to you.

A programmer is a "problem solver". When faced when a problem, they have to investigate and do research, and then apply thought and logic to come up with a solution.

If we simply give you the final code solution, you learn nothing.You simply see a solution, but don't learn how to do it yourself so that you can apply it in the future. You don't "grow".

You learn, by taking a "hint", so that it guides you while you research and investigate, so that you can develop your skills in logic.

If you don't like that approach, then you are not interested in learning, and you might as well just hire someone to code it for you and be done with it.

 

Thank you,


Such an explanation I can understand. It is not I wish to be spoon fed, but I need to be able to understand what you're talking about to impliment change.

I did not know it was best to send the source file I will do in future.

I am coding for MT4

As for the crossover I did only need it to detect the trend to filter out which direction to look for trades. That is why I used only part of the suggested code. Is what I done not correct for this?

With all that being said I am not sure what other changes I can do and I still have the same errors and cannot take trades.

Files:
CandleBlast.mq4  26 kb
 
Daniel Matthew #: As for the crossover I did only need it to detect the trend to filter out which direction to look for trades. That is why I used only part of the suggested code. Is what I done not correct for this?
PICNIC. You said you are looking for a cross. Your code just detects direction. Make up your mind what you want and code it.
 
I want it to detect direction
 
Daniel Matthew #: That is why I used only part of the suggested code. Is what I done not correct for this?

Well, let's just say that your code is somewhat "messy" and "stringy". It's logic is convoluted, and should any specific part be slightly changed, the rest will come tumbling down like a house of cards.

A program should be coded so that individual sections are well defined and not too dependant on overall logic, otherwise a slight change somewhere else will have a negative effect overall.

That is why it is best to properly detect a crossover (and not just if it is up or down), and not depend on some other part of the code keeping track if there are open orders or not.

 

By the way, it is better to detect changes or crossovers based on previous bars and not the current one.

The current bar is still in "flux" and the current closing price has not settled yet, meaning that whether it will close up or down is still unknown, while the previous bar is closed and will not change any more.

You should also only be checking once per bar and not on every tick.

Code Base

Detecting the start of a new bar or candle

Fernando Carreiro, 2022.04.24 00:46

Detecting the start of a new bar or candle, in the OnTick() event handler of an expert advisor.
 

Forgot to mention, that the most recent code you attached, namely CandleBlast.mq4, does not compile. You call a function IsNewTick which has not been declared.