Watchlist column: 3X StdDevChannel Labels

JiminySmanchez

New member
Hi everyone! First I want to say thank you to everyone here, as this site has been a huge help to me on my learning journey and I'm super grateful for this community already.

Screen+Shot+2022-02-02+at+7.18.00+PM.png


I have been working on the watchlist column indicator shown at the right in the image above. This indicator should show me when the close is greater than or equal to the upper stdDevs and when close is less than or equal to the lower StdDevs (i.e. N/A for inside first dev channel, UP1 for >= first stdDev, UP2 for >= second stdDev...). It should follow the below example on the chart.

Screen+Shot+2022-02-02+at+7.32.48+PM.png


My biggest issue now is getting it to work within my preferred timeframe, which would be Today: 1m. Ideally, I would like to see what the code would look like both with and without PM included (I like to use PM for the first 30 minutes of the day and only regular trading hours during the remainder of the day). If the code can be written to include both timeframes that would be AMAZING, and would prevent me from needing to switch back and forth, however, I'm not opposed to making the switch if needed and understand I may need to considering the "Include Extended-Hours Trading session" checkbox.

The code I have so far is:
Code:
def price = close;

def regression;
    regression = inertiaAll(price);
def stdDeviation;
    stdDeviation = stDevAll(price);


# First StdDev
input dev1 = 1.0;
def upperLine1 = regression + dev1 * stdDeviation;
def lowerLine1 = regression - dev1 * stdDeviation;


# Second StdDev
input dev2 = 2.0;
def upperLine2 = regression + dev2 * stdDeviation;
def lowerLine2 = regression - dev2 * stdDeviation;


# Third StdDev
input dev3 = 3.0;
def upperLine3 = regression + dev3 * stdDeviation;
def lowerLine3 = regression - dev3 * stdDeviation;


# Plot
def status = if price is greater than or equal to upperLine3 then 3
else if price is greater than or equal to upperLine2 then 2
else if price is greater than or equal to upperLine1 then 1
else if price is less than or equal to lowerLine3 then -3
else if price is less than or equal to lowerLine2 then -2
else if price is less than or equal to lowerLine1 then -1
else Double.NaN;

AddLabel(yes,
if status == 3 then "UP3"
else if status == 2 then "UP2"
else if status == 1 then "UP1"
else if status == -3 then "DN3"
else if status == -2 then "DN2"
else if status == -1 then "DN1"
else "N/A",
if status <> 0 then color.Black
else color.White);

AssignBackgroundColor(
if status == 1 then color.YELLOW
else if status == 2 then color.ORANGE
else if status == 3 then color.DOWNTICK
else if status == -1 then color.CYAN
else if status == -2 then color.LIGHT_GREEN
else if status == -3 then color.UPTICK
else color.CURRENT);

BONUS: If we can update the code to use Inerita(); and stDev(); instead of the All variants included in the regression and stdDeviation definitions, we should be able to remove the complex script warning from this code. The issue I've face when challenging this is that length needs to be a constant, so defining length has been unsuccessful for me.

Again, thank you all for any help you're able to provide!
 
So I ended up writing the script with a length of 390 to calculate for a 24 hour session without PM/AH on the 1min chart. I don't think it's perfect, but it's working well enough to be effective in my book:
Code:
input price = close;
input len = 390;

def regression;
    regression = Inertia(price, len);
def stdDeviation;
    stdDeviation = stDev(price, len);


# First StdDev
input dev1 = 1.0;
def upperLine1 = regression + dev1 * stdDeviation;
def lowerLine1 = regression - dev1 * stdDeviation;


# Second StdDev
input dev2 = 2.0;
def upperLine2 = regression + dev2 * stdDeviation;
def lowerLine2 = regression - dev2 * stdDeviation;


# Third StdDev
input dev3 = 3.0;
def upperLine3 = regression + dev3 * stdDeviation;
def lowerLine3 = regression - dev3 * stdDeviation;


# Plot
def status = if price is greater than or equal to upperLine3 then 3
else if price is greater than or equal to upperLine2 then 2
else if price is greater than or equal to upperLine1 then 1
else if price is less than or equal to lowerLine3 then -3
else if price is less than or equal to lowerLine2 then -2
else if price is less than or equal to lowerLine1 then -1
else Double.NaN;

AddLabel(yes,
if status == 3 then "UP3"
else if status == 2 then "UP2"
else if status == 1 then "UP1"
else if status == -3 then "DN3"
else if status == -2 then "DN2"
else if status == -1 then "DN1"
else "N/A",
if status <> 0 then color.Black
else color.White);

AssignBackgroundColor(
if status == 1 then createColor(225,0,0)
else if status == 2 then createColor(175,0,0)
else if status == 3 then createColor(100,0,0)
else if status == -1 then createColor(0,225,0)
else if status == -2 then createColor(0,175,0)
else if status == -3 then createColor(0,100,0)
else color.CURRENT);
 

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
489 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