arrows and wrong object being added to chart.

 

I have a delemna with coding my mt5/mql5 indicator. It is simple crossover indicator, however the coding is causing me frustration. the 2 main features of the indicator i want are...


1) at crossover of 2 mas, an arrow appears. The arrow direction will show in direction of the faster/smaller period ma,
2) a text label will appear in the top right corner of the chart, saying the direction of the faster ma. If the faster ma is above the slower ma, text will say Up trend, and visa versa.

But see in my image below, it often says the wrong msg, and sometimes does not show an arrow. I have read many documents and threads on this site, forum and online book, tried several changes but all have same result. Please post a link where i can find the cause, and what i am doing wrong, or different to how it should be done. I am experienced coding in mt4/mql4, but not much done in mt5/mql5, but am willing to continue to be stubborn and persevere, but i need some help from the coding gods.

NOTE in the image the msg in purple is the mistake. It should be msg "Long Up Trend" because the brown line (The fast ma) is above the slowest ma line (grey, longer trend, bigger ma period).

should say Long Up Trend

Since the code is 1000 lines, i have attached the file, instead of the usual insertion into this text post.

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
  • www.mql5.com
Object Properties - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
IND5.rMAx22.mq5  97 kb
 

Your code contains errors - it cannot be compiled.

My advice: create a very small example - that way We can compile the example, and you will find your mistake in a small example sooner.

 
Alert Crossing Two MA
Alert Crossing Two MA
  • www.mql5.com
Alert при пересечении двух iMA: 'Fast' и 'Slow'
 

just comment those 2 lines out. am going to check your reading link now, thanks.

 
Vladimir Karputov #:

Your code contains errors - it cannot be compiled.

My advice: create a very small example - that way We can compile the example, and you will find your mistake in a small example sooner.

yeah, that is what i did. half the remainder code is just for the text labels.

EDIT: but i guess i could have removed all that text label code and you still would have seen what i intended in the image.

Vladimir Karputov #:
Example: Alert Crossing Two MA


woohoo! thanks a whole bunch! and you put oodles of explanations and comments too! like i said... woohoo!

 
Vladimir Karputov #:
Example: Alert Crossing Two MA

As great as this is, and i think that it is faster than my original, however, i found that i have the same issue, but now i believe i understand what is happening...

When a sudden spike in price causes the fastest ma to cross the other lines it triggers the change of alert and text label, but often the price will make reverse onto the same side of the slower lines, where it was at end of the closed candle, making the chart look like the fast line did not crossover the other lines. This leaves the wrong text msg on the chart. So i have now added conditions to my indicator to allow for this scenario.

But! I have used yours with added lines and arrows and text labels, with just 1 issue i found, and i am stumped... It will not draw my arrows on the past candles. Can you make suggestion or another link to show what i need to add to your code to enable my arrows? i have the arrow buffers and the lines in the properties with number of buffers and plots, but there must be something else i am missing to make it show the arrows on the historical candles.

Files:
 
You need to analyze on bar #1, and not on bar #0 - thus there will be no situations "the indicator went up sharply during one bar, and then returned down".
 
Vladimir Karputov #:
You need to analyze on bar #1, and not on bar #0 - thus there will be no situations "the indicator went up sharply during one bar, and then returned down".

fixed. done. and proven working on my original. thanks.

But i want to use yours as a template, now that i have used it, even with the lines and text labels, it seems to be more brisk on the charts. So, if i can get those arrows to work on yours, with the closed candles upon initialising, i would be set. See my code in the previous comment. I can not get the arrows to draw on the closed candles when i first attach it to the chart.

 
Revo Trades # :

fixed. done. and proven working on my original. thanks.

But i want to use yours as a template, now that i have used it, even with the lines and text labels, it seems to be more brisk on the charts. So, if i can get those arrows to work on yours, with the closed candles upon initialising, i would be set. See my code in the previous comment. I can not get the arrows to draw on the closed candles when i first attach it to the chart.

Where is the MQL5 code? No code - no help. If you want help - attach your code to the message. Also MANDATORY show an example - explain WHAT EXACTLY you do not succeed. Show on what symbol and on what timeframe and on what date (time) the problem appears.

 
Vladimir Karputov #:

Where is the MQL5 code? No code - no help. If you want help - attach your code to the message. Also MANDATORY show an example - explain WHAT EXACTLY you do not succeed. Show on what symbol and on what timeframe and on what date (time) the problem appears.

i attached the code in comment #5 and described in detail my issue: the arrows will not draw on historical candles, when i first attach it to a chart. I made a few attempts to change your code to analyse before candle 0, but alas, no success. If you can fix it. i will buy 1 of your $30 indicators for 3 consecutive months. thanks.

any image i put up would look exactly like the original image, with exception that the text labels would be corrected. My arrows are drawing on candles on the current candle and they stay on the charts, they just do not draw on closed candles before the time that I attach the indicator to the chart.

I have also modified my mql5 website settings so that you can send me texts direct if you so wish to do so.
 
Revo Trades # :

i attached the code in comment #5 and described in detail my issue: the arrows will not draw on historical candles, when i first attach it to a chart. I made a few attempts to change your code to analyse before candle 0, but alas, no success. If you can fix it. i will buy 1 of your $30 indicators for 3 consecutive months. thanks.

any image i put up would look exactly like the original image, with exception that the text labels would be corrected. My arrows are drawing on candles on the current candle and they stay on the charts, they just do not draw on closed candles before the time that I attach the indicator to the chart.

I have also modified my mql5 website settings so that you can send me texts direct if you so wish to do so.

What code did you take as the original? (link please)

Reason: