Relative Volume Standard Deviation for ThinkorSwim

XeoNoX

Well-known member
VIP
This is the built in code of TOS for RelativeVolumeStDev

i however when its charted on a chart i just want to hide (not show) the bars that are under 2.0 times the relative volume.
example pic of what im trying to hide attached

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2014-2019
#

declare lower;
declare zerobase;

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
plot StDevLevel = numDev;

RelVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelVol.SetLineWeight(3);
RelVol.DefineColor("Above", GetColor(0));
RelVol.DefineColor("Below", GetColor(2));
RelVol.AssignValueColor(if RelVol >= numDev then RelVol.Color("Above") else RelVol.Color("Below"));
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);

nnwid8K.png
 

tomsk

Well-known member
VIP
@XeoNoX Per your request I have modified your study so that it only displays bars ABOVE the dotted line.
Here is the code, I tested against your 1 min chart of AMD

Code:
declare lower;
declare zerobase;

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);

plot StDevLevel = numDev;
plot RV = if RelVol > numDev then RelVol else Double.NaN;

RV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RV.SetLineWeight(3);
RV.DefineColor("Above", GetColor(0));
RV.DefineColor("Below", GetColor(2));
RV.AssignValueColor(if RelVol >= numDev then RV.Color("Above") else RV.Color("Below"));
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);
# End Code
 
Last edited:

ronl1975

New member
Hi everybody. I am brand new here. I like using the TOS built in study RelativeVolumeStDev. However I would like to set an alert if the numDev were to hit 4.0 or higher during intraday and PM/AH. Could somebody kindly help me out. I've tried using some alert code but no luck; I have no clue what I'm doing. Please help!

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2014-2021
#

declare lower;
declare zerobase;

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
plot StDevLevel = numDev;

RelVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelVol.SetLineWeight(3);
RelVol.DefineColor("Above", GetColor(0));
RelVol.DefineColor("Below", GetColor(2));
RelVol.AssignValueColor(if RelVol >= numDev then RelVol.Color("Above") else RelVol.Color("Below"));
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);
 

mc01439

Well-known member
2019 Donor
VIP
Try the following - I also added a label for you. If you do not want the label just pick "no" under input.

http://tos.mx/k9BGx4i


Code:
#Alert
def alerttrigger1 = volume crosses above numDev;

input alerttext = "!!!!! Volume crosses Number Deviation  !!!!!";

input UseAlerts = {false, default true};

input AlertType = {default "BAR", "ONCE", "TICK"};

def at = AlertType;

input AlertSound = {"Chimes", "Ring", default "Bell", "NoSound", "Ding"};

Alert (alerttrigger1 and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);

#Label
input label = yes;

def nDev = alerttrigger1;

AddLabel(label and nDev, " Deviation > Input ", color.PLUM);
 

ronl1975

New member
Try the following - I also added a label for you. If you do not want the label just pick "no" under input.

http://tos.mx/k9BGx4i


Code:
#Alert
def alerttrigger1 = volume crosses above numDev;

input alerttext = "!!!!! Volume crosses Number Deviation  !!!!!";

input UseAlerts = {false, default true};

input AlertType = {default "BAR", "ONCE", "TICK"};

def at = AlertType;

input AlertSound = {"Chimes", "Ring", default "Bell", "NoSound", "Ding"};

Alert (alerttrigger1 and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);

#Label
input label = yes;

def nDev = alerttrigger1;

AddLabel(label and nDev, " Deviation > Input ", color.PLUM);

@mc01439

Thanks again. I've tested this with /NQ tonight and it isn't working :( . I've switch the code around and tried other code after reading the "Thinkscript Learning Center" with no luck. I've been trying to get this one thing right for a month and figured I'd find a group and ask folks that know more than me -because I'm obviously not a coder. I am pleased that I've found somebody that could offer some help as I posted the same question 6 hours ago and didn't get an answer - Thus the reason why I posted again. I'm not trying to get on here to mooch off others. I'm not trying to have poor forum etiquette. I just figured that maybe this could be easy for somebody that could help. Therefore, I thank you for your time and effort in attempting to get this 1 alert right for me. I'll keep searching. (Sorry for the bold font, I do not know why it won't "unbold", sorry for the repost and sorry for the stupid questions)​

 

mc01439

Well-known member
2019 Donor
VIP

@mc01439

Thanks again. I've tested this with /NQ tonight and it isn't working :( . I've switch the code around and tried other code after reading the "Thinkscript Learning Center" with no luck. I've been trying to get this one thing right for a month and figured I'd find a group and ask folks that know more than me -because I'm obviously not a coder. I am pleased that I've found somebody that could offer some help as I posted the same question 6 hours ago and didn't get an answer - Thus the reason why I posted again. I'm not trying to get on here to mooch off others. I'm not trying to have poor forum etiquette. I just figured that maybe this could be easy for somebody that could help. Therefore, I thank you for your time and effort in attempting to get this 1 alert right for me. I'll keep searching. (Sorry for the bold font, I do not know why it won't "unbold", sorry for the repost and sorry for the stupid questions)​

Sorry my mistake. I tested with the corrections I made, it works now. Just change the "input numDev" to the number you want.

http://tos.mx/jDKQojo
 

Similar threads

Top