This indicator can only be used on PRTv11.
The indicator will analyse all of the history on the price chart and every time price is above or below price p bars ago it adds one to an array bucket for the exact percentage of price difference. The array buckets are 0.1% in size.
The distribution of returns curve can be drawn as either a line chart or a histogram with the ‘LineChart’ setting.
The x and y axis auto scale when drawn. The y axis is each filled array buckets quantity as a percentage of the total quantity of tests analysed.
The current position on the curve that price is compared to price p bars ago is also indicated on the curve.
I advise downloading and import to get full functionality.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
//Distribution of Returns //PRT v11 only //By Vonasi //Date: 20200330 defparam drawonlastbaronly = true //Settings //p = 22 /lookback period //linechart = 0 // 0 = histogram 1 = line chart //Fill positive gain array if close > open[p] then riseperc = round((((close - open[p])/open[p])*100),1)*10 $rise[riseperc] = $rise[riseperc] + 1 count = count + 1 endif $risepercentage[riseperc] = ($rise[riseperc]/count)*100 //Fill negative loss array if close < open[p] then fallperc = round((((open[p]-close)/open[p])*100),1)*10 $fall[fallperc] = $fall[fallperc] + 1 count = count + 1 endif $fallpercentage[fallperc] = ($fall[fallperc]/count)*100 //Only do the following code on latest bar to speed things up if islastbarupdate then //Get the latest gain or loss position in arrays if close > open[p] then thisperc = round((((close - open[p])/open[p])*100),1)*10 endif if close < open[p] then thisperc = -round((((open[p]-close)/open[p])*100),1)*10 endif //Initiate drawing positions lastvalue = $risepercentage[1] falllastvalue = 0 //Get highest filled array for auto scaling of x axis lastbar = max(lastset($risepercentage),lastset($fallpercentage)) //draw negative side of chart for a = lastbar downto 1 b = a+(lastbar) //Display line or histogram depending on setting if linechart then drawsegment(barindex-b-1, falllastvalue,barindex-b ,$fallpercentage[a])coloured(128,0,0) else drawrectangle(barindex-b-1, 0,barindex-b ,$fallpercentage[a])coloured(128,0,0) endif //Draw x scale text if a mod 10 = 0 then mytext = a/10 drawtext("-#mytext#", barindex-a+1-lastbar,-0.05,sansserif,bold,10) endif //Draw current position on curve if negative if thisperc = -a then drawpoint(barindex-b ,$fallpercentage[a],3)coloured(128,0,0) endif //Store old value for drawing in next loop round so segment can be drawn falllastvalue = $fallpercentage[a] //Store highest array value for autoscaling of y axis maxval = max(falllastvalue,maxval) next //Connect gap between two sides of line chart if linechart then drawsegment(barindex-b, falllastvalue,barindex-b+2 ,$risepercentage[1])coloured(128,0,0) endif //draw positive side of chart for a = 1 to lastbar b = lastbar-a //Display line or histogram depending on setting if linechart then drawsegment(barindex-b, lastvalue,barindex-b+1 ,$risepercentage[a])coloured(0,128,0) else drawrectangle(barindex-b, 0,barindex-b+1 ,$risepercentage[a])coloured(0,128,0) endif //Draw x scale text if b mod 10 = 0 then mytext = b/10 drawtext("#mytext#", barindex-a+1,-0.05,sansserif,bold,10) endif //Draw current position on curve if positive if thisperc = a then drawpoint(barindex-b+1 ,$risepercentage[a],3)coloured(0,128,0) endif //Store old value for drawing in next loop round so segment can be drawn lastvalue = $risepercentage[a] //Store highest array value for autoscaling of y axis maxval = max(lastvalue,maxval) next endif //draw x axis label drawtext("%", barindex-(lastbar*2)-5,-0.05,sansserif,bold,10) return -0.1 coloured(0,0,0,0),maxval coloured(0,0,0,0) |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Excellent job Vonasi, thanks very much for updating and improving your previous indicator.
sorry but doesnt work like you posted
You would need to let me know the exact instrument and time frame that you are trying to apply the indicator to for me to test myself. I assume you are on v11?