Tradeovate indicator not working (JAVASCRIPT) Simple indicator wont plot values on chart (PINE SCRIPT)

1 day ago 2
ARTICLE AD BOX

This indicator was converted from Pine script to JavaScript using A.I. However, it is not plotting the indicator or values. I converted the code using Gogle A.I. Figued it would be pretty strait forward for it to correctly create the JavaScript. The indicator will load, however there is something wrong with the coding and it is not correctly plotting the indicator.

Any help regarding this would be big time appreciated!

Thanks in advance!

Paul

const pre = new WeakMap(); class TrendlinesWithBreaks { map(d, i, history) { // 1. Initialize State for this instance let state = pre.get(this) || { upper: [], lower: [], slope_ph: [], slope_pl: [], single_upper: [], single_lower: [], atr_buffer: [] }; pre.set(this, state); const length = this.props.length; const k = this.props.k; // Ensure we have enough data to calculate if (i < length * 2) return {}; const high = history.high; const low = history.low; const close = history.close; // 2. Helper: Pivot Calculation const isPivot = (data, idx, len, isHigh) => { const val = data[idx - len]; for (let j = 0; j <= len * 2; j++) { if (j === len) continue; if (isHigh ? data[idx - j] > val : data[idx - j] < val) return null; } return val; }; // 3. Helper: ATR Calculation const getATR = (idx) => { let trSum = 0; for (let j = 0; j < length; j++) { const currIdx = idx - j; const tr = Math.max( high[currIdx] - low[currIdx], Math.abs(high[currIdx] - close[currIdx - 1]), Math.abs(low[currIdx] - close[currIdx - 1]) ); trSum += tr; } return trSum / length; }; const ph = isPivot(high, i, length, true); const pl = isPivot(low, i, length, false); // 4. Calculate Slopes and Levels const currentSlope = (getATR(i) / length) * k; const prev_slope_ph = state.slope_ph[i - 1] || 0; const prev_slope_pl = state.slope_pl[i - 1] || 0; const prev_upper = state.upper[i - 1] || close[i]; const prev_lower = state.lower[i - 1] || close[i]; state.slope_ph[i] = ph !== null ? currentSlope : prev_slope_ph; state.slope_pl[i] = pl !== null ? currentSlope : prev_slope_pl; state.upper[i] = ph !== null ? ph : prev_upper - state.slope_ph[i]; state.lower[i] = pl !== null ? pl : prev_lower + state.slope_pl[i]; // 5. Breakout Logic const src_len = close[i - length]; const prev_single_up = state.single_upper[i - 1] || 0; const prev_single_lo = state.single_lower[i - 1] || 0; state.single_upper[i] = src_len > state.upper[i] ? 0 : ph !== null ? 1 : prev_single_up; state.single_lower[i] = src_len < state.lower[i] ? 0 : pl !== null ? 1 : prev_single_lo; const breakoutUp = prev_single_up && src_len > state.upper[i]; const breakoutDown = prev_single_lo && src_len < state.lower[i]; // 6. Return values for Tradovate to plot return { upperLine: state.upper[i], lowerLine: state.lower[i], // Return numeric values for colors/styling if needed breakUp: breakoutUp ? state.upper[i] : null, breakDown: breakoutDown ? state.lower[i] : null }; } } module.exports = { name: "Trendlines with Breaks", description: "Detects pivot-based trendlines and breakouts.", calculator: TrendlinesWithBreaks, params: { length: { label: "Pivot Length", type: "number", def: 7, min: 2 }, k: { label: "Slope Multiplier", type: "number", def: 1.0, step: 0.1 } }, plots: { upperLine: { title: "Upper Trendline", type: "line", color: "#ff0000" }, lowerLine: { title: "Lower Trendline", type: "line", color: "#00ff00" }, breakUp: { title: "Breakout Up", type: "dot", color: "#00ffff" }, breakDown: { title: "Breakout Down", type: "dot", color: "#ff00ff" } }, schemeStyles: { dark: { upperLine: { color: "red" }, lowerLine: { color: "green" } } } };
Read Entire Article