Untitled
unknown
plain_text
2 years ago
4.2 kB
21
Indexable
// main.js
function performTechnicalAnalysis(data) {
function calculateFibonacciLevels(data) {
console.log(data)
const high = data.map(d => parseFloat(d[2])); // En yüksek fiyatları al
const low = data.map(d => parseFloat(d[3])); // En düşük fiyatları al
const maxPrice = Math.max(...high); // En yüksek fiyat
const minPrice = Math.min(...low); // En düşük fiyat
const diff = maxPrice - minPrice;
const fibonacciLevels = {
level0: maxPrice,
level236: maxPrice - (0.236 * diff),
level382: maxPrice - (0.382 * diff),
level618: maxPrice - (0.618 * diff),
level1: minPrice
};
return fibonacciLevels;
}
function calculateTrendLine(data) {
const xValues = data.map((d, index) => index + 1); // Zaman serisi için indeksler
const yValues = data.map(d => (parseFloat(d[2]) + parseFloat(d[3])) / 2); // Ortalama fiyatlar
const n = xValues.length;
let sumX = 0;
let sumY = 0;
let sumXY = 0;
let sumX2 = 0;
for (let i = 0; i < n; i++) {
sumX += xValues[i];
sumY += yValues[i];
sumXY += xValues[i] * yValues[i];
sumX2 += xValues[i] ** 2;
}
const slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX ** 2);
const intercept = (sumY - slope * sumX) / n;
const trendLine = {
start: [xValues[0], slope * xValues[0] + intercept], // Başlangıç noktası
end: [xValues[n - 1], slope * xValues[n - 1] + intercept] // Bitiş noktası
};
return trendLine;
}
function calculateSupportResistance(data) {
const closePrices = data.map(d => parseFloat(d[4])); // Kapanış fiyatları
const lowPrices = data.map(d => parseFloat(d[3])); // En düşük fiyatlar
const highPrices = data.map(d => parseFloat(d[2])); // En yüksek fiyatlar
// Destek ve direnç seviyelerini hesaplayacak ve depolayacak boş bir dizi oluşturalım
const supportResistanceLevels = [];
// Basit bir destek ve direnç analizi yaparak seviyeleri bulalım
const pivot = (Math.max(...highPrices) + Math.min(...lowPrices) + closePrices[closePrices.length - 1]) / 3;
const resistance = pivot + (pivot - Math.min(...lowPrices));
const support = pivot - (Math.max(...highPrices) - pivot);
supportResistanceLevels.push({ level: resistance, type: 'resistance' });
supportResistanceLevels.push({ level: support, type: 'support' });
return supportResistanceLevels;
}
function plotSupportResistanceChart(levels) {
// Grafik üzerinde destek ve direnç seviyelerini çizme işlemi
levels.forEach(level => {
const color = level.type === 'resistance' ? 'red' : 'green';
const chart = Highcharts.stockChart('container', {
series: [{
type: 'line',
color: color,
data: [[0, level.level], [100, level.level]], // Grafikte yüksek bir değer kullanabilirsiniz
lineWidth: 1,
marker: {
enabled: false
}
}]
});
});
}
const fibonacciLevels = calculateFibonacciLevels(data);
const trendLine = calculateTrendLine(data);
const supportResistance = calculateSupportResistance(data);
plotSupportResistanceChart(supportResistance);
return {
fibonacciLevels,
trendLine,
supportResistance
};
}
function drawChart(data) {
Highcharts.stockChart('container', {
series: [{
id: 'main',
type: 'candlestick',
color: '#FF6F6F',
upColor: '#6FB76F',
data: data,
dataGrouping: {
enabled: false
}
}]
});
}Editor is loading...
Leave a Comment