This indicator uses the 8 and 21 EMA.
Price > 8 EMA and 21 EMA --- green
Price > 8 EMA & Price < 21 EMA -- yellow
Price < 8 EMA & Price > 21 EMA -- orange
Price < 8 EMA & Price < 21 EMA -- red
This indicator had been implemented by James in JavaScript on TrendSpider. Check out the developer documentation to learn more about JS on TrendSpider.
describe_indicator("Jerry McGuire");
// Define lengths for EMAs
const lengthShort = 8; // 8 period EMA
const lengthLong = 21; // 21 period EMA
// Calculate EMAs
const emaShort = ema(close, lengthShort);
const emaLong = ema(close, lengthLong);
// Define candle colors based on conditions
const candleColors = for_every(close, emaShort, emaLong, (price, shortEMA, longEMA) => {
if (price > shortEMA && price > longEMA) {
return 'green'; // Above both EMAs
} else if (price > shortEMA && price < longEMA) {
return 'yellow'; // Above 8EMA, below 21EMA
} else if (price < shortEMA && price > longEMA) {
return 'orange'; // Below 8EMA, above 21EMA
} else if (price < shortEMA && price < longEMA) {
return 'red'; // Below both EMAs
} else {
return null; // Default color if none of the conditions are met
}
});
// Apply the color scheme to the candles
color_candles(candleColors);