Pine Script_Calmar Ratio Custom Range
Forums › ProRealTime English forum › ProBuilder support › Pine Script_Calmar Ratio Custom Range
- This topic has 2 replies, 2 voices, and was last updated 15 hours ago by
Iván.
Viewing 3 posts - 1 through 3 (of 3 total)
-
-
04/22/2025 at 12:49 PM #246216
This indicator aims to provide a risk-adjusted return statistic for a security over a selected period. Return is measured as CAGR and risk as Max Drawdown. The ratio of these two gives the Calmar Ratio. It works on any timeframe or range.
Calmar Ratio Custom Range on TradingView (open-source script)
It would be great if someone could convert it to ProBuilder.
04/24/2025 at 10:50 AM #246329Here you have:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091//-------------------------------------------------------////PRC_Calmar Ratio//version = 0//23.04.25//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledgedefparam drawonlastbaronly=true//-----------------------------------------------//// Inputs//-----------------------------------------------//startDate=20250207startTime=100000endDate=20250407endTime=150000//-----------------------------------------------//// Calculate x1,y1 and x2,y2//-----------------------------------------------//tm = gettimeframeif tm >= 86400 thenif opendate=startdate thenidxStart=barindexValueStart=closeendifif opendate=endDate thenidxEnd=barindexValueEnd=closeendifelseif opendate=startdate and opentime=startTime thenidxStart=barindexValueStart=closeendifif opendate=endDate and opentime=endTime thenidxEnd=barindexValueEnd=closeendifendifif ValueEnd>ValueStart thenr=0g=255b=0elser=255g=0b=0endif//-----------------------------------------------//// Draw and calculations//-----------------------------------------------//if startDate>=EndDate thendrawtext("You need more than 1 day between 2 points",0,-100)anchor(top,xshift,yshift)elsif ValueStart=0 or ValueEnd=0 thendrawtext("Check the start date you entered. It might be that you don’t have enough bars loaded.Or maybe you entered a day/time when the market was closed",0,-100)anchor(top,xshift,yshift)elseif islastbarupdate thenn1=barindex-idxStartn2=barindex-idxEnd//-----------------------------------------------//drawpoint(idxStart,ValueStart,5)coloured(r,g,b,30)drawpoint(idxEnd,ValueEnd,5)coloured(r,g,b,30)drawpoint(idxStart,ValueStart,2)coloured(r,g,b)drawpoint(idxEnd,ValueEnd,2)coloured(r,g,b)drawsegment(idxStart,ValueStart,idxEnd,ValueEnd)coloured(r,g,b)//-----------------------------------------------//drawvline(barindex[n1])style(dottedline)drawvline(barindex[n2])style(dottedline)//-----------------------------------------------//daysBetween=endDate-startDateiYears=daysBetween/365cagr = round((pow(ValueEnd/ValueStart,(1/iyears))-1)*100,2)//-----------------------------------------------//peak=ValueStartmaxDD=0for i=n1 downto n2 doif close[i]>peak thenpeak=close[i]endifdd=(peak-close[i])/peak*100if dd>maxDD thenmaxDD=ddendifnext//-----------------------------------------------//MaxDrawDown=round(-maxDD,2)Calmar=round(cagr/maxDD,2)drawtext("CAGR=#cagr#%",-100,-100)anchor(topright,xshift,yshift)drawtext("MaxDD=#MaxDrawDown#%",-100,-120)anchor(topright,xshift,yshift)drawtext("Calmar=#Calmar#",-100,-140)anchor(topright,xshift,yshift)endifendifreturn04/24/2025 at 3:09 PM #246347Now it’s better than the previous one.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108//-------------------------------------------------------////PRC_Calmar Ratio//version = 0//23.04.25//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledgedefparam drawonlastbaronly=true//-----------------------------------------------//// Inputs//-----------------------------------------------//startDate=20250207startTime=100000endDate=20250407endTime=150000//-----------------------------------------------//// Calculate x1,y1 and x2,y2//-----------------------------------------------//tm = gettimeframeif tm >= 86400 thenif opendate=startdate thenidxStart=barindexValueStart=closeendifif opendate=endDate thenidxEnd=barindexValueEnd=closeendifelseif opendate=startdate and opentime=startTime thenidxStart=barindexValueStart=closeendifif opendate=endDate and opentime=endTime thenidxEnd=barindexValueEnd=closeendifendifif ValueEnd>ValueStart thenr=0g=255b=0elser=255g=0b=0endif//-----------------------------------------------//// Draw and calculations//-----------------------------------------------//if startDate>=EndDate thendrawtext("You need more than 1 day between 2 points",0,-100)anchor(top,xshift,yshift)elsif ValueStart=0 or ValueEnd=0 thendrawtext("Check the start date you entered. It might be that you don’t have enough bars loaded.Or maybe you entered a day/time when the market was closed",0,-100)anchor(top,xshift,yshift)elseif islastbarupdate thenn1=barindex-idxStartn2=barindex-idxEnd//-----------------------------------------------//drawpoint(idxStart,ValueStart,5)coloured(r,g,b,30)drawpoint(idxEnd,ValueEnd,5)coloured(r,g,b,30)drawpoint(idxStart,ValueStart,2)coloured(r,g,b)drawpoint(idxEnd,ValueEnd,2)coloured(r,g,b)drawsegment(idxStart,ValueStart,idxEnd,ValueEnd)coloured(r,g,b)//-----------------------------------------------//drawvline(barindex[n1])style(dottedline)drawvline(barindex[n2])style(dottedline)//-----------------------------------------------//peak=ValueStartmaxDD=0bars=0for i=n1 downto n2 doif tm>=86400 thenbars=bars+1elseif openday<>openday[1] thenbars=bars+1elsebars=barsendifendifif close[i]>peak thenpeak=close[i]endifdd=(peak-close[i])/peak*100if dd>maxDD thenmaxDD=ddendifnext//-----------------------------------------------////---Check timeframe for CAGR calculation--------//if tm = 2592000 then //monthly timeframen = 12elsif tm = 604800 then //weekly timeframen = 52elsif tm <=86400 then //Other timeframes (daily or less)n = 252endifiYears=bars/ncagr = round((pow(ValueEnd/ValueStart,(1/iyears))-1)*100,2)//-----------------------------------------------//MaxDrawDown=round(-maxDD,2)Calmar=round(cagr/maxDD,2)drawtext("CAGR=#cagr#%",-100,-100)anchor(topright,xshift,yshift)drawtext("MaxDD=#MaxDrawDown#%",-100,-120)anchor(topright,xshift,yshift)drawtext("Calmar=#Calmar#",-100,-140)anchor(topright,xshift,yshift)endifendifreturn -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
Find exclusive trading pro-tools on
Similar topics: