This indicator plots moving average of chosen period and type, automatically colorized from the chosen oscillator state.
5 types of oscillator can colorized the moving average depending on their overbought and oversold situation:
This indicator is based on the great version from ALE: 3D Candlesticks (CCI,RSI,Stochastic,Cycle,DI) and coded following a request made in the technical indicators forum.
//PRC_Colourized MovingAverage | indicator
//19.10.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings
ONCE UseCci =0 // COMMODITY CHANNEL INDEX COLOUR
ONCE UseRsi =0 // RSI COLOUR
ONCE UseStochastic =0 // STOCHASTIC COLOUR
ONCE UseCycle =0 // CYCLE COLOUR
ONCE UseDI =0 // DIRECTIONAL INDEX COLOUR
// ---
ONCE CciPeriod =20
ONCE RsiPeriod =14
ONCE N =14
ONCE K =3
ONCE DiPeriod =14
ONCE MAperiod =20
ONCE MAtype =0 //0=SMA
// --- end of settings
If UseCci then // CANDLE + COMMODITY CHANNEL INDEX COLOUR
MyCci = Cci[max(1,CciPeriod)](customclose)
R = (200-MyCci)
G =(200+MyCci)
Elsif UseRsi then // CANDLE + RSI COLOUR
MyRsi = RSI[max(1,RsiPeriod)](customclose)
R =50+(200-(MyRsi-50)*12)
G =50+(200+(MyRsi-50)*12)
Elsif UseStochastic then // CANDLE + STOCHASTIC COLOUR
MyStoch = Stochastic[max(1,N),max(1,K)](customclose)
R =50+(200-(MyStoch-50)*6)
G =50+(200+(MyStoch-50)*6)
Elsif UseCycle then // CANDLE + CYCLE COLOUR
MyCycle = Cycle(customclose)
R = (200-MyCycle*10)
G =(200+MyCycle*10)
Elsif UseDI then // CANDLE + DIRECTIONAL INDEX
MyDi = DI[max(1,DiPeriod)](customclose)
R = 50+(200-MyDi*10)
G =50+(200+MyDi*10)
endif
avg = average[MAperiod,MAtype](customclose)
Return avg coloured(R,G,0) style(line,3) as "MA coloured by oscillator"