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));
#2 Bar buy
def b1 = (low > max(LowerBand, UpperBand));
def buy1Count = if b1 then buy1count[1] + 1 else 0;
#plot test = buy1count;
#test.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
plot buy1 = buy1Count[1] == 2;
buy1.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
buy1.setDefaultColor(color.uptick);
Alert(buy1, "Buy 1", alert.bar, sound.ding);
#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);
Alert(sell1, "Sell 1", alert.bar, sound.ding);
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));
#2 Bar buy
def b1 = (low > max(LowerBand, UpperBand));
def buy1Count = if b1 then buy1count[1] + 1 else 0;
#plot test = buy1count;
#test.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
plot buy1 = buy1Count[1] == 2;
buy1.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
buy1.setDefaultColor(color.uptick);
Alert(buy1, "Buy 1", alert.bar, sound.ding);
#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);
Alert(sell1, "Sell 1", alert.bar, sound.ding);