Thepremier
New member
Can someone help me with a script for an outside day and and an inside day? I would like to create a scan for them.
Last edited:
@mosog
You put the conditions inside the addchartbubble statement as the first parameter to determine whether or not the bubble is displayed.
Code:input buyLevel = 0.20; input sellLevel = 0.70; def prevHigh = high[2]; def prevLow = low[2]; def prevClose = close [2]; def prevOpen = open [2]; def insideBar = high [1] < high [2] and low [1] > low [2]; def range1 = close [1] - low [1]; def range2 = high [1] - low [1]; def IBS = range1 / range2; def longSignal = IBS < 0.20; def shortSignal = IBS > 0.70; AddChartBubble(insideBar and longSignal, high, IBS, color.green, yes); AddChartBubble(insideBar and shortSignal, high, IBS, color.red, yes);
@mosog
AssignPriceColor(if insideBar and longSignal then Color.BLUE else Color.CURRENT);
It colors the candle after the inside candle, how do I tell it to color the inside candle?@mosog
AssignPriceColor(if insideBar and longSignal then Color.BLUE else Color.CURRENT);
of course, so simple it just didn't compute in my head. Thinkscript is different from regular programming, sometimes so simple its complex@mosog
Change the AssignValue line to:
AssignPriceColor(if insideBar[-1] and longSignal[-1] then Color.BLUE else Color.CURRENT);
Svanoy:@mosog
Change the AssignValue line to:
AssignPriceColor(if insideBar[-1] and longSignal[-1] then Color.BLUE else Color.CURRENT);
Svanoy:
It seems like my condition for putting the ChartBubble doesn't really do the right thing, here is the complete code and a screenshot showing that the ChartBubble shows up when the conditions are not met, i.e. when IBS is not < 0.20 or > 0.70. I'm trying to figure it out but if you can spot it fast then I would appreciate that.
input buyLevel = 0.20;
input sellLevel = 0.70;
def stackedUp = MovAvgExponential("length" = 8)."AvgExp" is greater than MovAvgExponential("length" = 21)."AvgExp" and MovAvgExponential("length" = 21)."AvgExp" is greater than MovAvgExponential("length" = 34)."AvgExp" and MovAvgExponential("length" = 34)."AvgExp" is greater than MovAvgExponential("length" = 55)."AvgExp" and MovAvgExponential("length" = 55)."AvgExp" is greater than MovAvgExponential("length" = 89)."AvgExp";
def stackedDn = MovAvgExponential("length" = 8)."AvgExp" is less than MovAvgExponential("length" = 21)."AvgExp"
and MovAvgExponential("length" = 21)."AvgExp" is less than MovAvgExponential("length" = 34)."AvgExp"
and MovAvgExponential("length" = 34)."AvgExp" is less than MovAvgExponential("length" = 55)."AvgExp"
and MovAvgExponential("length" = 55)."AvgExp" is less than MovAvgExponential("length" = 89)."AvgExp";
def prevHigh = high[2];
def prevLow = low[2];
def prevClose = close [2];
def prevOpen = open [2];
def insideBar = high [1] < high [2] and low [1] > low [2];
def range1 = close [1] - low [1];
def range2 = high [1] - low [1];
def IBS = range1 / range2;
def longSignal = IBS < 0.20;
def shortSignal = IBS > 0.70;
AddChartBubble(insideBar[-1] and longSignal[-1] and stackedUp, high[1], IBS, color.green, yes);
AddChartBubble(insideBar[-1] and shortSignal[-1] and stackedDn, high[1], IBS, color.red, yes);
AssignPriceColor(if insideBar[-1] then Color.Yellow else Color.CURRENT);
@om4
I made no change to your original code for defining an inside bar.
I only looked at high/low ranges of bars your code triggered on and provided an additional filter for minimum percentage.
I am not seeing a triggered candle at 1:45 on LC with the code in my last post.
# Generation time: 2020-09-26T16:01:42.946Z
input timeFrame = {default DAY, WEEK, MONTH};
def cap = GetAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7);
case MONTH:
periodIndx = RoundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def ema = MovAvgExponential(close, 9, 0, no);
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def PatternPlot =
((Sum(IsUp, 1)[2] >= 0)) and
((Sum(IsUp, 1)[1] >= 0)) and
((Sum(IsUp, 1)[0] >= 0)) and
Lowest(low[2], 1) < Lowest(low[1], 1) and
Highest(high[2], 1) > Highest(high[1], 1) and
Highest(high[1], 1) > Highest(high[0], 1) and
Lowest(low[1], 1) < Lowest(low[0], 1) ;
#patternPlot.setPaintingStrategy(paintingStrategy.ARROW_UP);
def inside = high < high[1] and low > low[1];
def cross = high > price and low < price;
def con = inside [1] and cross [1];#PatternPlot and close crosses ema or patternPlot and close crosses price;
###########################################################################################################################
def Con_High = if con then high else Con_High[1];
def Con_Low = if con then low else Con_Low[1];
def Con_High_Low_Range = AbsValue(Con_High - Con_Low);
input Start_Bar_Time = 0930;
def Start_Bar_High = If secondsFromTime(Start_Bar_Time)==(GetAggregationPeriod()/1000) then high[1] else Start_Bar_High[1];
def Start_Bar_Low = If secondsFromTime(Start_Bar_Time)==(GetAggregationPeriod()/1000) then low[1] else Start_Bar_Low[1];
def Start_Bar_High_Low_Range = AbsValue(Start_Bar_High - Start_Bar_Low);
def Percent_Check = RoundDown((Con_High_Low_Range/Start_Bar_High_Low_Range) * 100,1) >= 40;
AddChartBubble(Con[-1] and Percent_Check[-1],high,RoundDown((Con_High_Low_Range/Start_Bar_High_Low_Range) * 100,1),color.white);
###########################################################################################################################
plot CONDITION = if con[-1] and Percent_Check[-1] then low else Double.NaN;
CONDITION.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
CONDITION.AssignValueColor(color.WHITE);
CONDITION.SetLineWeight(4);
Alert(con, "ALERT", Alert.ONCE, Sound.Ding);
AssignBackgroundColor(if CONDITION then Color.PLUM else Color.BLACK);
is there a way to have this work on the 1hr timeframe starting at 9:30am market open? i'm trying to run it as a scan and its not working at market open.@om4
Adjusted plot location.
Code:# Generation time: 2020-09-26T16:01:42.946Z input timeFrame = {default DAY, WEEK, MONTH}; def cap = GetAggregationPeriod(); def errorInAggregation = timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH; Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period"); def yyyyMmDd = GetYYYYMMDD(); def periodIndx; switch (timeFrame) { case DAY: periodIndx = yyyyMmDd; case WEEK: periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7); case MONTH: periodIndx = RoundDown(yyyyMmDd / 100, 0); } def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes); def volumeSum; def volumeVwapSum; def volumeVwap2Sum; if (isPeriodRolled) { volumeSum = volume; volumeVwapSum = volume * vwap; volumeVwap2Sum = volume * Sqr(vwap); } else { volumeSum = CompoundValue(1, volumeSum[1] + volume, volume); volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap); volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap)); } def price = volumeVwapSum / volumeSum; def ema = MovAvgExponential(close, 9, 0, no); def IsUp = close > open; def IsDown = close < open; def IsDoji = IsDoji(); def avgRange = 0.05 * Average(high - low, 20); def PatternPlot = ((Sum(IsUp, 1)[2] >= 0)) and ((Sum(IsUp, 1)[1] >= 0)) and ((Sum(IsUp, 1)[0] >= 0)) and Lowest(low[2], 1) < Lowest(low[1], 1) and Highest(high[2], 1) > Highest(high[1], 1) and Highest(high[1], 1) > Highest(high[0], 1) and Lowest(low[1], 1) < Lowest(low[0], 1) ; #patternPlot.setPaintingStrategy(paintingStrategy.ARROW_UP); def inside = high < high[1] and low > low[1]; def cross = high > price and low < price; def con = inside [1] and cross [1];#PatternPlot and close crosses ema or patternPlot and close crosses price; ########################################################################################################################### def Con_High = if con then high else Con_High[1]; def Con_Low = if con then low else Con_Low[1]; def Con_High_Low_Range = AbsValue(Con_High - Con_Low); input Start_Bar_Time = 0930; def Start_Bar_High = If secondsFromTime(Start_Bar_Time)==(GetAggregationPeriod()/1000) then high[1] else Start_Bar_High[1]; def Start_Bar_Low = If secondsFromTime(Start_Bar_Time)==(GetAggregationPeriod()/1000) then low[1] else Start_Bar_Low[1]; def Start_Bar_High_Low_Range = AbsValue(Start_Bar_High - Start_Bar_Low); def Percent_Check = RoundDown((Con_High_Low_Range/Start_Bar_High_Low_Range) * 100,1) >= 40; AddChartBubble(Con[-1] and Percent_Check[-1],high,RoundDown((Con_High_Low_Range/Start_Bar_High_Low_Range) * 100,1),color.white); ########################################################################################################################### plot CONDITION = if con[-1] and Percent_Check[-1] then low else Double.NaN; CONDITION.SetPaintingStrategy(PaintingStrategy.ARROW_UP); CONDITION.AssignValueColor(color.WHITE); CONDITION.SetLineWeight(4); Alert(con, "ALERT", Alert.ONCE, Sound.Ding); AssignBackgroundColor(if CONDITION then Color.PLUM else Color.BLACK);
You cannot have a secondary aggregation in a scanis there a way to have this work on the 1hr timeframe starting at 9:30am market open? i'm trying to run it as a scan and its not working at market open.
I'm trying to figure out two different studies/indicators
Inside/Outside Bar
-when a Inside bar is formed it turns Orange with an option to have the #1 show up below or above the bar
-when an outside bar shows it turns Purple with an option to have the #3 show up below or above the bar
Daily ATR
Is there a way to make a script that takes the Daily ATR and then at market open it automatically plots data to show where the top and bottom would be based on ATR
then as the stock prices moves up or down the top or bottom trails showing the possible range of a stock if it holds to daily ATR?
Here is a chart with both scripts showing The red clouds indicate that the Daily ATR is greater than the Range (High-Low) during regular trading hours and green otherwise
Here is the inside/outside script
Here is the ATR scxript with various options to display the data.Ruby:def insideBar = if High < High[1] and Low > Low[1] then 1 else Double.NaN; def outsidebar = if high > high[1] and low < low[1] then 1 else Double.NaN; input pricecolor = yes; AssignPriceColor(if !pricecolor then color.current else if !isNaN(insideBar) then color.orange else if !isnan(outsideBar) then color.magenta else color.current); input showbubbles = yes; addchartbubble(showbubbles and insidebar, high, "#1", color.orange); addchartbubble(showbubbles and outsidebar, high, "#3", color.magenta);
Ruby:input agg = AggregationPeriod.DAY; def DATR = Average(TrueRange(high(period = agg), close(period = agg), low(period = agg)), 14); def start = GetTime() crosses above RegularTradingStart(GetYYYYMMDD()); def rthrs = between(gettime(), regularTradingStart(getyyyYMMDD()), regularTradingEnd(getyyyYMMDD())); def o = if start then open else o[1]; def h = if start then high else if rthrs then Max(high, h[1]) else h[1]; def l = if start then low else if rthrs then Min(low, l[1]) else l[1]; plot hday = h; hday.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); plot lday = l; lday.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); def range = DATR - (h - l); def rangeopen = if range > 0 then range else 0; def datrh = if (h - l) crosses above DATR then l+datr else datrh[1]; plot datrhigh = if h < h + (rangeopen / 2) then h + (rangeopen / 2) else datrh; plot datrlow = if l > l - (rangeopen / 2) then l - (rangeopen / 2) else l; input showclouds = yes; addcloud(hday, datrhigh, color.green, color.red); addcloud(lday, datrlow, color.red, color.green); input showlabels = yes; addlabel(showlabels, "DATR: " + astext(DATR) + " H-L: " + astext(h-l), color.yellow); addlabel(showlabels, "Diff :" + astext(range), if range < 0 then color.green else color.light_red); input showbubbles = yes; input bubblemover = 3; def bm = bubblemover; def bm1 = bm + 1; addchartbubble(showbubbles and isnan(close[bm]) and !isnan(close[bm1]), datrhigh, "ATR High \n" + astext(datrhigh), datrhigh.takevalueColor()); addchartbubble(showbubbles and isnan(close[bm]) and !isnan(close[bm1]), datrlow, "ATR low\n" + astext(datrlow), datrlow.takevalueColor()); addchartbubble(showbubbles and isnan(close[bm]) and !isnan(close[bm1]), hday, "High\n" + astext(hday), hday.takevalueColor()); addchartbubble(showbubbles and isnan(close[bm]) and !isnan(close[bm1]), lday, "Low\n" + astext(lday), lday.takevalueColor()); ;
I have a code for a inside bar and outside bar I would like the script to put a dot on the candle instead of turning it a color.
Also a line at the high and the low of the inside bar or outside bar would be great.
If the script finds a double inside bar I would like an alert and a different color dot.
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
def open_time = 0930;
def closing_time = 1600;
# hal_inside hal_outside
def price = close;
def inside = high < high[1] and low > low[1];
def outside = high > high[1] and low < low[1];
AssignPriceColor(if inside
then Color.BLUE
else Color.CURRENT);
AssignPriceColor(if outside
then Color.white
else Color.CURRENT);
def double_inside = high[1] < high[2] && Low[1] > Low[2] && high[2] < high[3] && Low[2] >Low[3];
I have a code for a inside bar and outside bar I would like the script to put a dot on the candle instead of turning it a color.
Also a line at the high and the low of the inside bar or outside bar would be great.
If the script finds a double inside bar I would like an alert and a different color dot.
#
# TD Ameritrade IP Company, Inc. (c) 2007-2022
#
def open_time = 0930;
def closing_time = 1600;
def price = close;
def inside = high < high[1] and low > low[1];
def outside = high > high[1] and low < low[1];
AssignPriceColor(if inside
then Color.BLUE
else Color.CURRENT);
AssignPriceColor(if outside
then Color.white
else Color.CURRENT);
def double_inside = high[1] < high[2] && Low[1] > Low[2] && high[2] < high[3] && Low[2] >Low[3];
# inside_outside_01
# https://usethinkscript.com/threads/inside-outside-bar.12396/
# inside bar and outside bar code,
def na = double.nan;
def price = close;
# inside bar - a big candle and smaller candles after it
def inside1 = high > high[-1] and low < low[-1];
def inside2 = inside1 and high > high[-2] and low < low[-2];
# outside bar - a big candle with smaller candles before it
def outside1 = high > high[1] and low < low[1];
def outside2 = outside1 and high > high[2] and low < low[2];
# remove small insides within larger insides
def insidebar = if inside2[1] then 0 else if inside2 then 2 else if inside1 then 1 else 0;
# remove small outsides within larger outsides
def outsidebar = if outside2[-1] then 0 else if outside2 then 2 else if outside1 then 1 else 0;
input show_small_arrows = yes;
# inside shapes above candles, up wedge
plot zin = if !show_small_arrows then 0 else insidebar;
zin.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zin.SetDefaultColor(Color.cyan);
zin.setlineweight(2);
zin.hidebubble();
# outside shapes below candles, down wedge
plot zout = if !show_small_arrows then 0 else outsidebar;
zout.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zout.SetDefaultColor(Color.yellow);
zout.setlineweight(2);
zout.hidebubble();
plot inside_top =
if insidebar[0] > 0 then high[0]
else if insidebar[1] > 0 then high[1]
else if insidebar[2] > 1 then high[2]
else na;
plot inside_bot =
if insidebar[0] > 0 then low[0]
else if insidebar[1] > 0 then low[1]
else if insidebar[2] > 1 then low[2]
else na;
inside_top.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_top.SetDefaultColor(Color.cyan);
inside_top.hidebubble();
inside_bot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
inside_bot.SetDefaultColor(Color.cyan);
inside_bot.hidebubble();
plot outside_top =
if outsidebar[0] > 0 then high[0]
else if outsidebar[-1] > 0 then high[-1]
else if outsidebar[-2] > 1 then high[-2]
else na;
plot outside_bot =
if outsidebar[0] > 0 then low[0]
else if outsidebar[-1] > 0 then low[-1]
else if outsidebar[-2] > 1 then low[-2]
else na;
outside_top.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_top.SetDefaultColor(Color.yellow);
outside_top.hidebubble();
outside_bot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
outside_bot.SetDefaultColor(Color.yellow);
outside_bot.hidebubble();
input show_double_shapes = yes;
def vert = 0.006;
#plot y1 = if inside1 then high*1.01 else na;
plot y1 = if show_double_shapes and inside2 then high*(1+vert) else na;
y1.SetPaintingStrategy(PaintingStrategy.triangles);
y1.SetDefaultColor(Color.cyan);
y1.setlineweight(4);
y1.hidebubble();
#plot y2 = if inside2 then high*1.02 else na;
plot y2 = if show_double_shapes and outside2 then low*(1-vert) else na;
y2.SetPaintingStrategy(PaintingStrategy.triangles);
y2.SetDefaultColor(Color.yellow);
y2.setlineweight(4);
y2.hidebubble();
#
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
How to create alerts for Outside Bars | Questions | 1 | ||
M | show which stocks trade outside the zone | Questions | 2 | |
O | Outside Bar High/Low | Questions | 4 | |
K | Full candle outside of Bollinger Band | Questions | 7 | |
D | Inside Bar OutSide Bar Clouds For ThinkOrSwim | Questions | 4 |
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.