Hello, I am still looking for a solution to the below if anyone can help? The indicator is a colour change moving average so if the ma is higher than it was on the last candle then it will change colour to lime and down to red. I would like to introduce a "lookback" period to this so that it looks back 30 candles to decide whether it is higher or lower. This smooths out a lot of the brief colour changes. I think I can see the part of the code where it compares the last two candles but nothing I do to it will work, the ma's just disappear off the chart. I'm guessing that when I add the 30 lookback it is trying to look for data at the extreme left that doesn't exist. If that's the case then I need to start the indicator reference from something like rates_total - 30 but I'm struggling with it to be honest. Any help would be gratefully appreciated.
- Help with changing an indicator
- Need some help.
- Indicators: Volumes
//+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- const int toCopy=(rates_total==prev_calculated)?1:rates_total-prev_calculated; if(CopyBuffer(handle,0,0,toCopy,MABuffer)!=toCopy) return(0); //--- const int limit=(rates_total==prev_calculated)?prev_calculated-1:(!prev_calculated)?Period+Lookback:prev_calculated; for(int i=limit;i<rates_total;i++) MAColors[i]=(MABuffer[i]>MABuffer[i-Lookback])?0:(MABuffer[i]<MABuffer[i-Lookback])?1:2; //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Files:
MA_Color.mq5
3 kb
Ernst Van Der Merwe:
@Ernst Van Der Merwe That's absolutely perfect! Thank you very much.
Forum on trading, automated trading systems and testing trading strategies
Showing color iMA using iCustom, is this the solution?
Vladimir Karputov, 2020.08.17 15:28
Indicator idea
The iMA (Moving Average, MA) indicator on the ' MA: trend N Bars ' segment will define the trend. DRAW_COLOR_LINE paints the indicator in three colors using the graphical plotting style. The first color - the trend is not defined, the second - the uptrend and the third - the downward trend.
Figure: 1. MA Color N Bars
The indicator allows you to more visually highlight trend areas.
Vladimir Karputov:
Thank you, I've seen that one but I didn't like it as much.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register