Reputation: 1
Seniors. I am trying to draw an arrow that satisfies this special condition with pine script. The conditions are follow as: -If a low is colored dark green and its value is higher than or equal to the lowest point of any of the next five candles, draw an arrow to the first matching candle. -If a high is colored dark red and its value is lower than or equal to the highest point of any of the next five candles, draw an arrow to the first matching candle. Thank you any answers.
The hardest part for me is identifying the next five candle values. To do this, I defined a global range variable, but the historical data for that global range variable was not available at my disposal. For example. var int highindex = na ... if highindex[2] > highindex[3] ... Here, highindex[2], highindex[3] ... have the same value, but they cannot logically have the same value. I have attached the target image.
Upvotes: 0
Views: 72
Reputation: 816
You can use ta.pivothigh(high, 0, 5)
and also pivotlow
to find the highest/lowest extreme points, store them in an array with a user defined type and then check if the current candle has covered any of these values.
Always remember that all your pine script code is executed on every candle (and if this is the last candle, then on every tick).
It is best to draw arrows only on the last candle (barstate.islast
) and each time before that remove all arrows from the chart.
Something like:
<...>
if matching_array.size() > 0
for i = 0 to matching_array.size() - 1
udt_element = matching_array.get(i)
if udt_element.isLow and close > udt_element.high
udt_element_to = bar_index
<...>
line.all.clear()
if barstate.islast and matching_array.size() > 0
for i = 0 to matching_array.size() - 1
udt_element = matching_array.get(i)
line.new(udt_element.from, udt_element.high, udt_element.to, udt_element.high)
Same logic for lows of highest points.
Upvotes: 1