Thinkscript Custom Standard Deviation Labels

shineeey

New member
Would like to have the bars on the chart that shows the average SD per day, like in this picture.

r2OF4x6.png


Any help would be greatly appreciated.
 

thinkscriptnewb

New member
I would like to get the standard deviation I have on my spreadsheet on to TOS to help in trading options. Personally, I try to stay 1-2 standard deviations away from the current price. If anyone has any interest in coding this, it would be much appreciated. I thank you in advance!

I was hoping to display +/-1 and +/-2 standard deviations on the charts. It would be similar to this post below, however, I use a different method to calculate standard deviation which I find more reliable.

I use the equation below for 1 standard deviation. For 2 standard deviations, I just multiply by 2.

Current Stock Price * [(implied volatility + historical volatility)/2] * square root of the "number of days" / square root of 365

I imagine the variables that would need to be inputed in the settings would be "number of days" which would range from 1-30.

The labels I'd ideally want are below. This is an example using a stock with a price of 781, with implied volatility + historical volatility/2 = .45, which was set for "number of days" = 5

1SD: 41 // 2SD: 82 // -2SD: 699 // -1SD: 740 // +1SD: 822 // +2SD: 863
 

rad14733

Well-known member
VIP
@thinkscriptnewb Have you done any research here to see whether any code already exists that does what you expect, or can be modified to do so...??? Due diligence and learning to do for yourself is an expectation here... I understand that you are new and may not be fully up to speed here but we normally don't just bang out code upon request... We're willing to help those who are willing to help themselves... There are plenty of sites out there where you can pay for pre-made indicators but we don't feel that people should have to pay for what is freely available... Most of the code you find here was written to serve someone's own needs and then shared freely... But it isn't just written upon request... Thinkscript isn't all that hard compared to some other languages and we've had members who have never coded previously learn rapidly... Be a self-starter rather than relying on others to write code that controls the future of your money...
 

zamanib

New member
I need help in coding custom quotes column for my watchlist/marketwatch
Indicator Standard deviation channel -- I want to create 3 custom column for my watchlist/marketwatch
I try to edit the indicator code and add label and color
I only want to see the lower channel to turn green - else grey once price close below or at standardDev 2 (lower line) I will do it 3 times just edit the setting from StandDev to 3 and 4

Here is original code-

input price = close;
input deviations = 2.0;
input fullRange = Yes;
input length = 21;

def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(price);
stdDeviation = stdevAll(price);
} else {
regression = InertiaAll(price, length);
stdDeviation = stdevAll(price, length);
}

plot UpperLine = regression + deviations * stdDeviation;
plot MiddleLine = regression;
plot LowerLine = regression - deviations * stdDeviation;

UpperLine.SetDefaultColor(GetColor(8));
MiddleLine.SetDefaultColor(GetColor(8));
LowerLine.SetDefaultColor(GetColor(8));

---------------------------------------------------------
I modify to for custom column --- NEED HELP TO CORRECT IT
THIS WHAT I HAVE DONE

input price = close;
input deviations = 1.0;
input fullRange = Yes;
input length = 21;

def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(price);
stdDeviation = stdevAll(price);
} else {
regression = InertiaAll(price, length);
stdDeviation = stdevAll(price, length);
}

def LowerLine = regression - deviations * stdDeviation;



plot LowerLineBelow = if close < LowerLine then 1 else 0;

AssignBackgroundColor (if LowerLineBelow >= 1 then color.DARK_GREEN else color.LIGHT_GRAY);
 

Similar threads

Top