Reputation: 1
//@version=5
indicator("Price Movement Check", overlay = true)
// Set input parameters for n and m
n = input.int(title="Days for price increase check", defval=5)
m = input.int(title="Days for price decrease check", defval=2)
// Check if close price is increasing for n days
isIncreasing = true
for i = 1 to n
isIncreasing := isIncreasing and close[i] > close[i-1]
// Check if close price is decreasing for m days
isDecreasing = true
for i = 1 to m
isDecreasing := isDecreasing and close[i] < close[i-1]
// Plot a shape if both conditions are true
if isIncreasing and isDecreasing
plotshape(true, style=shape.triangleup, location=location.abovebar, offset=-n, color=#009688, size=size.small)
I'm writing a code so that It gives me a buy signal if the close price increases and decreases for 'n' number of days. The buy signal should appear if both the increase and decrease conditions are met.
It gives an error quoting "Cannot use 'plotshape' in local scope" "Remarks Use plotshape function in conjuction with 'overlay=true' indicator parameter"
Upvotes: 0
Views: 51
Reputation: 1435
You can't use the plotshape in an if statement. You need to use the ternary operator to check if conditions are true rather than an if statement.
plotshape(isIncreasing and isDecreasing ? 1 : na, style=shape.triangleup, location=location.abovebar, offset=-n, color=#009688, size=size.small)
Upvotes: 0