Bollinger Bands Format, Watchlist, Label, Scan For ThinkOrSwim

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

@mourningwood4521 If it's not listed under the conditional wizard, most likely, ThinkorSwim won't let you run the scanner. Like the example you stated, using the "last" price in the scanner's code will not work because ToS' scan system does not support it. Feel free to test out different price types.
 
@mourningwood4521 If it's not listed under the conditional wizard, most likely, ThinkorSwim won't let you run the scanner. Like the example you stated, using the "last" price in the scanner's code will not work because ToS' scan system does not support it. Feel free to test out different price types.
I posted corrected code... For scans Close serves as Last for active bars/candles... Then he failed to notice that hlc3 is in the Price Type list... I have faith that with practice he'll get up to speed on coding Thinkscript...
 
@mourningwood4521 What do you think hlc3 is...??? The code I posted should work... Did you see the code I posted above...???
yeah I saw the code you posted and thank you for that.


I thought high low close 3 is the average of the 3 values. And a hlc3 on a daily chart would be from the day before wouldn't it? because you can't have a close if the market is still open. Unless I'm misunderstanding something and if you say the close, then that would be the close of the most recent bar at the type the operation is being executed.
 
I posted corrected code... For scans Close serves as Last for active bars/candles... Then he failed to notice that hlc3 is in the Price Type list... I have faith that with practice he'll get up to speed on coding Thinkscript...
not hlc3 im sorry that was error in my typing, I was multi tasking.

I meant to type open. so it should read: DO you think it would be possible to make the system find the (high + low + open) divided by 3? just cuz I don't see that option incorporated into the system.


okay now I understand that close would be the last. " For scans Close serves as Last for active bars/candles".

Why did thinkscript not take plot Condition today but every other plot condition I've done has accepted that term?
 
yeah I saw the code you posted and thank you for that.


I thought high low close 3 is the average of the 3 values. And a hlc3 on a daily chart would be from the day before wouldn't it? because you can't have a close if the market is still open. Unless I'm misunderstanding something and if you say the close, then that would be the close of the most recent bar at the type the operation is being executed.
hlc3 will always use the previous candle/bar, not the previous day - unless you set aggregation to day or use day as your timeframe...

hlc3 is in the Price Type list or can be used in Thinkscript...
 
I posted corrected code... For scans Close serves as Last for active bars/candles... Then he failed to notice that hlc3 is in the Price Type list... I have faith that with practice he'll get up to speed on coding Thinkscript...
I promise I'm not dumb :p. I just screwup my words from time to time.
 
Here is a slight tweak that makes the clouds translucent so they don't over take the screen.
Code:
#
# Double Bollinger Bands with translucent clouds.
# Assembled by BenTen at useThinkScript.com
# Based on request/concept of @aliikhatami
# Slightly touched up by some spitball no name.

input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn1 = -1.0;
input Num_Dev_up1 = 1.0;
input Num_Dev_Dn3 = -3.0;
input Num_Dev_up3 = 3.0;
input averageType = AverageType.EXPONENTIAL;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand1 = MidLine + num_Dev_Dn1 * sDev;
plot UpperBand1 = MidLine + num_Dev_Up1 * sDev;
plot UpperBand3 = MidLine + num_Dev_Up3 * sDev;
plot LowerBand3 = MidLine + num_Dev_Dn3 * sDev;

AddCloud(UpperBand1, UpperBand3, createcolor(000, 090, 000), createcolor (000, 090, 000));

AddCloud(LowerBand1, LowerBand3, createcolor(100, 000, 000), createcolor (100, 000, 000));
 
Hello everyone, First of all, thank you for your response and here is the help that I need:

Can some one help me with an indicator which tells me when "5 minute lower Bollinger Band" is touching "Daily lower Bollinger Band".
 
put it on a 5 minute time frame and it should work

Code:
# DG_MTFBollingerBands
# Paints Bollinger Bands from higher time period
# onto current time period
#German BUrrito
# Copyright (c) 2017 Daniel Granville
declare lower;
input timeframe = AggregationPeriod.DAY;
input period = 20;
input std = 2.0;
input moving_average_type = {default SMA, EMA};

def data = close(period = timeframe);
def band = StDev(data, period);

plot MidLine;

switch(moving_average_type) {
    case SMA:
        MidLine = Average(data, period);
    case EMA:
        MidLine = ExpAverage(data, period);
}

plot BBandTop = MidLine + band;

plot BBandBot = MidLine - band;


#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

input price2 = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = price2[-displace], length = length);

plot MidLine2 = MovingAverage(averageType, data = price2[-displace], length = length);
plot LowerBand = MidLine2 + num_Dev_Dn * sDev;
plot UpperBand = MidLine2 + num_Dev_Up * sDev;

LowerBand.SetDefaultColor(GetColor(0));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));



def U = LowerBand <=  BBandBot ;
def D = lowerband >=  BBandBot;



AddLabel( U, " down " , Color.red);
AddLabel( D, " up " , Color.green);
 
Thank you so much Germanburrito and it is really helpful.
However, my expectation was to have it as a scan and I am getting error while trying to paste this code (by removing addlabel kind of statements in scan. Could you be able to help me here please?
All I need is - at this moment, I would like to know the tickers where the price is below 5 mins Lower Bollinger band and daily Bollinger Band levels.
I am getting error as "Secondary period not allowed" while giving this in scan.
Many thanks in advance!

 
Thanks for the quick response but it seems I am still getting the same error. Scan is working good when Day is selected (but obviously resulting no rows - which is expected), but when changing it to 5 minutes, I am getting the error as "Secondary period not allowed: Day" because of Day is being considered within the script.

Can you please help me?
 
So I take 2 studies and overlap them. I set one cloud at 1 and 3 Std Dev and the second cloud I set at 2 and 3 Std Dev. Right now I only use it on my daily chart with 20 SMA.

qoxATQh.png
 
You are in luck. I had to pay someone to code this. It's very helpful for me.

Good luck!

Code:
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -1.0;
input Num_Dev_up = 1.0;
input averageType = AverageType.simple;

def sDev = stdev(data = price[-displace], length = length);

def MidLine = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;
def aboveUpperBand = close > UpperBand;
def almostToUpperBand = close < UpperBand and close > UpperBand ;

UpperBand.AssignValueColor(if aboveUpperBand or almostToUpperBand then Color.BLACK else Color.WHITE);
AssignBackgroundColor(if aboveUpperBand then Color.GREEN else if almostToUpperBand then Color.YELLOW else Color.BLACK);

You might check out post #5 here as well which is even more functionality.

I think what someone posted here is even better (post #5) https://usethinkscript.com/threads/colored-candles-based-on-bollinger-bands.1265/

Cheers!
 
@Tradarr This probably belongs in its own thread as it would be nice to keep this thread related to the VOLATILITY BASED ENVELOPES... although i know it is based of creator Metastocks, they are all different studies and ideas. To answer your question.. your requested conversion would be difficult to convert without the base code used in the references that you posted in your scan. In other words your syntaxes are referencing other syntaxes and without those syntaxes its difficult to code.
I found the TOS shared item for the strategy, it is a strategy and not a shared scan so it would need to be converted. I found a strategy to study conversion example guide and will try. The current strategy script is below and the conversion example follows if someone else wants to try also:

Code:
#Detecting Swings Strategy Start
input swingType = {default "Pivot High-Low", "Bollinger Bands Crossover", "RSI Crossover", "RSI + Higher Low / Lower High"};
input length = 12;
input exitLength = 20;
input deviations = 2.0;
input overbought = 60;
input oversold = 40;
input averageType = AverageType.SIMPLE;

def rsi = reference RSI(length = length, "average type" = averageType);
def bbUpperBand = MovingAverage(averageType, close, length) + deviations * StDev(close, length);
def bbLowerBand = MovingAverage(averageType, close, length) - deviations * StDev(close, length);

def upSwing;
def downSwing;
switch (swingType) {
case "Pivot High-Low":
    upSwing = low[1] < low[2] and low[1] < low;
    downSwing = high[1] > high[2] and high[1] > high;
case "Bollinger Bands Crossover":
    upSwing = close crosses above bbLowerBand;
    downSwing = close crosses below bbUpperBand;
case "RSI Crossover":
    upSwing = rsi crosses above oversold;
    downSwing = rsi crosses below overbought;
case "RSI + Higher Low / Lower High":
    upSwing = rsi < oversold and low > low[1];
    downSwing = rsi > overbought and high < high[1];
}

def entryPrice = EntryPrice();
def afterEntryCount = if IsNaN(entryPrice[1]) and !IsNaN(entryPrice) then 1 else if !IsNaN(entryPrice) then afterEntryCount[1] + 1 else Double.NaN;

AddOrder(OrderType.BUY_TO_OPEN, upSwing, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "PriceSwingLE");
AddOrder(OrderType.SELL_TO_OPEN, downSwing, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "PriceSwingSE");
AddOrder(OrderType.BUY_TO_CLOSE, afterEntryCount > exitLength, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "PriceSwingLX");
AddOrder(OrderType.SELL_TO_CLOSE, afterEntryCount > exitLength, tickcolor = GetColor(3), arrowcolor = GetColor(3), name = "PriceSwingSX");
#Startegy End

Conversion Example

Convert Strategy To Study For Alerts Example
https://www.hahn-tech.com/ans/generate-alerts-from-macdstrat-chart-strategy/

First, we'll show the full code that is copied directly from the built-in chart strategy named MACDStrat:

Code:
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
def diff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
AddOrder(OrderType.BUY_AUTO, diff crosses above 0, tickColor = GetColor(0), arrowColor = GetColor(0), name = "MACDStratLE");
AddOrder(OrderType.SELL_AUTO, diff crosses below 0, tickColor = GetColor(1), arrowColor = GetColor(1), name = "MACDStratSE");

Next, well convert this to a chart study by removing the AddOrder() statements. For the alerts, we simply add two Alert() statements to replace the AddOrder() statements. We will retain the true/false condition of the AddOrder() statements which are used to plot the theoretical buys and sells on the chart.

Code:
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
def diff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
Alert(diff crosses above 0, "MACD Hist Cross Above", Alert.BAR, Sound.RING);
Alert(diff crosses below 0, "MACD Hist Cross Below", Alert.BAR, Sound.RING);
AddLabel(yes, "", Color.BLACK);

Sorry but I can't figure out how to set up the plots for scan usage.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
484 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