This indicator displays the distribution of values returned by the RSI, Stochastic, Williams%R and ADX indicators.
This indicator only works on v11 onwards.
Select which indicator you want to analyse with the ‘RSIndex’, ‘Stoch’, ‘WilliamsR’ and ‘ADX’ settings. The default is RSI if nothing is selected. If two are selected then it defaults to the last one selected.
‘P’ is the period setting for the index. ‘K’ is the K% setting for the stochastic index. ‘D’ is the average period used in the signal line. The signal line is just a simple moving average of the index value and is not used in the distribution calculations. You can turn this signal line display on or off with the ‘SignalLine’ setting.
You can select a start date to analyse from or set ‘StartDate’ to zero to analyse all of the data.
The distribution chart shows you where the index spends most of its time and where it spends the least amount of time. The chart has a maximum score of 100% which represents the highest scoring distribution value. The displayed value and dot show you where the index currently is on the distribution curve and how it scores compared to the maximum score.
Note: The Williams%R returned values have been changed from -100 to zero and are shown as zero to 100 for ease of calculations in the code.
As always I advise downloading and importing the ITF file to get full functionality.
//Distribution of Index
//PRT v11 onwards
//By Vonasi
//Date: 20200509
//p = 14 // Period used in indicator
//k = 3 // K% setting for stochastic
//d = 9 // Period used for signal line
//RSIndex = 1 // Select RSI
//Stoch = 0 // Select Stochastic
//WilliamsR = 0 // Select Williams%R
//ADXindex = 0 // Select ADX
//SignalLine = 1 // Turn on/off display of signal line
//StartDate = 19950101 // Date to start analysis from. Zero = all data
p = max(1,p)
k = max(1,k)
d = max(1,d)
if date >= startdate then
once signal = undefined
if RSIndex or (not Stoch and not WilliamsR and not ADXindex) then
indicator = rsi[p]
endif
if Stoch then
indicator = stochastic[p,k]
endif
if WilliamsR then
indicator = williams[p]+100
endif
if ADXindex then
indicator = ADX[p]
endif
if signalline then
signal = average[d](indicator)
endif
rindicator = round(indicator)
for a = 1 to 100
if rindicator = a then
$perc[a] = $perc[a]+1
maxval = max(maxval,$perc[a])
break
endif
next
if islastbarupdate then
for a = 1 to 100
thisperc = round(($perc[a]/maxval)*100)
if rindicator = a then
drawpoint(barindex+thisperc+5,a,3) coloured(0,0,255)
drawtext("#thisperc#%",barindex+115,a,sansserif,bold,14) coloured(0,0,128)
endif
r = 255
g = 0
if thisperc >= 25 then
r = 128
g = 0
endif
if thisperc >= 50 then
r = 0
g = 255
endif
if thisperc >= 75 then
r = 0
g = 128
endif
drawrectangle(barindex+5,a,barindex+thisperc+5,a) coloured(r,g,128)
next
for a = 1 to 4
if ADXindex then
drawtext("ADX #p# = #rindicator#",barindex+5,108,sansserif,bold,14) coloured(0,0,128)
break
endif
if WilliamsR then
drawtext("Williams%R #p# = #rindicator#",barindex+5,108,sansserif,bold,14) coloured(0,0,128)
break
endif
if Stoch then
drawtext("Stochastic #p##k##d# = #rindicator#",barindex+5,108,sansserif,bold,14) coloured(0,0,128)
break
endif
if RSIndex or (not Stoch and not WilliamsR and not ADXindex) then
drawtext("RSI #p# = #rindicator#",barindex+5,108,sansserif,bold,14) coloured(0,0,128)
break
endif
next
endif
endif
return 0 coloured(0,0,0,0) as "Line",108 coloured(0,0,0,0) as "Line",indicator as "Indicator",signal style(dottedline) as "Signal"