Reputation: 11
As you can see i made 2 Hull MA with both length 75. For the blue one i made offset to -10. How can i create a strategy from the crossover of the 2 MA? My problem is that offset is only changing the plot so if i try crossover(hullma,hullma1) nothing is happening as tradingview think these lines are the same. So is there any change to move left 10 bars an indicator and setup a crossover strategy? thanks
Upvotes: 1
Views: 1592
Reputation: 3828
Using a negative offset means you offset current data to the past and you won't be able to determine the cross at the live candle, only with a delay equal to the offset value.
This will make it impossible to create a cross signal at the same moment of the happened cross, but you can use that signal for the analysis on the history candles.
Note that you won't be able to spot a cross during last 10 (equal to offset value) candles.
//@version=4
study(title="HMA Cross the Offset HMA", overlay=true)
length = input(75, minval=1)
src = input(close, title="Source")
hullMa = wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)))
// Current Hull Moving Average
plot(hullMa, color = color.red)
// Hull Moving Average with a negative offset
plot(hullMa, color = color.blue, offset = -10)
float hullMaWithOffset = nz(hullMa[10])
bool cross = cross(hullMa, hullMaWithOffset)
// Mark Cross with Background color
// To spot the exact bar with a crossover we should use the equal offset value
bgcolor(cross? color.orange : na, offset = -10)
Upvotes: 1