Add configurable RSI levels and remove line settings for RSI
RSI Changes: - Add overbought and oversold level inputs (default 70/30) - Update calculate() to return overboughtBand and oversoldBand instead of hardcoded bands - Update plots to use overboughtBand and oversoldBand with fixed style='dashed' and width=1 - This makes RSI bands adjustable while keeping line style and width fixed Configuration Panel: - Hide Line Type and Line Width settings for RSI (indicator.type === 'rsi') - RSI bands always dashed at 1px width as standard - Overbought and oversold levels now appear as configurable parameters
This commit is contained in:
@ -3,6 +3,8 @@ import { BaseIndicator } from './base.js';
|
|||||||
export class RSIIndicator extends BaseIndicator {
|
export class RSIIndicator extends BaseIndicator {
|
||||||
calculate(candles) {
|
calculate(candles) {
|
||||||
const period = this.params.period || 14;
|
const period = this.params.period || 14;
|
||||||
|
const overbought = this.params.overbought || 70;
|
||||||
|
const oversold = this.params.oversold || 30;
|
||||||
|
|
||||||
// 1. Calculate RSI using RMA (Wilder's Smoothing)
|
// 1. Calculate RSI using RMA (Wilder's Smoothing)
|
||||||
let rsiValues = new Array(candles.length).fill(null);
|
let rsiValues = new Array(candles.length).fill(null);
|
||||||
@ -38,29 +40,31 @@ export class RSIIndicator extends BaseIndicator {
|
|||||||
return {
|
return {
|
||||||
paneBg: 80, // Background lightening trick
|
paneBg: 80, // Background lightening trick
|
||||||
rsi: rsi,
|
rsi: rsi,
|
||||||
upperBand: 70,
|
overboughtBand: overbought,
|
||||||
lowerBand: 30
|
oversoldBand: oversold
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getMetadata() {
|
getMetadata() {
|
||||||
const plots = [
|
|
||||||
// RSI Line
|
|
||||||
{ id: 'rsi', color: '#7E57C2', title: '', width: 1, lastValueVisible: true },
|
|
||||||
|
|
||||||
// Bands
|
|
||||||
{ id: 'upperBand', color: '#787B86', title: '', style: 'dashed', width: 1, lastValueVisible: false },
|
|
||||||
{ id: 'lowerBand', color: '#787B86', title: '', style: 'dashed', width: 1, lastValueVisible: false }
|
|
||||||
];
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'RSI',
|
name: 'RSI',
|
||||||
description: 'Relative Strength Index',
|
description: 'Relative Strength Index',
|
||||||
inputs: [
|
inputs: [
|
||||||
{ name: 'period', label: 'RSI Length', type: 'number', default: 14, min: 1, max: 100 }
|
{ name: 'period', label: 'RSI Length', type: 'number', default: 14, min: 1, max: 100 },
|
||||||
|
{ name: 'overbought', label: 'Overbought Level', type: 'number', default: 70, min: 50, max: 95 },
|
||||||
|
{ name: 'oversold', label: 'Oversold Level', type: 'number', default: 30, min: 5, max: 50 }
|
||||||
|
],
|
||||||
|
plots: [
|
||||||
|
// RSI Line - solid, 1px
|
||||||
|
{ id: 'rsi', color: '#7E57C2', title: '', style: 'solid', width: 1, lastValueVisible: true },
|
||||||
|
|
||||||
|
// Overbought Band - dashed, 1px
|
||||||
|
{ id: 'overboughtBand', color: '#787B86', title: '', style: 'dashed', width: 1, lastValueVisible: false },
|
||||||
|
|
||||||
|
// Oversold Band - dashed, 1px
|
||||||
|
{ id: 'oversoldBand', color: '#787B86', title: '', style: 'dashed', width: 1, lastValueVisible: false }
|
||||||
],
|
],
|
||||||
plots: plots,
|
|
||||||
displayMode: 'pane',
|
displayMode: 'pane',
|
||||||
paneMin: 0,
|
paneMin: 0,
|
||||||
paneMax: 100
|
paneMax: 100
|
||||||
|
|||||||
@ -281,6 +281,7 @@ return `
|
|||||||
`.trim() + '';
|
`.trim() + '';
|
||||||
}).join('')}
|
}).join('')}
|
||||||
|
|
||||||
|
${indicator.type !== 'rsi' ? `
|
||||||
<div class="config-row">
|
<div class="config-row">
|
||||||
<label>Line Type</label>
|
<label>Line Type</label>
|
||||||
<select onchange="window.updateIndicatorSetting && window.updateIndicatorSetting('${indicator.id}', '_lineType', this.value)">
|
<select onchange="window.updateIndicatorSetting && window.updateIndicatorSetting('${indicator.id}', '_lineType', this.value)">
|
||||||
@ -293,6 +294,7 @@ return `
|
|||||||
<input type="range" min="1" max="5" value="${indicator.params._lineWidth || 2}" onchange="this.nextElementSibling.textContent = this.value; window.updateIndicatorSetting && window.updateIndicatorSetting('${indicator.id}', '_lineWidth', parseInt(this.value))">
|
<input type="range" min="1" max="5" value="${indicator.params._lineWidth || 2}" onchange="this.nextElementSibling.textContent = this.value; window.updateIndicatorSetting && window.updateIndicatorSetting('${indicator.id}', '_lineWidth', parseInt(this.value))">
|
||||||
<span class="range-value">${indicator.params._lineWidth || 2}</span>
|
<span class="range-value">${indicator.params._lineWidth || 2}</span>
|
||||||
</div>
|
</div>
|
||||||
|
` : ''}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${meta?.inputs && meta.inputs.length > 0 ? `
|
${meta?.inputs && meta.inputs.length > 0 ? `
|
||||||
|
|||||||
Reference in New Issue
Block a user