Индикатор Tradovate не работает (JAVASCRIPT). Простой индикатор не отображает значения на графике (PINE SCRIPT)Javascript

Форум по Javascript
Ответить
Anonymous
 Индикатор Tradovate не работает (JAVASCRIPT). Простой индикатор не отображает значения на графике (PINE SCRIPT)

Сообщение Anonymous »

Этот индикатор был преобразован из сценария Pine в JavaScript с использованием искусственного интеллекта. Однако он не отображает индикатор или значения. Я преобразовал код с помощью Gogle A.I. Подумал, что было бы довольно просто правильно создать JavaScript. Индикатор загрузится, однако что-то не так с кодированием, и он неправильно отображает индикатор.
Будем очень благодарны за любую помощь по этому поводу!
Заранее спасибо!
Пол
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 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 || 0;
const prev_slope_pl = state.slope_pl || 0;
const prev_upper = state.upper || close;
const prev_lower = state.lower || close;

state.slope_ph = ph !== null ? currentSlope : prev_slope_ph;
state.slope_pl = pl !== null ? currentSlope : prev_slope_pl;

state.upper = ph !== null ? ph : prev_upper - state.slope_ph;
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" }
}
}
};


Подробнее здесь: https://stackoverflow.com/questions/798 ... lot-values
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»