BardParticipant
Master
Hi,
I was interested in developing a Renko moving average indicator based on Nicolas’s code here: https://www.prorealcode.com/topic/discussion-re-pure-renko-strategy/page/5/#post-122154
but with the idea of having different moving average types like the Moving Average Filter Regression: https://www.prorealcode.com/prorealtime-indicators/average-filter-regression/
It’s just that the AVG line seems a bit jerky and not smooth? Pls see image and yellow average.
Also how can you add “priceMAperiod” (because it’s part of a “once” statement) to the variables so you can adjust the moving average without having to go into the code and change it from 10 to 100 for example?
Cheers!
//Renko Moving Average Filter Regression
///BoxSize = 100
//Average[N,M](price)
//Where M can be set with any of these values, to return the specific moving average calculation:
//0 = SMA
//1 = EMA
//2 = WMA
//3 = Wilder
// --- parameters
// MAType = 0
Series = CustomClose
// priceMAperiod = 10
// ---
//-----------------------------//
// SMA - Simple Moving Average //
//-----------------------------//
IF MAType = 0 THEN
priceMAperiod = MAX(priceMAperiod, 1)
AVG = Average[priceMAperiod](Series)
ENDIF
//----------------------------------//
// EMA - Exponential Moving Average //
//----------------------------------//
IF MAType = 1 THEN
priceMAperiod = MAX(priceMAperiod, 1)
AVG = ExponentialAverage[priceMAperiod](Series)
ENDIF
//-------------------------------//
// WMA - Weighted Moving Average //
//-------------------------------//
IF MAType = 2 THEN
priceMAperiod = MAX(priceMAperiod, 1)
AVG = WeightedAverage[priceMAperiod](Series)
ENDIF
//------------------------------//
// WIMA - Wilder Moving Average //
//------------------------------//
IF MAType = 3 THEN
priceMAperiod = MAX(priceMAperiod, 1)
AVG = WilderAverage[priceMAperiod](Series)
ENDIF
//Boxsize = 100
renkoMax = ROUND(close / boxSize) * boxSize
renkoMin = renkoMax - boxSize
once usema=1
if usema then
once priceMAperiod=10
count=0
sum=0
lastbox=0
for i = 0 to barindex do
if renkomax[i]<>lastbox then
lastbox=renkomax[i]
count=count+1
median=((renkomax[i]+renkomin[i])/2)
sum=sum+median
if count=priceMAperiod+1 then
sum=sum-last
last=median
break
//
endif
endif
next
once avg=undefined
if last<>last[1] then
avg = sum/priceMAperiod
endif
endif
RETURN AVG coloured(255,255,0) style(line, 2) as "Renko Mvg Ave Filter"
Ouch! Not that easy!! Renko are not time dependent, so you can’t use a classic period (which is based on normal candlestick) and use it on the custom renko bricks i created in this code…
I did a simple MA, which is nothing less than an arithmetic average, sum all the price (which here are the renko Close) and divide the sum by the period, easy.
But if you want to make the same with other types of MA, which have very different kind of calculation, that would involve a very difficult coding. Without array, in v10.3, you should give up now.
And in v11, even with array, you don’t have to code it, because it is now possible to apply any custom indicator on renko charts.
BardParticipant
Master
Thanks, glad I didn’t copy and paste and then edit all the different moving average types in anticipation of your “code fix” for the above indicator! Is v11 out yet?
BelParticipant
New
Shame we can’t put indicators on IG 10.3 versions even though 11 is out already but they seem to do nothing to implement it. I’m interested in the same as Brads as well. Seems other platforms had these options for ages.
Regards,
Bel.