I am just starting to learn to write code for MT4 so I tried to do a simple indicator to put buy and sell signals above and below the bars when an MA cross occurs in each direction.
It sort of works, but here's the problem.
I of course only wanted a buy/sell arrow to show on the first bar of the new cross over direction rather than having a string of buy arrows "as long as the fast MA is above the slow MA" etc, so in the code I tried to calculate the indicator buffer values while taking into account the value of the previous bar's MA cross over status - so if the current bar has a buy in effect with the fast MA above the slow MA, then if the previous bar also had this same condition, don't redraw a buy signal, it was already drawn in the past.
When I load the indicator, I get the string of buy and sell arrows on every bar instead of just the first bar....yet if I go into the language editor and compile the code, suddenly the chart will refresh and the proper arrow pattern shows up, just one for each new buy or sell.
If I then switch time frames or something, it reverts back to the string of arrows instead of proper signals.
This must be something simple that I don't know about and is easy to fix...any ideas?
It sort of works, but here's the problem.
I of course only wanted a buy/sell arrow to show on the first bar of the new cross over direction rather than having a string of buy arrows "as long as the fast MA is above the slow MA" etc, so in the code I tried to calculate the indicator buffer values while taking into account the value of the previous bar's MA cross over status - so if the current bar has a buy in effect with the fast MA above the slow MA, then if the previous bar also had this same condition, don't redraw a buy signal, it was already drawn in the past.
When I load the indicator, I get the string of buy and sell arrows on every bar instead of just the first bar....yet if I go into the language editor and compile the code, suddenly the chart will refresh and the proper arrow pattern shows up, just one for each new buy or sell.
If I then switch time frames or something, it reverts back to the string of arrows instead of proper signals.
This must be something simple that I don't know about and is easy to fix...any ideas?
Attached File(s)
Test.mq4
2 KB
|
186 downloads
"Support and Resistance either holds or it doesn't."
-Anonymous hillbilly