Daily Historical Volatility StdDev Levels R2 For ThinkOrSwim

Hello

I am leaving this link to seek helps to convert Pine script at Tradingview.

https://www.tradingview.com/script/m03F3fQ7-Daily-Historical-Volatility-StdDev-Levels/


--------------------- Code below ______________________________________
//@version=3
//

study(title="Daily Historical Volatility StdDev Levels R2 by JustUncleL", shorttitle="HVSD", overlay = true)

//
// Author : JustUncleL
//
// Description:
// Plots Daily Standard deviation levels on price chart based on Historical Volatility (HV).
// The following uses the most common approach for calculating historical volatility as
// standard deviation of logarithmic returns, based on daily closing/settlement prices.
// Assets: Any Currency, Commodities also on stocks, some indices.
// Time Frames: 5min to 60min.
// This will also work on Daily Chart, by setting "DaystoExpire" to 21
//
// Options:
// - Use Daily Data to Calculate StdDev HV (default), otherwise use the charts Time Frame
// - Lookback = number of days/periods to calculate stddev of HV (21 by default)
// - Annual = number of trading days in a calender year (252 by default)
// - Days to Expiry = number of days for the life of this option ( for auto calculation
// this is 1 for intraday, 21 for dayly and annual when chart TF used)
// - Settlement Source = close price by default, can use another source.
// - Settlement Volume Weighted Average Length = by setting this to >1 then an average
// is used for settlement.
// - Display ### Standard Deviation Levels = select what levels are to be displayed.
//
// References:
// - How To Use Standard Deviation In Your Trading Day
//
// - Deviation Levels Indicator
//
// - http://www.macroption.com/historical-volatility-calculation/
// - Historical Volatility based Standard Deviation_V2 by ucsgears
// - Historical Volatility Strategy by Hpotter
//
// Revisions:
//
// 30-July-2017 : Original
//
// 01-Aug-2017 : - Corrected Change of day detection for Intraday TFs
// - Corrected -0.75 Label.
//
// 14-Aug-2017 : - Chnge to only display background fill for upto +/- 1 Stddev.
// - Added option to Display Only Todays Levels.
//
// 16-Aug-2017 : - Made changes so that it also work with Renko Charts, But
// only works well with short TF (<=5min) and brick (<=6pip).
// - Added Option to display Previous Day's High Low Levels.
// - Added Option to display Current Day's High Low Levels.
// - Changed 0.75 level to 0.7 level.
//
// 9-Sep-2017 : - Modified the way displaying "Only Today" levels, now only
// show up within the current days price action.
//
// 5-Jun-2018 : - Improved efficiency by reducing the number of plot lines
// required by adding "style=2" to the plot options.
// - Added fill colour for 2nd and 3rd Stddevs.
//
// 8-Jun-2018 : - Corrected no history "nohist" flag.
//
//
// -----------------------------------------------------------------------------
// Copyright 2017,2018 @JustUncleL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License can be found here
// <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
//

// === INPUTS
useDaily = input(true,title="Use Daily Data to Calculate HV (default), otherwise chart TF")
LookBack = input(21, minval=1,type=integer)
annual = input(252,minval=1,type=integer)
DaystoExpire_ = input (defval=0, minval=0,type=integer, title="Calender Days to Expiry (0=Auto, default)")
src = input(close,title="Settlement Source (close=default)")
sLength_ = input(1,minval=1,type=integer,title="Settlement Volume Weighted Average Length (1=Use end of day)")
//
stddev1 =input(true,title="Display 1x Standard Deviation Levels")
stddev2 =input(false,title="Display 2x Standard Deviation Levels")
stddev3 =input(false,title="Display 3x Standard Deviation Levels")
pivotNow =input(false,title="Display Only Todays Deviation Levels")
sHiLo =input(false,title="Show Previous Day's High Low Levels")
sHiLoNow =input(false,title="Show Current Day's Running High Low Levels")
//
// === /INPUTs
dodgerblue = #1E90FF
//
// Test for new Daily Session or start of new month for Daily.
sLength = isintraday ? sLength_ : 1
nstart = security(tickerid,"D", n, barmerge.gaps_off, barmerge.lookahead_on)
start = security(tickerid,"D", time, barmerge.gaps_off, barmerge.lookahead_on)
first = security(tickerid,"D",valuewhen(barstate.islast,time,0), barmerge.gaps_off, barmerge.lookahead_on)

nohist = nstart<=max(sLength,LookBack)+1

newDay = nohist? false : isintraday ? change(start) : dayofmonth(time)<dayofmonth(time[1])


// Calculate Annualised Volatility
hv = 0.0
hv_ = useDaily? security(tickerid,"D", stdev(log(src / src[1]), LookBack) * sqrt(annual), barmerge.gaps_off, barmerge.lookahead_on) : stdev(log(src / src[1]), LookBack) * sqrt(annual)
hv := newDay ? hv_ : nz(hv[1],hv_)
hinow = high
hinow := newDay ? high : high>hinow[1] ? high : hinow[1]
lonow = low
lonow := newDay ? low : low<lonow[1] ? low : lonow[1]

prevhi = valuewhen(newDay,hinow[1],0)
prevlo = valuewhen(newDay,lonow[1],0)

// get the Daily Settlement
settlement = sLength==1? valuewhen(start[1]<=time, src, 0) : vwma(src[1],sLength)
settlement := newDay ? settlement : nz(settlement[1],open[1])


//--- debug
//plotchar(n,title="n",location=location.bottom,color=na)
//plotchar(nstart,title="nstart",location=location.bottom,color=na)
//plotchar(nohist,title="noHist",location=location.bottom,color=na)
//plotchar(dayofmonth(start),title="startDay",location=location.bottom,color=na)
//plotchar(hour(start),title="startMins",location=location.bottom,color=na)
//plotchar(dayofmonth(first),title="firstDay",location=location.bottom,color=na)
//plotchar(hour(first),title="firstMins",location=location.bottom,color=na)
//plotchar(newDay,title="newDay",location=location.bottom,color=na)
//--- /debug

firstDay = dayofmonth(start)==dayofmonth(first) and month(start)==month(first) and year(start)==year(first)
//
// Calculate STDdev over life of the option (generally this is one day for 5min to 60min TFs,
// and 21 days for Daily TF)
stdhv = 0.0
DaystoExpire = DaystoExpire_==0? isintraday? useDaily? 1 : min(annual,1440/interval) : LookBack : DaystoExpire_
stdhv := newDay? settlement*hv*sqrt(DaystoExpire/annual) : nz(stdhv[1])

// calculate StdDev lines ratios.
stdhv05 = stdhv * 0.5
stdhv07 = stdhv * 0.7
stdhv1 = stdhv
stdhv15= stdhv*1.5
stdhv2 = stdhv*2.0
stdhv25 = stdhv*2.5
stdhv3 = stdhv*3.0

// Plot the StdDev Levels for all Days.
SettleM = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay? settlement:na, color = purple, style=2,title = "Settlement",linewidth=3, transp=40)
Stdhv05u = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay? (settlement+stdhv05):na, color = orange, style=2,title = "+0.5 SD",linewidth=1, transp=20)
Stdhv05d = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay? (settlement-stdhv05):na, color = orange, style=2,title = "-0.5 SD",linewidth=1, transp=20)
Stdhv07u = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay? (settlement+stdhv07):na, color = red, style=2,title = "+0.7 SD",linewidth=1, transp=20)
Stdhv07d = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay? (settlement-stdhv07):na, color = red, style=2,title = "-0.7 SD",linewidth=1, transp=20)
Stdhv1u = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay? (settlement+stdhv1):na, color = lime, style=2,title = "+1 SD",linewidth=3, transp=20)
Stdhv1d = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay? (settlement-stdhv1):na, color = lime, style=2,title = "-1 SD",linewidth=3, transp=20)
Stdhv15u = plot(not nohist and stddev2 and (not pivotNow or firstDay) and not newDay? (settlement+stdhv15):na, color = green, style=2,title = "+1.5 SD",linewidth=1, transp=20)
Stdhv15d = plot(not nohist and stddev2 and (not pivotNow or firstDay) and not newDay? (settlement-stdhv15):na, color = green, style=2, title = "-1.5 SD",linewidth=1, transp=20)
Stdhv2u = plot(not nohist and stddev2 and (not pivotNow or firstDay) and not newDay? (settlement+stdhv2):na, color = dodgerblue, style=2,title = "+2 SD",linewidth=3, transp=20)
Stdhv2d = plot(not nohist and stddev2 and (not pivotNow or firstDay) and not newDay? (settlement-stdhv2):na, color = dodgerblue, style=2,title = "-2 SD",linewidth=3, transp=20)
Stdhv25u = plot(not nohist and stddev3 and (not pivotNow or firstDay) and not newDay? (settlement+stdhv25):na, color = dodgerblue, style=2,title = "+2.5 SD",linewidth=1, transp=20)
Stdhv25d = plot(not nohist and stddev3 and (not pivotNow or firstDay) and not newDay? (settlement-stdhv25):na, color = dodgerblue, style=2,title = "-2.5 SD",linewidth=1, transp=20)
Stdhv3u = plot(not nohist and stddev3 and (not pivotNow or firstDay) and not newDay? (settlement+stdhv3):na, color = gray, style=2,title = "+3 SD",linewidth=3, transp=20)
Stdhv3d = plot(not nohist and stddev3 and (not pivotNow or firstDay) and not newDay? (settlement-stdhv3):na, color = gray,style=2, title = "-3 SD",linewidth=3, transp=20)
//
plot( (not pivotNow or firstDay) and not nohist and sHiLo and not newDay? prevhi:na, color = navy,style=2, title = "PREV HI",linewidth=2, transp=20,style=cross,join=true)
plot( (not pivotNow or firstDay) and not nohist and sHiLo and not newDay? prevlo:na, color = black,style=2, title = "PREV LO",linewidth=2, transp=20,style=cross,join=true)
plot( (not pivotNow or firstDay) and not nohist and sHiLoNow and not newDay? lonow:na, color = fuchsia,style=2, title = "D Lo",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
plot( (not pivotNow or firstDay) and not nohist and sHiLoNow and not newDay? hinow:na, color = teal,style=2, title = "D Hi",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)

// Colour in between levels.
// Removed causes issues with next option.
fill(Stdhv3d,Stdhv2d,color=gray,transp=95,title="-3 Stdev Fill")
fill(Stdhv3u,Stdhv2u,color=gray,transp=95,title="+3 Stdev Fill")
fill(Stdhv2d,Stdhv15d,color=blue,transp=95,title="-2 Stdev Fill")
fill(Stdhv2u,Stdhv15u,color=blue,transp=95,title="+2 Stdev Fill")
fill(Stdhv15d,Stdhv1d,color=green,transp=95,title="-1.5 Stdev Fill")
fill(Stdhv15u,Stdhv1u,color=green,transp=95,title="+1.5 Stdev Fill")
fill(Stdhv1d,Stdhv07d,color=lime,transp=95,title="-1 Stdev Fill")
fill(Stdhv1u,Stdhv07u,color=lime,transp=95,title="+1 Stdev Fill")
fill(Stdhv07d,Stdhv05d,color=red,transp=95,title="-0.7 Stdev Fill")
fill(Stdhv07u,Stdhv05u,color=red,transp=95,title="+0.7 Stdev Fill")
fill(Stdhv05d,SettleM,color=purple,transp=92,title="-0.5 Stdev Fill")
fill(Stdhv05u,SettleM,color=purple,transp=92,title="+0.5 Stdev Fill")

//
try this.

CSS:
#// Author : JustUncleL
#study(title="Daily Historical Volatility StdDev Levels R2 by JustUncleL", shorttitle="HVSD", overlay = true)
# Converted by Sam4Cok@Samer800    - 05/2023
#// === INPUTS
input UseDailyDataToCalculateVolatility = yes; # "Use Daily Data to Calculate HV (default)
input LookBack = 21;
input annual =   252;
input CalenderDaysToExpiry = 0;                # "Calender Days to Expiry (0=Auto, default)"
input SettlementSource     = close;            # "Settlement Source (close=default)"
input SettlementVolWeightedAvgLength = 1;      # "Settlement Volume Weighted Average Length (1=Use end of day)"
input stdDev1  = yes;                          # "Display 1x Standard Deviation Levels")
input stdDev2  = no;                           # "Display 2x Standard Deviation Levels")
input stdDev3  = no;                           # "Display 3x Standard Deviation Levels")
input DisplayOnlyTodayDeviationLevels = no;    # "Display Only Todays Deviation Levels")
input ShowPreviousDayHighLowLevels    = no;    # "Show Previous Day's High Low Levels")
input ShowCurrentDayHighLowLevels = no;        # "Show Current Day's Running High Low Levels")

def na = Double.NaN;
def last = isNaN(close);
def useDaily = UseDailyDataToCalculateVolatility;
def DaystoExpire_ = CalenderDaysToExpiry;
def sLength_ = SettlementVolWeightedAvgLength;
def showHiLo = ShowPreviousDayHighLowLevels;
def sHiLoNow = ShowCurrentDayHighLowLevels;

DefineGlobalColor("dodgerblue", CreateColor(30, 144, 255));
DefineGlobalColor("teal", CreateColor(0,128,128));
#// Test for new Daily Session or start of new month for Daily.
def current = GetAggregationPeriod();
def isintraday = current < AggregationPeriod.DAY;
def sLength = if isintraday then sLength_ else 1;
def bar = AbsValue(CompoundValue(1, BarNumber(), 0));
def pivotNow =  if DisplayOnlyTodayDeviationLevels then GetDay() != GetLastDay() else 0;
def day = GetDay();
def dayofmonth = GetDayOfMonth(GetYyyyMmDd());#<dayofmonth(time[1])
def time = GetTime();
def nohist = bar <= Max(sLength, LookBack) + 1;
def newDay = if nohist then na else if isintraday then day != day[1] else dayofmonth<dayofmonth[1];

#// Calculate Annualised Volatility
def c = close(Period = AggregationPeriod.DAY);
def hvD = StDev(Log(c / c[1]), LookBack) * Sqrt(annual);
def hvC = StDev(Log(SettlementSource / SettlementSource[1]), LookBack) * Sqrt(annual);
def hv_ = if useDaily then hvD else hvC;
def hv  = if newDay then hv_ else If(isNaN(hv[1]), hv_, hv[1]);
#hinow = high
def hinow = if isNaN(hinow[1]) then high else
            if newDay then high else if high > hinow[1] then high else hinow[1];
#lonow = low
def lonow = if isNaN(lonow[1]) then low else
            if newDay then low else if low < lonow[1] then low else lonow[1];

def prevhi =  if newDay then hinow[1] else prevhi[1];
def prevlo =  if newDay then lonow[1] else prevlo[1];

#// get the Daily Settlement
def preset = Average(SettlementSource[1] * volume, sLength) / Average(volume, sLength);
def settlement_ = if sLength == 1 then SettlementSource else preset;
def settlement = if newDay then settlement_  else If(settlement[1] == 0, open[1], settlement[1]);

def DaystoExpire = if DaystoExpire_==0 then if isintraday then if useDaily then 1 else
                 min(annual,24*60*60*1000/current) else LookBack else DaystoExpire_;
def stdhv = if newDay then settlement*hv*sqrt(DaystoExpire/annual) else stdhv[1];

AddLabel(1 , 24*60*10000/current, color.WHITE);
#// calculate StdDev lines ratios.
def stdhv05 = stdhv * 0.5;
def stdhv07 = stdhv * 0.7;
def stdhv1 = stdhv;
def stdhv15= stdhv*1.5;
def stdhv2 = stdhv*2.0;
def stdhv25 = stdhv*2.5;
def stdhv3 = stdhv*3.0;

#// Plot the StdDev Levels for all Days.
plot SettleM  = if !nohist and stddev1 and (!pivotNow) and !newDay then settlement else na;    #"Settlement"
SettleM.SetDefaultColor(Color.GRAY);
SettleM.SetStyle(Curve.MEDIUM_DASH);

def Stdhv05u = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement+stdhv05) else na;     # "+0.5 SD"
#Stdhv05u.SetDefaultColor(Color.LIGHT_RED);

def Stdhv05d = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement-stdhv05) else na;     # "-0.5 SD"
#Stdhv05d.SetDefaultColor(Color.LIGHT_RED);

def Stdhv07u = if !nohist and stddev1 and (!pivotNow ) and !newDay then (settlement+stdhv07) else na;    # "+0.7 SD"
#Stdhv07u.SetDefaultColor(Color.RED);

def Stdhv07d = if !nohist and stddev1 and (!pivotNow) and !newDay then  (settlement-stdhv07) else na;    # "-0.7 SD"
#Stdhv07d.SetDefaultColor(Color.RED);

plot Stdhv1u = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement+stdhv1) else na;      # "+1 SD"
Stdhv1u.SetLineWeight(2);
Stdhv1u.SetDefaultColor(Color.GREEN);

plot Stdhv1d = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement-stdhv1) else na;      # "-1 SD"
Stdhv1d.SetLineWeight(2);
Stdhv1d.SetDefaultColor(Color.GREEN);

plot Stdhv15u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv15) else na;     # "+1.5 SD"
Stdhv15u.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv15d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv15) else na;     # "-1.5 SD"
Stdhv15d.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv2u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv2) else na;       # "+2 SD"
Stdhv2u.SetLineWeight(2);
Stdhv2u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv2d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv2) else na;       # "-2 SD"
Stdhv2d.SetLineWeight(2);
Stdhv2d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv25) else na;     # "+2.5 SD"
Stdhv25u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv25) else na;     # "-2.5 SD"
Stdhv25d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv3u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv3) else na;       # "+3 SD"
Stdhv3u.SetLineWeight(2);
Stdhv3u.SetDefaultColor(Color.VIOLET);

plot Stdhv3d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv3) else na;       # "-3 SD"
Stdhv3d.SetLineWeight(2);
Stdhv3d.SetDefaultColor(Color.VIOLET);

#// Plot the StdDev Levels for all Days.

plot preHi = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevhi else na;            # "PREV HI"
preHi.SetStyle(Curve.POINTS);
preHi.SetDefaultColor(Color.BLUE);

plot preLo = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevlo else na;            # "PREV LO"
preLo.SetStyle(Curve.POINTS);
preLo.SetDefaultColor(Color.PINK);

plot DLo = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then lonow else na;#, color = fuchsia,style=2, title = "D Lo",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DLo.SetDefaultColor(Color.MAGENTA);
DLo.SetPaintingStrategy(PaintingStrategy.DASHES);

plot DHi = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then hinow else na;#, color = teal,style=2, title = "D Hi",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DHi.SetDefaultColor(GlobalColor("teal"));
DHi.SetPaintingStrategy(PaintingStrategy.DASHES);

AddCloud(Stdhv2d, Stdhv3d , Color.GRAY);        # "-3 Stdev Fill"
AddCloud(Stdhv3u, Stdhv2u , Color.GRAY);        # "+3 Stdev Fill"
AddCloud(Stdhv15d, Stdhv2d, Color.BLUE);        # "-2 Stdev Fill"
AddCloud(Stdhv2u , Stdhv15u, Color.BLUE);       # "+2 Stdev Fill"
AddCloud(Stdhv1d,Stdhv15d, Color.DARK_GREEN);   # "-1.5 Stdev Fill"
AddCloud(Stdhv15u,Stdhv1u,  Color.DARK_GREEN);  # "+1.5 Stdev Fill"
AddCloud(Stdhv07d,Stdhv1d, Color.DARK_GREEN);   # "-1 Stdev Fill"
AddCloud(Stdhv1u,Stdhv07u, Color.DARK_GREEN);   # "+1 Stdev Fill"
AddCloud(Stdhv05d, Stdhv07d, Color.DARK_RED, Color.DARK_RED, yes);   # "-0.7 Stdev Fill"
AddCloud(Stdhv07u,Stdhv05u, Color.DARK_RED, Color.DARK_RED, yes);    # "+0.7 Stdev Fill"
AddCloud(SettleM, Stdhv05d, Color.DARK_GRAY);   # "-0.5 Stdev Fill"
AddCloud(Stdhv05u,SettleM, Color.DARK_GRAY);    # "+0.5 Stdev Fill"

#--- END of CODE
 
try this.

CSS:
#// Author : JustUncleL
#study(title="Daily Historical Volatility StdDev Levels R2 by JustUncleL", shorttitle="HVSD", overlay = true)
# Converted by Sam4Cok@Samer800    - 05/2023
#// === INPUTS
input UseDailyDataToCalculateVolatility = yes; # "Use Daily Data to Calculate HV (default)
input LookBack = 21;
input annual =   252;
input CalenderDaysToExpiry = 0;                # "Calender Days to Expiry (0=Auto, default)"
input SettlementSource     = close;            # "Settlement Source (close=default)"
input SettlementVolWeightedAvgLength = 1;      # "Settlement Volume Weighted Average Length (1=Use end of day)"
input stdDev1  = yes;                          # "Display 1x Standard Deviation Levels")
input stdDev2  = no;                           # "Display 2x Standard Deviation Levels")
input stdDev3  = no;                           # "Display 3x Standard Deviation Levels")
input DisplayOnlyTodayDeviationLevels = no;    # "Display Only Todays Deviation Levels")
input ShowPreviousDayHighLowLevels    = no;    # "Show Previous Day's High Low Levels")
input ShowCurrentDayHighLowLevels = no;        # "Show Current Day's Running High Low Levels")

def na = Double.NaN;
def last = isNaN(close);
def useDaily = UseDailyDataToCalculateVolatility;
def DaystoExpire_ = CalenderDaysToExpiry;
def sLength_ = SettlementVolWeightedAvgLength;
def showHiLo = ShowPreviousDayHighLowLevels;
def sHiLoNow = ShowCurrentDayHighLowLevels;

DefineGlobalColor("dodgerblue", CreateColor(30, 144, 255));
DefineGlobalColor("teal", CreateColor(0,128,128));
#// Test for new Daily Session or start of new month for Daily.
def current = GetAggregationPeriod();
def isintraday = current < AggregationPeriod.DAY;
def sLength = if isintraday then sLength_ else 1;
def bar = AbsValue(CompoundValue(1, BarNumber(), 0));
def pivotNow =  if DisplayOnlyTodayDeviationLevels then GetDay() != GetLastDay() else 0;
def day = GetDay();
def dayofmonth = GetDayOfMonth(GetYyyyMmDd());#<dayofmonth(time[1])
def time = GetTime();
def nohist = bar <= Max(sLength, LookBack) + 1;
def newDay = if nohist then na else if isintraday then day != day[1] else dayofmonth<dayofmonth[1];

#// Calculate Annualised Volatility
def c = close(Period = AggregationPeriod.DAY);
def hvD = StDev(Log(c / c[1]), LookBack) * Sqrt(annual);
def hvC = StDev(Log(SettlementSource / SettlementSource[1]), LookBack) * Sqrt(annual);
def hv_ = if useDaily then hvD else hvC;
def hv  = if newDay then hv_ else If(isNaN(hv[1]), hv_, hv[1]);
#hinow = high
def hinow = if isNaN(hinow[1]) then high else
            if newDay then high else if high > hinow[1] then high else hinow[1];
#lonow = low
def lonow = if isNaN(lonow[1]) then low else
            if newDay then low else if low < lonow[1] then low else lonow[1];

def prevhi =  if newDay then hinow[1] else prevhi[1];
def prevlo =  if newDay then lonow[1] else prevlo[1];

#// get the Daily Settlement
def preset = Average(SettlementSource[1] * volume, sLength) / Average(volume, sLength);
def settlement_ = if sLength == 1 then SettlementSource else preset;
def settlement = if newDay then settlement_  else If(settlement[1] == 0, open[1], settlement[1]);

def DaystoExpire = if DaystoExpire_==0 then if isintraday then if useDaily then 1 else
                 min(annual,24*60*60*1000/current) else LookBack else DaystoExpire_;
def stdhv = if newDay then settlement*hv*sqrt(DaystoExpire/annual) else stdhv[1];

AddLabel(1 , 24*60*10000/current, color.WHITE);
#// calculate StdDev lines ratios.
def stdhv05 = stdhv * 0.5;
def stdhv07 = stdhv * 0.7;
def stdhv1 = stdhv;
def stdhv15= stdhv*1.5;
def stdhv2 = stdhv*2.0;
def stdhv25 = stdhv*2.5;
def stdhv3 = stdhv*3.0;

#// Plot the StdDev Levels for all Days.
plot SettleM  = if !nohist and stddev1 and (!pivotNow) and !newDay then settlement else na;    #"Settlement"
SettleM.SetDefaultColor(Color.GRAY);
SettleM.SetStyle(Curve.MEDIUM_DASH);

def Stdhv05u = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement+stdhv05) else na;     # "+0.5 SD"
#Stdhv05u.SetDefaultColor(Color.LIGHT_RED);

def Stdhv05d = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement-stdhv05) else na;     # "-0.5 SD"
#Stdhv05d.SetDefaultColor(Color.LIGHT_RED);

def Stdhv07u = if !nohist and stddev1 and (!pivotNow ) and !newDay then (settlement+stdhv07) else na;    # "+0.7 SD"
#Stdhv07u.SetDefaultColor(Color.RED);

def Stdhv07d = if !nohist and stddev1 and (!pivotNow) and !newDay then  (settlement-stdhv07) else na;    # "-0.7 SD"
#Stdhv07d.SetDefaultColor(Color.RED);

plot Stdhv1u = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement+stdhv1) else na;      # "+1 SD"
Stdhv1u.SetLineWeight(2);
Stdhv1u.SetDefaultColor(Color.GREEN);

plot Stdhv1d = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement-stdhv1) else na;      # "-1 SD"
Stdhv1d.SetLineWeight(2);
Stdhv1d.SetDefaultColor(Color.GREEN);

plot Stdhv15u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv15) else na;     # "+1.5 SD"
Stdhv15u.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv15d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv15) else na;     # "-1.5 SD"
Stdhv15d.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv2u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv2) else na;       # "+2 SD"
Stdhv2u.SetLineWeight(2);
Stdhv2u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv2d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv2) else na;       # "-2 SD"
Stdhv2d.SetLineWeight(2);
Stdhv2d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv25) else na;     # "+2.5 SD"
Stdhv25u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv25) else na;     # "-2.5 SD"
Stdhv25d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv3u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv3) else na;       # "+3 SD"
Stdhv3u.SetLineWeight(2);
Stdhv3u.SetDefaultColor(Color.VIOLET);

plot Stdhv3d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv3) else na;       # "-3 SD"
Stdhv3d.SetLineWeight(2);
Stdhv3d.SetDefaultColor(Color.VIOLET);

#// Plot the StdDev Levels for all Days.

plot preHi = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevhi else na;            # "PREV HI"
preHi.SetStyle(Curve.POINTS);
preHi.SetDefaultColor(Color.BLUE);

plot preLo = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevlo else na;            # "PREV LO"
preLo.SetStyle(Curve.POINTS);
preLo.SetDefaultColor(Color.PINK);

plot DLo = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then lonow else na;#, color = fuchsia,style=2, title = "D Lo",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DLo.SetDefaultColor(Color.MAGENTA);
DLo.SetPaintingStrategy(PaintingStrategy.DASHES);

plot DHi = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then hinow else na;#, color = teal,style=2, title = "D Hi",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DHi.SetDefaultColor(GlobalColor("teal"));
DHi.SetPaintingStrategy(PaintingStrategy.DASHES);

AddCloud(Stdhv2d, Stdhv3d , Color.GRAY);        # "-3 Stdev Fill"
AddCloud(Stdhv3u, Stdhv2u , Color.GRAY);        # "+3 Stdev Fill"
AddCloud(Stdhv15d, Stdhv2d, Color.BLUE);        # "-2 Stdev Fill"
AddCloud(Stdhv2u , Stdhv15u, Color.BLUE);       # "+2 Stdev Fill"
AddCloud(Stdhv1d,Stdhv15d, Color.DARK_GREEN);   # "-1.5 Stdev Fill"
AddCloud(Stdhv15u,Stdhv1u,  Color.DARK_GREEN);  # "+1.5 Stdev Fill"
AddCloud(Stdhv07d,Stdhv1d, Color.DARK_GREEN);   # "-1 Stdev Fill"
AddCloud(Stdhv1u,Stdhv07u, Color.DARK_GREEN);   # "+1 Stdev Fill"
AddCloud(Stdhv05d, Stdhv07d, Color.DARK_RED, Color.DARK_RED, yes);   # "-0.7 Stdev Fill"
AddCloud(Stdhv07u,Stdhv05u, Color.DARK_RED, Color.DARK_RED, yes);    # "+0.7 Stdev Fill"
AddCloud(SettleM, Stdhv05d, Color.DARK_GRAY);   # "-0.5 Stdev Fill"
AddCloud(Stdhv05u,SettleM, Color.DARK_GRAY);    # "+0.5 Stdev Fill"

#--- END of CODE
@samer800 Is it possible to convert this to weekly and monthly levels
 
@samer800 Is it possible to convert this to weekly and monthly levels
try this. I didn't test it.
CSS:
#// Author : JustUncleL
#study(title="Daily Historical Volatility StdDev Levels R2 by JustUncleL", shorttitle="HVSD", overlay = true)
# Converted by Sam4Cok@Samer800    - 05/2023
#// === INPUTS
input VolatilityTimeframe = {Default Daily, Weekly, Monthly};
input UseDailyDataToCalculateVolatility = yes; # "Use Daily Data to Calculate HV (default)
input LookBack = 21;
input annual =   252;
input CalenderDaysToExpiry = 0;                # "Calender Days to Expiry (0=Auto, default)"
input SettlementSource     = close;            # "Settlement Source (close=default)"
input SettlementVolWeightedAvgLength = 1;      # "Settlement Volume Weighted Average Length (1=Use end of day)"
input stdDev1  = yes;                          # "Display 1x Standard Deviation Levels")
input stdDev2  = no;                           # "Display 2x Standard Deviation Levels")
input stdDev3  = no;                           # "Display 3x Standard Deviation Levels")
input DisplayOnlyTodayDeviationLevels = no;    # "Display Only Todays Deviation Levels")
input ShowPreviousDayHighLowLevels    = no;    # "Show Previous Day's High Low Levels")
input ShowCurrentDayHighLowLevels = no;        # "Show Current Day's Running High Low Levels")

def na = Double.NaN;
def last = isNaN(close);
def useDaily = UseDailyDataToCalculateVolatility;
def DaystoExpire_ = CalenderDaysToExpiry;
def sLength_ = SettlementVolWeightedAvgLength;
def showHiLo = ShowPreviousDayHighLowLevels;
def sHiLoNow = ShowCurrentDayHighLowLevels;

DefineGlobalColor("dodgerblue", CreateColor(30, 144, 255));
DefineGlobalColor("teal", CreateColor(0,128,128));
#// Test for new Daily Session or start of new month for Daily.
def day;# = GetWeek();
Switch (VolatilityTimeframe) {
case Daily   : day = GetDay();
case Weekly  : day = GetWeek();
case Monthly : day = GetMonth();
}

def current = GetAggregationPeriod();
def isintraday = current < AggregationPeriod.DAY;
def sLength = if isintraday then sLength_ else 1;
def bar = AbsValue(CompoundValue(1, BarNumber(), 0));
def pivotNow =  if DisplayOnlyTodayDeviationLevels then GetDay()!=GetLastDay() else 0;

def dayofmonth = GetDayOfMonth(GetYyyyMmDd());#<dayofmonth(time[1])
def time = GetTime();
def nohist = bar <= Max(sLength, LookBack) + 1;
def newDay = if nohist then na else day != day[1];#if isintraday then day != day[1] else dayofmonth<dayofmonth[1];

#// Calculate Annualised Volatility
def c = close(Period = AggregationPeriod.DAY);
def hvD = StDev(Log(c / c[1]), LookBack) * Sqrt(annual);
def hvC = StDev(Log(SettlementSource / SettlementSource[1]), LookBack) * Sqrt(annual);
def hv_ = if useDaily then hvD else hvC;
def hv  = if newDay then hv_ else If(isNaN(hv[1]), hv_, hv[1]);
#hinow = high
def hinow = if isNaN(hinow[1]) then high else
            if newDay then high else if high > hinow[1] then high else hinow[1];
#lonow = low
def lonow = if isNaN(lonow[1]) then low else
            if newDay then low else if low < lonow[1] then low else lonow[1];

def prevhi =  if newDay then hinow[1] else prevhi[1];
def prevlo =  if newDay then lonow[1] else prevlo[1];

#// get the Daily Settlement
def preset = Average(SettlementSource[1] * volume, sLength) / Average(volume, sLength);
def settlement_ = if sLength == 1 then SettlementSource else preset;
def settlement = if newDay then settlement_  else If(settlement[1] == 0, open[1], settlement[1]);

def DaystoExpire = if DaystoExpire_==0 then if isintraday then if useDaily then 1 else
                 min(annual,24*60*60*1000/current) else LookBack else DaystoExpire_;
def stdhv = if newDay then settlement*hv*sqrt(DaystoExpire/annual) else stdhv[1];

AddLabel(1 , 24*60*10000/current, color.WHITE);
#// calculate StdDev lines ratios.
def stdhv05 = stdhv * 0.5;
def stdhv07 = stdhv * 0.7;
def stdhv1 = stdhv;
def stdhv15= stdhv*1.5;
def stdhv2 = stdhv*2.0;
def stdhv25 = stdhv*2.5;
def stdhv3 = stdhv*3.0;

#// Plot the StdDev Levels for all Days.
plot SettleM  = if !nohist and stddev1 and (!pivotNow) and !newDay then settlement else na;    #"Settlement"
SettleM.SetDefaultColor(Color.GRAY);
SettleM.SetStyle(Curve.MEDIUM_DASH);

def Stdhv05u = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement+stdhv05) else na;     # "+0.5 SD"
#Stdhv05u.SetDefaultColor(Color.LIGHT_RED);

def Stdhv05d = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement-stdhv05) else na;     # "-0.5 SD"
#Stdhv05d.SetDefaultColor(Color.LIGHT_RED);

def Stdhv07u = if !nohist and stddev1 and (!pivotNow ) and !newDay then (settlement+stdhv07) else na;    # "+0.7 SD"
#Stdhv07u.SetDefaultColor(Color.RED);

def Stdhv07d = if !nohist and stddev1 and (!pivotNow) and !newDay then  (settlement-stdhv07) else na;    # "-0.7 SD"
#Stdhv07d.SetDefaultColor(Color.RED);

plot Stdhv1u = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement+stdhv1) else na;      # "+1 SD"
Stdhv1u.SetLineWeight(2);
Stdhv1u.SetDefaultColor(Color.GREEN);

plot Stdhv1d = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement-stdhv1) else na;      # "-1 SD"
Stdhv1d.SetLineWeight(2);
Stdhv1d.SetDefaultColor(Color.GREEN);

plot Stdhv15u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv15) else na;     # "+1.5 SD"
Stdhv15u.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv15d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv15) else na;     # "-1.5 SD"
Stdhv15d.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv2u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv2) else na;       # "+2 SD"
Stdhv2u.SetLineWeight(2);
Stdhv2u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv2d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv2) else na;       # "-2 SD"
Stdhv2d.SetLineWeight(2);
Stdhv2d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv25) else na;     # "+2.5 SD"
Stdhv25u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv25) else na;     # "-2.5 SD"
Stdhv25d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv3u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv3) else na;       # "+3 SD"
Stdhv3u.SetLineWeight(2);
Stdhv3u.SetDefaultColor(Color.VIOLET);

plot Stdhv3d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv3) else na;       # "-3 SD"
Stdhv3d.SetLineWeight(2);
Stdhv3d.SetDefaultColor(Color.VIOLET);

#// Plot the StdDev Levels for all Days.

plot preHi = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevhi else na;            # "PREV HI"
preHi.SetStyle(Curve.POINTS);
preHi.SetDefaultColor(Color.BLUE);

plot preLo = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevlo else na;            # "PREV LO"
preLo.SetStyle(Curve.POINTS);
preLo.SetDefaultColor(Color.PINK);

plot DLo = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then lonow else na;#, color = fuchsia,style=2, title = "D Lo",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DLo.SetDefaultColor(Color.MAGENTA);
DLo.SetPaintingStrategy(PaintingStrategy.DASHES);

plot DHi = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then hinow else na;#, color = teal,style=2, title = "D Hi",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DHi.SetDefaultColor(GlobalColor("teal"));
DHi.SetPaintingStrategy(PaintingStrategy.DASHES);

AddCloud(Stdhv2d, Stdhv3d , Color.GRAY);        # "-3 Stdev Fill"
AddCloud(Stdhv3u, Stdhv2u , Color.GRAY);        # "+3 Stdev Fill"
AddCloud(Stdhv15d, Stdhv2d, Color.BLUE);        # "-2 Stdev Fill"
AddCloud(Stdhv2u , Stdhv15u, Color.BLUE);       # "+2 Stdev Fill"
AddCloud(Stdhv1d,Stdhv15d, Color.DARK_GREEN);   # "-1.5 Stdev Fill"
AddCloud(Stdhv15u,Stdhv1u,  Color.DARK_GREEN);  # "+1.5 Stdev Fill"
AddCloud(Stdhv07d,Stdhv1d, Color.DARK_GREEN);   # "-1 Stdev Fill"
AddCloud(Stdhv1u,Stdhv07u, Color.DARK_GREEN);   # "+1 Stdev Fill"
AddCloud(Stdhv05d, Stdhv07d, Color.DARK_RED, Color.DARK_RED, yes);   # "-0.7 Stdev Fill"
AddCloud(Stdhv07u,Stdhv05u, Color.DARK_RED, Color.DARK_RED, yes);    # "+0.7 Stdev Fill"
AddCloud(SettleM, Stdhv05d, Color.DARK_GRAY);   # "-0.5 Stdev Fill"
AddCloud(Stdhv05u,SettleM, Color.DARK_GRAY);    # "+0.5 Stdev Fill"

#--- END of CODE
 
try this. I didn't test it.
CSS:
#// Author : JustUncleL
#study(title="Daily Historical Volatility StdDev Levels R2 by JustUncleL", shorttitle="HVSD", overlay = true)
# Converted by Sam4Cok@Samer800    - 05/2023
#// === INPUTS
input VolatilityTimeframe = {Default Daily, Weekly, Monthly};
input UseDailyDataToCalculateVolatility = yes; # "Use Daily Data to Calculate HV (default)
input LookBack = 21;
input annual =   252;
input CalenderDaysToExpiry = 0;                # "Calender Days to Expiry (0=Auto, default)"
input SettlementSource     = close;            # "Settlement Source (close=default)"
input SettlementVolWeightedAvgLength = 1;      # "Settlement Volume Weighted Average Length (1=Use end of day)"
input stdDev1  = yes;                          # "Display 1x Standard Deviation Levels")
input stdDev2  = no;                           # "Display 2x Standard Deviation Levels")
input stdDev3  = no;                           # "Display 3x Standard Deviation Levels")
input DisplayOnlyTodayDeviationLevels = no;    # "Display Only Todays Deviation Levels")
input ShowPreviousDayHighLowLevels    = no;    # "Show Previous Day's High Low Levels")
input ShowCurrentDayHighLowLevels = no;        # "Show Current Day's Running High Low Levels")

def na = Double.NaN;
def last = isNaN(close);
def useDaily = UseDailyDataToCalculateVolatility;
def DaystoExpire_ = CalenderDaysToExpiry;
def sLength_ = SettlementVolWeightedAvgLength;
def showHiLo = ShowPreviousDayHighLowLevels;
def sHiLoNow = ShowCurrentDayHighLowLevels;

DefineGlobalColor("dodgerblue", CreateColor(30, 144, 255));
DefineGlobalColor("teal", CreateColor(0,128,128));
#// Test for new Daily Session or start of new month for Daily.
def day;# = GetWeek();
Switch (VolatilityTimeframe) {
case Daily   : day = GetDay();
case Weekly  : day = GetWeek();
case Monthly : day = GetMonth();
}

def current = GetAggregationPeriod();
def isintraday = current < AggregationPeriod.DAY;
def sLength = if isintraday then sLength_ else 1;
def bar = AbsValue(CompoundValue(1, BarNumber(), 0));
def pivotNow =  if DisplayOnlyTodayDeviationLevels then GetDay()!=GetLastDay() else 0;

def dayofmonth = GetDayOfMonth(GetYyyyMmDd());#<dayofmonth(time[1])
def time = GetTime();
def nohist = bar <= Max(sLength, LookBack) + 1;
def newDay = if nohist then na else day != day[1];#if isintraday then day != day[1] else dayofmonth<dayofmonth[1];

#// Calculate Annualised Volatility
def c = close(Period = AggregationPeriod.DAY);
def hvD = StDev(Log(c / c[1]), LookBack) * Sqrt(annual);
def hvC = StDev(Log(SettlementSource / SettlementSource[1]), LookBack) * Sqrt(annual);
def hv_ = if useDaily then hvD else hvC;
def hv  = if newDay then hv_ else If(isNaN(hv[1]), hv_, hv[1]);
#hinow = high
def hinow = if isNaN(hinow[1]) then high else
            if newDay then high else if high > hinow[1] then high else hinow[1];
#lonow = low
def lonow = if isNaN(lonow[1]) then low else
            if newDay then low else if low < lonow[1] then low else lonow[1];

def prevhi =  if newDay then hinow[1] else prevhi[1];
def prevlo =  if newDay then lonow[1] else prevlo[1];

#// get the Daily Settlement
def preset = Average(SettlementSource[1] * volume, sLength) / Average(volume, sLength);
def settlement_ = if sLength == 1 then SettlementSource else preset;
def settlement = if newDay then settlement_  else If(settlement[1] == 0, open[1], settlement[1]);

def DaystoExpire = if DaystoExpire_==0 then if isintraday then if useDaily then 1 else
                 min(annual,24*60*60*1000/current) else LookBack else DaystoExpire_;
def stdhv = if newDay then settlement*hv*sqrt(DaystoExpire/annual) else stdhv[1];

AddLabel(1 , 24*60*10000/current, color.WHITE);
#// calculate StdDev lines ratios.
def stdhv05 = stdhv * 0.5;
def stdhv07 = stdhv * 0.7;
def stdhv1 = stdhv;
def stdhv15= stdhv*1.5;
def stdhv2 = stdhv*2.0;
def stdhv25 = stdhv*2.5;
def stdhv3 = stdhv*3.0;

#// Plot the StdDev Levels for all Days.
plot SettleM  = if !nohist and stddev1 and (!pivotNow) and !newDay then settlement else na;    #"Settlement"
SettleM.SetDefaultColor(Color.GRAY);
SettleM.SetStyle(Curve.MEDIUM_DASH);

def Stdhv05u = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement+stdhv05) else na;     # "+0.5 SD"
#Stdhv05u.SetDefaultColor(Color.LIGHT_RED);

def Stdhv05d = if !nohist and stddev1 and (!pivotNow) and !newDay then (settlement-stdhv05) else na;     # "-0.5 SD"
#Stdhv05d.SetDefaultColor(Color.LIGHT_RED);

def Stdhv07u = if !nohist and stddev1 and (!pivotNow ) and !newDay then (settlement+stdhv07) else na;    # "+0.7 SD"
#Stdhv07u.SetDefaultColor(Color.RED);

def Stdhv07d = if !nohist and stddev1 and (!pivotNow) and !newDay then  (settlement-stdhv07) else na;    # "-0.7 SD"
#Stdhv07d.SetDefaultColor(Color.RED);

plot Stdhv1u = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement+stdhv1) else na;      # "+1 SD"
Stdhv1u.SetLineWeight(2);
Stdhv1u.SetDefaultColor(Color.GREEN);

plot Stdhv1d = if !nohist and stddev1 and  (!pivotNow) and !newDay then (settlement-stdhv1) else na;      # "-1 SD"
Stdhv1d.SetLineWeight(2);
Stdhv1d.SetDefaultColor(Color.GREEN);

plot Stdhv15u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv15) else na;     # "+1.5 SD"
Stdhv15u.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv15d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv15) else na;     # "-1.5 SD"
Stdhv15d.SetDefaultColor(Color.DARK_GREEN);

plot Stdhv2u = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement+stdhv2) else na;       # "+2 SD"
Stdhv2u.SetLineWeight(2);
Stdhv2u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv2d = if !nohist and stddev2 and (!pivotNow) and !newDay then (settlement-stdhv2) else na;       # "-2 SD"
Stdhv2d.SetLineWeight(2);
Stdhv2d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv25) else na;     # "+2.5 SD"
Stdhv25u.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv25d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv25) else na;     # "-2.5 SD"
Stdhv25d.SetDefaultColor(GlobalColor("dodgerblue"));

plot Stdhv3u = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement+stdhv3) else na;       # "+3 SD"
Stdhv3u.SetLineWeight(2);
Stdhv3u.SetDefaultColor(Color.VIOLET);

plot Stdhv3d = if !nohist and stddev3 and (!pivotNow) and !newDay then (settlement-stdhv3) else na;       # "-3 SD"
Stdhv3d.SetLineWeight(2);
Stdhv3d.SetDefaultColor(Color.VIOLET);

#// Plot the StdDev Levels for all Days.

plot preHi = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevhi else na;            # "PREV HI"
preHi.SetStyle(Curve.POINTS);
preHi.SetDefaultColor(Color.BLUE);

plot preLo = if last then na else
             if (!pivotNow ) and !nohist and showHiLo and !newDay then prevlo else na;            # "PREV LO"
preLo.SetStyle(Curve.POINTS);
preLo.SetDefaultColor(Color.PINK);

plot DLo = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then lonow else na;#, color = fuchsia,style=2, title = "D Lo",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DLo.SetDefaultColor(Color.MAGENTA);
DLo.SetPaintingStrategy(PaintingStrategy.DASHES);

plot DHi = if (!pivotNow ) and !nohist and sHiLoNow and !newDay then hinow else na;#, color = teal,style=2, title = "D Hi",linewidth=2, transp=20,trackprice = false,offset=0,style=circles,join=true)
DHi.SetDefaultColor(GlobalColor("teal"));
DHi.SetPaintingStrategy(PaintingStrategy.DASHES);

AddCloud(Stdhv2d, Stdhv3d , Color.GRAY);        # "-3 Stdev Fill"
AddCloud(Stdhv3u, Stdhv2u , Color.GRAY);        # "+3 Stdev Fill"
AddCloud(Stdhv15d, Stdhv2d, Color.BLUE);        # "-2 Stdev Fill"
AddCloud(Stdhv2u , Stdhv15u, Color.BLUE);       # "+2 Stdev Fill"
AddCloud(Stdhv1d,Stdhv15d, Color.DARK_GREEN);   # "-1.5 Stdev Fill"
AddCloud(Stdhv15u,Stdhv1u,  Color.DARK_GREEN);  # "+1.5 Stdev Fill"
AddCloud(Stdhv07d,Stdhv1d, Color.DARK_GREEN);   # "-1 Stdev Fill"
AddCloud(Stdhv1u,Stdhv07u, Color.DARK_GREEN);   # "+1 Stdev Fill"
AddCloud(Stdhv05d, Stdhv07d, Color.DARK_RED, Color.DARK_RED, yes);   # "-0.7 Stdev Fill"
AddCloud(Stdhv07u,Stdhv05u, Color.DARK_RED, Color.DARK_RED, yes);    # "+0.7 Stdev Fill"
AddCloud(SettleM, Stdhv05d, Color.DARK_GRAY);   # "-0.5 Stdev Fill"
AddCloud(Stdhv05u,SettleM, Color.DARK_GRAY);    # "+0.5 Stdev Fill"

#--- END of CODE
As Always, thank you so much for all you do for this community.
 
Sameer -

Thank you. My search skills need some work. But can you explain what the red shading represents ? This is what TV looks like with a 1std enabled (I know the levels are a bit off )

Would love to remove the shading if possible to make it just levels where i can define their weight and color (which is already enabled)
1702428059275.png


1702427828012.png


Any takers?
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
626 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top