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:
Thank you Joshua. It works great on the price bars but it is also painting the volume histogram. Is there a way to block it from painting the volume?
Code:def outsideBarID = high > high[1] and low < low[1]; def nan = Double.NaN; def h = if outsideBarID then high else nan; def l = if outsideBarID then low else nan; def o = if outsideBarID then if open > close then open else close else nan; def c = if outsideBarID then if open > close then close else open else nan; AddChart(h, l, o, c, ChartType.CANDLE, growColor = Color.WHITE);
Thank you so much - I could not figure it out but this makes sense.It appears that you have selected in setting's appearance to have volume bars color as symbol ticks. As assignpricecolor colors a bar, it then is picked up by the color settings. To workaround this, you could use the following addchart coloring of those bars.
Here ya go:The below code adds an arrow on top of the inside candle. I was hoping someone could alter to code to instead just paint the inside bar candle white instead of adding an arrow on top of it.
Existing Code Ben wrote, which adds a arrow on top of the inside bar candle:
Code:# Inside Bar # Mobius # 8.7.2017 def inside = high < high[1] and low > low[1]; plot inside_bar = inside; inside_bar.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); inside_bar.SetDefaultColor(Color.MAGENTA); inside_bar.SetLineWeight(1);
# Inside Bar
# Mobius
# 8.7.2017
def inside = high < high[1] and low > low[1];
AssignPriceColor(
if inside then color.white else color.current);
Hi Ben its telling me a plot is expected. ?@Thepremier Here you go:
Rich (BB code):# Inside and Outside Bar # Mobius # 8.7.2017 def inside = high < high[1] and low > low[1]; def outside = high > high[1] or low < low[1]; AssignPriceColor(if inside then color.cyan else if outside then color.yellow else color.current);
That indicator will plot outside and inside bars on your chart. Switch over to the Scan tab and use it as a scanner if you like. We also have Double Inside Day and Narrow Range Day as well.
By default, charts expect studies to plot something. Because this indicator only paints candles. It vomits an error.Hi Ben its telling me a plot is expected. ?
# Inside and Outside Bar
# Mobius
# 8.7.2017
def inside = high < high[1] and low > low[1];
def outside = high > high[1] or low < low[1];
AssignPriceColor(if inside
then color.cyan
else if outside
then color.yellow
else color.current);
plot data = close;
data.hide();
@Svanoy could you look at above and possibly help?Below script looks for Inside bar crossing/touching VWAP
i need a condition added so that the script is only true when that inside bar that it found be 40% of the first bar of the day.
the 40% is the difference between high and low of each bar being compared. if first bar is $1 high .50 low difference is .50...if the inside bar that triggered high is .75 and low .50 difference is .25...difference between inside bar and 1st bar of day = .25 / .50 = .25 *100 = meaning inside bar is 50% of first bar.
# 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;
plot CONDITION=if con then low else double.NaN;
condition.setPaintingStrategy(paintingStrategy.POINTS);
conditiON.setLineWeight(3);
alert(con,"ALERT",alert.ONCE,sound.Ding);
AssignbackgroundColor(if condition then color.plum else color.black);
# 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 and Percent_Check,high,RoundDown((Con_High_Low_Range/Start_Bar_High_Low_Range) * 100,1),color.white);
###########################################################################################################################
plot CONDITION = if con and Percent_Check then low else Double.NaN;
CONDITION.SetPaintingStrategy(PaintingStrategy.POINTS);
CONDITION.SetLineWeight(3);
Alert(con, "ALERT", Alert.ONCE, Sound.Ding);
AssignBackgroundColor(if CONDITION then Color.PLUM else Color.BLACK);
the script above is not respecting the inside bar requirement of the script. i used it today and every alert it provided was not an inside bar. as an example,@om4
I assume you meant 40% or more.
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 and Percent_Check,high,RoundDown((Con_High_Low_Range/Start_Bar_High_Low_Range) * 100,1),color.white); ########################################################################################################################### plot CONDITION = if con and Percent_Check then low else Double.NaN; CONDITION.SetPaintingStrategy(PaintingStrategy.POINTS); CONDITION.SetLineWeight(3); Alert(con, "ALERT", Alert.ONCE, Sound.Ding); AssignBackgroundColor(if CONDITION then Color.PLUM else Color.BLACK);
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
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);
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.