EA printing values that shouldn't be there - page 2

 
Fernando Carreiro #:

If your aim is to get the Indicator to work properly, then post that instead of the EA, and explain what the difficulties you are having with it.

When, coding, build it in layers. Never advance to the next step until the previous one is working flawlessly. Don't even attempt "Alerts" (and before that not even the "Buy/Sell" signals) until the underlaying functionality is working exactly as expected with no flaws.

If you attempt to solve to many things at the same time, your focus gets distracted. You get lost and waste time. Focus on one step at the time and only advance to the next one, when it is correct.

Alright, here is my indicator.

I used what me and you went over and completely rewrote it.

It seems to be changing trends between blue and red more or less where it should be. So, I thought that I was ready to move on to the next step, which was getting it to make the Buy and Sell signals when it turns blue above my MA, and if it turns red below the MA. As mentioned before, they appear in the right locations pretty much, just not unless the chart is refreshed.

There are no errors shown in the compiler or in MT5.

Files:
 
Tristen Shaw #:

Alright, here is my indicator.

I used what me and you went over and completely rewrote it.

It seems to be changing trends between blue and red more or less where it should be. So, I thought that I was ready to move on to the next step, which was getting it to make the Buy and Sell signals when it turns blue above my MA, and if it turns red below the MA. As mentioned before, they appear in the right locations pretty much, just not unless the chart is refreshed.

There are no errors shown in the compiler or in MT5.

  1. Please explain its logic or what you are trying to achieve so that we can comment on your implementation.
  2. At a quick glance, the use of isNewBar is flawed. You are checking outside data instead of the data provided to the OnCalculate and you are using it inside the update loop without regard to the index being handled. This is why it is important to build in layers so your logic does not get lost in nirvana.
  3. I've yet to understand what people find so fascinating with the "Waddah Attar Explosion". I will suggest this to you. Always study what your indicators do. You may find that it overcomplicates thinks, and this is indeed the case for this indicator. It's based on MACD and Bollinger bands, both of which are based on moving averages of the quote prices. And now your indicator is based on that. It is just building on top creating even more complications. It will be highly inefficient and convoluted, making your learning curve of MQL even more difficult and stressful.
Anyway, I will await your explanation of what you are trying to achieve.
 
Fernando Carreiro #:
  1. Please explain its logic or what you are trying to achieve so that we can comment on your implementation.
  2. At a quick glance, the use of isNewBar is flawed. You are checking outside data instead of the data provided to the OnCalculate and you are using it inside the update loop without regard to the index being handled. This is why it is important to build in layers so your logic does not get lost in nirvana.
  3. I've yet to understand what people find so fascinating with the "Waddah Attar Explosion". I will suggest this to you. Always study what your indicators do. You may find that it overcomplicates thinks, and this is indeed the case for this indicator. It's based on MACD and Bollinger bands, both of which are based on moving averages of the quote prices. And now your indicator is based on that. It is just build on top creating even more complications. It will be highly inefficient and convoluted, making your learning curve of MQL even more difficult and stressful.
Anyway, I will await your explanation of what you are trying to achieve.

Ok, my threshold is the last WAE bar of the current trend direction (color) that is above the signal line. When 2 consecutive bars of the opposite direction go above that threshold it changes trend to the other direction.

That is then augmented. I weight the values if the price is above the MA and if the Volty is in a particular direction. So, if it's above the MA and the volty is up, it makes the WAE more likely to turn over to that direction.

A change over on the proper side of the MA is a valid entry. In other words, if it turns blue while above the MA or if it turns red while below. My target is then to go for 1 ATR at my target and to have a smaller one that tries to capture longer trends. I set the SL on the trailing smaller trade to break even after the main trade hits it's target.

So far, it seems like it gave good results in backtest. Granted, that is a small sample size, but thats just because that's all I can fit in a SS.


I am toying with altering the entry just a little, but I'll have to explain that after I get back from my appointment.

 

I am going to reconsider things here and change my stance on helping you out with the current code.

I highly suggest that you put this indicator on hold. You are trying to learn MQL coding by tackling projects that are just too convoluted and advanced for you. Your code clearly shows that you are lost about most of it.  

I am going to highly recommend that you code something that is only slightly above your skill level and make sure you get it right. Only advance to the next level of complexity when you are clearly at ease with all the concepts of making an Indicator properly.

There is no way we can help you if you keep stumbling over things without properly understanding the things that came before it. It does not help you, nor us, as we will end up throwing our hands in the air and shaking our heads.  

Please, I beg of you, start small and make it work perfectly before attempting anything else.

 
Fernando Carreiro #:

I am going to reconsider things here and change my stance on helping you out with the current code.

I highly suggest that you put this indicator on hold. You are trying to learn MQL coding by tackling projects that are just too convoluted and advanced for you. Your code clearly shows that you are lost about most of it.  

I am going to highly recommend that you code something that is only slightly above your skill level and make sure you get it right. Only advance to the next level of complexity when you are clearly at ease with all the concepts of making an Indicator properly.

There is no way we can help you if you keep stumbling over things without properly understanding the things that came before it. It does not help you, nor us, as we will end up throwing our hands in the air and shaking our heads.  

Please, I beg of you, start small and make it work perfectly before attempting anything else.

I have no idea what I should do then.

This is my strategy, it's shown good results for me on my backtest and the reason I started learning MQL5 was specifically to turn it into an EA for myself.

How am I supposed to work up to it? I have no idea how to know what is just slightly above my level. It's not like there is a school for this. All I can do is read tutorials, try to follow along and then post in forums and frustrate other programmers.

I didn't think I was coding way above my level since everything seemed to be working the way I wanted it to. The only problem I was having was getting the signal to show up.

 
Tristen Shaw #:

I have no idea what I should do then.

This is my strategy, it's shown good results for me on my backtest and the reason I started learning MQL5 was specifically to turn it into an EA for myself.

How am I supposed to work up to it? I have no idea how to know what is just slightly above my level. It's not like there is a school for this. All I can do is read tutorials, try to follow along and then post in forums and frustrate other programmers.

I didn't think I was coding way above my level since everything seemed to be working the way I wanted it to. The only problem I was having was getting the signal to show up.

Consider this ... What is your objective?

  • Is it to code your strategy?
  • Is it to learn MQL coding?

Believe it or not, they can be mutually exclusive, meaning that you may not be able to do both at the same time.

If your answer is ... to learn MQL coding?

To learn MQL coding, you should put your strategy on hold, and learn to code a simple indicator and a simple EA. For example, a simple close price crosses MA — buy signal when bar closes above MA, sell signal when bar closes below MA. Build the indicator, then when it is perfect, build an EA for simple net position in the market.

The learning process is about learning to code and implement the simplest of things, not about implementing your strategy.

As you progress, you slowly add more complexity, a little at a time, in the direction of your ultimate goal, being your strategy.

By the time you have reached your strategy, you should have coded multiple indicators and multiple EAs.

If your answer is ... to code your strategy ?

Then hire someone to do it for you.

Obviously,you can continue to learn MQL irrespective of having someone else code your strategy.



 
Fernando Carreiro #:

Consider this ... What is your objective?

  • Is it to code your strategy?
  • Is it to learn MQL coding?

Believe it or not, they can be mutually exclusive, meaning that you may not be able to do both at the same time.

If your answer is ... to learn MQL coding?

To learn MQL coding, you should put your strategy on hold, and learn to code a simple indicator and a simple EA. For example, a simple close price crosses MA — buy signal when bar closes above MA, sell signal when bar closes below MA. Build the indicator, then when it is perfect, build an EA for simple net position in the market.

The learning process is about learning to code and implement the simplest of things, not about implementing your strategy.

As you progress, you slowly add more complexity, a little at a time, in the direction of your ultimate goal, being your strategy.

By the time you have reached your strategy, you should have coded multiple indicators and multiple EAs.

If your answer is ... to code your strategy ?

Then hire someone to do it for you.

Obviously,you can continue to learn MQL irrespective of having someone else code your strategy.



I guess that I would say that my goal is both.

I've always been interested in coding and computer programming. And this past year I found that I also find trading to be very interesting, so it seemed like a good deal that I could combine two things that I'm interested in into one.

To be honest with you, if I had the money I would probably hire someone to code my EA for me while I'm learning. But, the truth of the matter is, I'm juggling bills as it is and just don't have hundreds of dollars to pay someone to make it. That's a big part of why I decided to try and learn it myself.

And to be honest, I had thought that I was making progress and doing okay for a self taught person. .

Sigh. . . I guess I'll have to slow down. It's just hard to get excited about making indicators and EAs that I know I'll never use.

 
Tristen Shaw #: I guess that I would say that my goal is both. I've always been interested in coding and computer programming. And this past year I found that I also find trading to be very interesting, so it seemed like a good deal that I could combine two things that I'm interested in into one. To be honest with you, if I had the money I would probably hire someone to code my EA for me while I'm learning. But, the truth of the matter is, I'm juggling bills as it is and just don't have hundreds of dollars to pay someone to make it. That's a big part of why I decided to try and learn it myself. And to be honest, I had thought that I was making progress and doing okay for a self taught person. Sigh. . . I guess I'll have to slow down. It's just hard to get excited about making indicators and EAs that I know I'll never use.

As I stated, both at the same time may not be possible!

When I started with MQL, I was already an established software developer with 30 years of experience. But even then, I approached it the way I described. Even with my solid background in C and C++, MQL was not just about coding. It also had to do with the MetaTrader platform and trading concepts, and those were totally new to me.

Many of the strategies I had in the beginning eventually got bashed away by the reality that trading can differ totally from what one thinks it is in the beginning. I came up with very elaborate stuff, only for them to be ultimately thrown in the bin because I was naïve.

As I progressed, I realised that my trusted friend in coding, namely K.I.S.S. (Keep it simple, stupid!), is just as relevant in trading as it is in much of anything else in life. Complex strategies are useless and just distract us from what is really important.

As time went by, my strategies became simpler and my EAs become more refined. However, to my surprise, over time, money and risk management became the central theme of it all. It gradually became clear to me that entry rules were not all that important, but exit rules, risk and money management can make or break a strategy and became paramount for me.

In essences, almost any indicator gives approximately the same signals, given that they all derive those signals from the price action itself. So you might as well stick to the simplest and cleanest of indicators and concentrate on the exits, risk and management of the trades.

With that in mind, I decided that my code should be simple, clean and efficient, and focus on the risk and trade management and very little on the indicators and signals they generate.

This is my advice to you. Learn to code MQL and understand the platform and trading, methodically and properly, because as you do, you might find that your current strategy is going to end up in the trash bin.

NB! My journey with trading and MQL took me years (not months), to get to a level I could be happy with.

 
I can only confirm. I've easily written 10 to 12 MB of source code within the last 4 years only for MQL to learn and build working code.

Maybe you start easy with an oscillator like StochRsi and an LWMA on chart indicator.

Find the formulas, write these two indicators and then compare them to what you find in code base.

That's anyways already a good task to start with.

Then write an EA that uses these two indicators. No matter if it's profitable, but make it work stable. Have positions and ordersend working correctly. Test multiple assets with different specs, like digits.

Test it with "random" settings in the tester and resolve all the issues along.

Try multiple demo accounts with different brokers, see how it behaves.

And once you got that going, then copy everything, and begin to build your strategy into it.

Maybe that's a way to go for you.
 
Fernando Carreiro #:

As I progressed, I realised that my trusted friend in coding, namely K.I.S.S. (Keep it simple, stupid!), is just as relevant in trading as it is in much of anything else in life. Complex strategies are useless and just distract us from what is really important.

As time went by, my strategies became simpler and my EAs become more refined. However, to my surprise, over time, money and risk management became the central theme of it all. It gradually became clear to me that entry rules were not all that important, but exit rules, risk and money management can make or break a strategy and became paramount for me.

...

With that in mind, I decided that my code should be simple, clean and efficient, and focus on the risk and trade management and very little on the indicators and signals they generate.


Well said! In the journey of becoming profitable, we all went through the phase of seeking holy grail, get beaten badly, then realize only when we make everything simpler, we can deal with the complex market environment. 

The market is complex, sometimes rational and sometimes irrational, but by stick with simple strategy, simplicity becomes our advantage.


Personally I am a manual trader and I don't know coding. I started my journey back a few years ago and my chart is so complex, full of indicators, trend lines, it is bombarded with information, and of course I occur losses from my trades.

Now my chart is as clean as only 2 moving averages, which I use this same thing on forex (mt5), futures, stocks (on other trading platforms). Only by making things simple then I make money. 

Risk and trade management can make most if not all strategy we come cross in CodeBase shine. I see a lot of people complaining on this forum about CodeBase strategies don't bring them profit. The truth is strategy is just a tool, it is the skillful/unskilled person who use the tool make the difference. Simplicity, risk managment is two of the many essentials skill to have in order to make money.

Ever think the magic of the famous turtle trading strategy, the magic behind entry rule: price break out 20 days high/low? I think many traders have studied turtle trading strategy, wondering what makes the entry rule special. There is nothing special about the entry rule! It is just a simple excuse to enter the position, and this excuse can be any other simple things. The real magic behind is the risk managment/chase profit which the entire turtle strategy is centered about.


I only browse forum and never post, but I do so this time because I find rare to see someone speak the true wisdom of trading, as Fernando Carreiro describes above. 

Reason: