Plot high and low of previous inside bar


Category:
0
0

Hi, I hope you can help. I have a scanner or study that finds  Inside Bars, and after the inside Bar is close it shows me an alert with an arrow for the third bar.  I have the code here:

def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def foundit = 0;
def avgRange = 0.05 * Average(high – low, 20);
plot 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);

PatternPlot.AssignValueColor(Color.YELLOW);
PatternPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Alert(PatternPlot, ” InsideBar”, Alert.BAR, Sound.Chimes);

 

I would like to show the value of the high and low of the inside bar that is close. for example I found these: but it does it in every single candle. I only want when the condition is met.

I have these:

plot data_low = low;
data_low.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
plot data_high = high;
data_high.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

I appreciate all your help

thanks

Arlette

 

 

Marked as spam
Posted by (Questions: 4, Answers: 1)
Asked on May 17, 2020 2:40 pm
174 views
0
Private answer

Wow, I can't help but mention that you have some very unorthodox code there. Looks like it was written by an engineer, and not a computer engineer but one trained in one of the other disciplines. Brute force all the way. But I guess it gets the job done for you so that's all that matters in the end.

Please don't offense to that, I just need to point that out because we have a lot of newbie programmers visiting this forum and it's important to me that folks learn the right way to code. There are a lot of examples out there of how not to do something. This falls into that category.

So you want to plot the values of the high and low of the inside bar, but only when the inside bar appears on the chart. Since your code is set to declare the inside bar only after it closes we need to read the future in order to get the plots to appear on the inside bar instead of the bar that comes immediately after it.

When your condition is true, the inside bar is the first bar to the left. So we need to test if the condition is true on that bar. That's why we have to read the future. We do this using a negative integer for the index [-1].

plot insideBarHigh = if patternPlot[-1] then high else Double.NaN;
insideBarHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
plot insideBarLow = if patternPlot[-1] then low else Double.NaN;
insideBarLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

Just add those to the end of your existing code and it will work as you requested.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 17, 2020 4:44 pm