# Up/Dn arrows...how to paint on bar[1]?

#### DaysOff

##### New member
I have coded a strategy in thinkorswim that places up or down arrows on the chart once a condition has been met. For discussion sake, let's say the condition is if two bars form with the entire range of each bar completely above the upper Bollinger band, a red arrow is placed below the second bar. When I try to code this, it will paint on the next bar after the condition has been met. Is there any way to get the arrow to paint on the prior bar?

Thanks in advance for any assistance!

In the image is an example with corresponding code below. In the example, the condition is met when two bars are entirely above or below the BB's. Instead of the arrow painting on the next bar, I'd like it to paint on the one previous...the second bar that forms entirely outside.

Code:
input price = 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 = price[-displace], length = length);

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

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

def b1 = (low > max(LowerBand, UpperBand));
#test.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);

#2 Bar sell
def s1 = (high < min(LowerBand, UpperBand));
def sell1Count = if s1 then sell1count[1] + 1 else 0;
#plot test2 = sell1count;
#test2.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
plot sell1 = sell1Count[1] == 2;
sell1.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_Down);
sell1.setDefaultColor(color.downtick);

it should be showing the arrow as soon as 2 valid candles finish, so not much delay.

it is looking at a previous bar to determine a buy. because then it only looks at completed bars.

try changing the [1] to [0] , to make it look at the current bar.
the price fluctuations may cause multiple triggers?

@DaysOff If you don't wait for the two prior candles to close before painting the arrows, the indicator will repaint, giving false signals... There is good reason for the lag of some indicators because we want to know that something happened rather than something may or may not be happening... Acting prematurely can get you stopped out of a higher percentage of trades than desirable...

Thanks for the replies. I wasn’t suggesting the logic be changed…as it works the way it is. I was more wondering if it was possible to indicate on which bar to have the arrow painted. I don’t think it is possible…but thought I would ask.

Thanks for the replies. I wasn’t suggesting the logic be changed…as it works the way it is. I was more wondering if it was possible to indicate on which bar to have the arrow painted. I don’t think it is possible…but thought I would ask.

Yes, the chart bar/candle can be painted to match the arrow... The issue would be that the candle/bar would repaint along with the arrow... The code would be something like the following but it hasn't been tested... I'm assuming this is what you are looking for...

Ruby:
``AssignPriceColor(if buy1 then Color.GREEN else if sell1 then Color.RED else Color.CURRENT);``

Thanks for the replies. I wasn’t suggesting the logic be changed…as it works the way it is. I was more wondering if it was possible to indicate on which bar to have the arrow painted. I don’t think it is possible…but thought I would ask.

See if this works for you. By increasing/decreasing the arrowmover you can move arrow right/left. It will plot the arrow after the bar closes meeting your condition. The counts for buy/sell are plotted for testing and the circled areas are highlighting the arrows.

Ruby:
``````input price = 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 = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + Num_Dev_Dn * sDev;
plot UpperBand = MidLine + Num_Dev_up * sDev;

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

input arrowmover = -1;#Hint arrowmover: increase/decrease arrowmover to move arrowmover right/left
def n  = arrowmover;
def n1 = n + 1;

def b1 = (low > Max(LowerBand, UpperBand));
test.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot buy1 = if !IsNaN(close[n]) and buy1Count[n1] == 2 then 1 else 0;

#2 Bar sell
def s1 = (high < Min(LowerBand, UpperBand));
def sell1Count = if s1 then sell1Count[1] + 1 else 0;
plot test2 = sell1count;
test2.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
plot sell1 = if !IsNaN(close[n]) and sell1Count[n1] == 2 then 1 else 0;
sell1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell1.SetDefaultColor(Color.DOWNTICK);

Last edited:
See if this works for you. By increasing/decreasing the arrowmover you can move arrow right/left. It will plot the arrow after the bar closes meeting your condition. The counts for buy/sell are plotted for testing and the circled areas are highlighting the arrows.
Hi, How do I incorporate this ArrowMover feature into the following? Thanks in advance for your help.

plot ArrowUp = if EMA9 crosses above SMA20
then low
else double.nan;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
ArrowUP.SetLineWeight(2);
ArrowUP.SetDefaultColor(Color.GREEN);

plot ArrowDN = if EMA9 crosses below SMA20
then high
else double.nan;
ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
ArrowDN.SetLineWeight(2);
ArrowDN.SetDefaultColor(Color.RED);

Hi, How do I incorporate this ArrowMover feature into the following? Thanks in advance for your help.

plot ArrowUp = if EMA9 crosses above SMA20
then low
else double.nan;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
ArrowUP.SetLineWeight(2);
ArrowUP.SetDefaultColor(Color.GREEN);

plot ArrowDN = if EMA9 crosses below SMA20
then high
else double.nan;
ArrowDN.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
ArrowDN.SetLineWeight(2);
ArrowDN.SetDefaultColor(Color.RED);

This has the arrowmover included, which was modified to fit with your code. When 'n' is set to zero, then both arrowmover is at the normal arrow plot. A negative number moves it n spaces to the left and a postive number to the right of the normal arrow.

Your arrowup and arrowdn was changed from low/high to 1/0 boolean to facilitate the arrowmover code adaption.

Ruby:
``````def ema9 = ExpAverage(close, 9);
def sma20 = SimpleMovingAvg(close, 20);

def Arrow_Up = if ema9 crosses above sma20 then 1 else 0;
def Arrow_DN = if ema9 crosses below sma20 then 1 else 0;

input arrowmover = -1;#Hint arrowmover: increase/decrease arrowmover to move arrowmover right/left
def n  = arrowmover;

#2 Bar up
def upCount  = if Arrow_Up then upCount[1] + 1 else 0;

plot arrowup = if !IsNaN(close[n]) and upCount[n] == 1 then 1 else 0;
arrowup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrowup.SetDefaultColor(Color.UPTICK);

#2 Bar dn
def dnCount  = if Arrow_DN then dnCount[1] + 1 else 0;

plot arrowdn = if !IsNaN(close[n]) and dnCount[n] == 1 then 1 else 0;
arrowdn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
arrowdn.SetDefaultColor(Color.DOWNTICK);

#Test Bubbles
input test = yes;
AddChartBubble(test and arrowup == 1, low * .9995, "Off\nSet: \n" + n, Color.GREEN, no);
AddChartBubble(test and arrowdn == 1, high * 1.0005, "Off\nSet: \n" + n, Color.RED);``````

This has the arrowmover included, which was modified to fit with your code. When 'n' is set to zero, then both arrowmover is at the normal arrow plot. A negative number moves it n spaces to the left and a postive number to the right of the normal arrow.

Your arrowup and arrowdn was changed from low/high to 1/0 boolean to facilitate the arrowmover code adaption.
Thank you so much!

87k+ Posts
345 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?