'How to watch multiple criteria then plotchar() there?
My Pine script calculates a bunch of everything, twice. The final challenge is to mark the price if multiple criterion is met.
Just for testing purpose, I found a marker code line here
plotchar(ta.rising(close, 5), "`plotchar()`", "▲", location.belowbar, color.lime, size = size.tiny)
Well, okay, I don't get what's that ta.rising() part and what's that 5 in the (close, 5) part but it works well standalone and I see something (some unwanted green triangles on the chart; it's cool). But if I insert an IF RSI <= 30:
if rsi <= 30
plotchar(ta.rising(close, 5), "`plotchar()`", "▲", location.belowbar, color.lime, size = size.tiny)
… then not the if line but the plotchar line returns with an error message: Mismatched input 'plotchar' expecting 'end of line without line continuation'. (I repeat, it works without that IF …)
In case I put a tabulator before the plotchar:
if rsi <= 30
plotchar(ta.rising(close, 5), "`plotchar()`", "▲", location.belowbar, color.lime, size = size.tiny)
… then the error message is: Cannot use 'plotchar' in local scope.
So I'm obviously far from the thread. What's the right usage of this code part? And eventually, how to make it put that triangle below the candle if (in this case) RSI goes under 30? (It's the built-in RSI source code there, waiting for something to RSI…)
Solution 1:[1]
You cannot use the plot() functions in local scope.
You can add your condition to the series argument of your plot() function.
plotchar((rsi <= 30) and (ta.rising(close, 5)), "`plotchar()`", "?", location.belowbar, color.lime, size = size.tiny)
Solution 2:[2]
Well, it turned out, the right syntax is:
plotchar((rsi <= 30) and (ta.rising(close, 5)), "`plotchar()`", "?", location.belowbar, color.lime, size = size.tiny)
How to make it place those triangles below every single candles the RSI criteria triggers on?
Okay, it was obvious:
plotchar(rsi <= 30), "`plotchar()`", "?", location.belowbar, color.lime, size = size.tiny)
Now after some experimentation, I finally found it out how to combine criterions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vitruvius |
| Solution 2 |
