Timestamp watch list column


Category:
0
0

Pete

I have a code for watch list cross red bar is bearish and green bar is bullish.  Is it possible to make the most recent EMA cross pop to the top of my column like a timestamp.

def price = close;
def fast_length = 9;
def slow_length = 50;
def displace = 0;

def fastema = ExpAverage(price[-displace], fast_length);
def slowema = ExpAverage(price[-displace], slow_length);

plot crossover = if fastema > slowema then 1 else 0;
crossover.AssignValueColor(if fastema > slowema
then Color.DARK_GREEN else color.DARK_RED);
AssignBackgroundColor(if fastema > slowema then Color.GREEN else Color.DARK_RED);

 

Marked as spam
Posted by (Questions: 49, Answers: 42)
Asked on January 29, 2019 9:17 am
121 views
0
Private answer

Timestamp, no. We cannot create a timestamp showing when a specific event happened. About the only thing we can do is to count the number of bars since the cross happened and apply that value to the watchlist column. This value can then be used as a sort column.

def price = close;
def fast_length = 9;
def slow_length = 50;
def displace = 0;
def fastema = ExpAverage(price[-displace], fast_length);
def slowema = ExpAverage(price[-displace], slow_length);
def crossover = fastema > slowema;
def crossunder = fastema < slowema;
rec counterUp = if crossover and !crossover[1] then 1 else if fastema > slowema then counterUp[1] + 1 else 0;
rec counterDown = if crossunder and !crossunder[1] then 1 else if fastema < slowema then counterDown[1] + 1 else 0;
plot data = Max(counterUp, counterDown);
data.AssignValueColor(if fastema > slowema then Color.BLACK else color.WHITE);
AssignBackgroundColor(if fastema > slowema then Color.GREEN else Color.DARK_RED);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 29, 2019 1:46 pm
0
Pete All the red bars have a value of 0….Could I also get it when the 9EMA crosses below the 50 for red bars
( at January 29, 2019 3:30 pm)
0

I have updated the code to include the cross in the other direction.

( at January 30, 2019 11:21 am)
0

Pete,
This indicator is working great but could you tweek it for me….I’ve been looking at some of the candle counter numbers and thought they were off…What it was counting was any time the bar crosses the EMA it starts counting….Could you code it so the counter startes when the EMA crosses regardless of where the candles is..So if the 9 ema crosses above the 50 ema the box is green and the counter will start there at the EMA cross not how may bar ago did the bar crross above the 9 EMA…..And the same for the other direction

def price = close;
def fast_length = 9;
def slow_length = 50;
def displace = 0;
def fastema = ExpAverage(price[-displace], fast_length);
def slowema = ExpAverage(price[-displace], slow_length);
def crossover = fastema > slowema;
def crossunder = fastema < slowema; rec counterUp = if crossover and !crossover[1] then 1 else if fastema > slowema then counterUp[1] + 1 else 0;
rec counterDown = if crossunder and !crossunder[1] then 1 else if fastema < slowema then counterDown[1] + 1 else 0; plot data = Max(counterUp, counterDown); data.AssignValueColor(if fastema > slowema then Color.BLACK else color.WHITE);
AssignBackgroundColor(if fastema > slowema then Color.GREEN else Color.DARK_RED);

( at February 4, 2019 9:47 am)
0

The code already does what you are requesting here. Not sure why your observations do not match that. The code contains nothing to look at the position of individual candles. The candle only sees the moving averages. The counter always resets to 1 when the moving averages cross. Then the code counts the number of bars elapsed since the last cross in that same direction. If you notice everything matches on the daily time frame but does not match on intraday, then you have a chart setting to adjust.

( at February 6, 2019 8:56 am)