Display bars since cross above HMA


Category:
0
0

I would like to create a watchlist with the number of days the price as crossed up through the 20 hull ma and keep a count its been there

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on December 30, 2019 8:52 pm
240 views
0
Private answer

I think this should do the job. I have included the count for bars since cross below as well. Then colored the background based on which count is greater. You can adjust the length and the average type in the user inputs. Which will make this applicable to a broad range of specifications.

input price = close;
input length = 20;
input type = AverageType.HULL;
input displace = 0;
def ma = MovingAverage(type, price, length)[-displace];
def crossAbove = close[1] < ma[1] and close > ma;
def crossBelow = close[1] > ma[1] and close < ma; rec countAbove = if crossAbove then 1 else if close > ma then countAbove[1] + 1 else 0;
rec countBelow = if crossBelow then -1 else if close < ma then countBelow[1] - 1 else 0; plot data = if countAbove > AbsValue(countBelow) then countAbove else countBelow;
data.AssignValueColor(if data == 0 then Color.CURRENT else Color.BLACK);
AssignBackgroundColor(if data > 0 then Color.GREEN else if data < 0 then Color.RED else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on December 31, 2019 2:21 pm