@mourningwood4521 What do you think hlc3 is...??? The code I posted should work... Did you see the code I posted above...???
Last edited:
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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 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.
yeah I saw the code you posted and thank you for that.@mourningwood4521 What do you think hlc3 is...??? The code I posted should work... Did you see the code I posted above...???
not hlc3 im sorry that was error in my typing, I was multi tasking.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...
hlc3 will always use the previous candle/bar, not the previous day - unless you set aggregation to day or use day as your timeframe...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 promise I'm not dumb . I just screwup my words from time to time.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...
#
# 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));
# 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);
Aahhh... thank you for saving my future time BenTen from breaking my head on how to do it. .@sritrade Refer to this post: https://usethinkscript.com/threads/fix-secondary-period-not-allowed-in-thinkorswim-scanner.927/
Simply put, what you're trying to do is not possible because ToS scanner does not allow secondary aggregation period in their scanner.
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);
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:@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.
#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
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");
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);
Nevermind i used your screenshot here to hack it i think. You're the man BenTen thanks!No need to make it complicated. Use the conditional wizard.
Start a new thread and receive assistance from our community.
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.
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.