Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Stochastic output #236

Open
elyas74 opened this issue May 21, 2021 · 5 comments
Open

Incorrect Stochastic output #236

elyas74 opened this issue May 21, 2021 · 5 comments

Comments

@elyas74
Copy link

elyas74 commented May 21, 2021

I can't match Stoch modules output with tradingview output,

any idea or sample code for it?

thanks.

@justertee
Copy link

I think so. Any one is not match?

@marcusmota
Copy link

Mine is correct, just add more candle data 👍

@bennycode
Copy link

@anandanand84 your Stochastic Oscillator implementation is very different from the results of the famous Tulip Indicators.

I used the values from the Example Calculation of Tulip Indicators and created a test script to verify your implementation:

const Stochastic = require('technicalindicators').Stochastic;

const candles: [number, number, number][] = [
  [82.15, 81.29, 81.59],
  [81.89, 80.64, 81.06],
  [83.03, 81.31, 82.87],
  [83.3, 82.65, 83.0],
  [83.85, 83.07, 83.61],
  [83.9, 83.11, 83.15],
  [83.33, 82.49, 82.84],
  [84.3, 82.3, 83.99],
  [84.84, 84.15, 84.55],
  [85.0, 84.11, 84.36],
  [85.9, 84.03, 85.53],
  [86.58, 85.39, 86.54],
  [86.98, 85.76, 86.89],
  [88.0, 87.17, 87.77],
  [87.87, 87.01, 87.29],
];

const highs = [];
const lows = [];
const closes = [];

for (let i = 0; i < candles.length; i++) {
  const [high, low, close] = candles[i];
  highs.push(high);
  lows.push(low);
  closes.push(close);
}

let input = {
  high: highs,
  low: lows,
  close: closes,
  period: 5,
  signalPeriod: 3,
};

console.log(Stochastic.calculate(input));

Here are your results:

[
  { k: 92.52336448598145, d: undefined },
  { k: 76.99386503067488, d: undefined },
  { k: 59.07335907335904, d: 76.19686286333847 },
  { k: 84.49999999999989, d: 73.52240803467794 },
  { k: 88.58267716535411, d: 77.38534541290434 },
  { k: 76.29629629629629, d: 83.12632448721676 },
  { k: 89.72222222222213, d: 84.8670652279575 },
  { k: 99.06542056074785, d: 88.36131302642208 },
  { k: 96.94915254237277, d: 95.2455984417809 },
  { k: 94.20654911838781, d: 96.74037407383612 },
  { k: 82.11586901763239, d: 91.09052355946432 }
]

With Tulip Indicators the last values should be: 91.09 (k) & 94.36 (d)

@marcusmota
Copy link

@bennycode if you add more candles you get the same value as tradingview.

👍

@saru2020
Copy link

doesn't work with values matching the period, but it works when we add more values, so basically try to pass all the candles data and it should work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants