♥ 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 fastema = ExpAverage(price[-displace], fast_length); plot crossover = if fastema > slowema then 1 else 0;
Marked as spam
|
Please log in to post questions.
I have updated the code to include the cross in the other direction.
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);
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.