anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.13k stars 550 forks source link

this bugging me for so long about how this script works like this reeeeeeee xD ahahaha #237

Open gurachan opened 3 years ago

gurachan commented 3 years ago

so in rsi. if u give it a 500 array it returns 486. but why.. how can I align it per candles..

its has same value as tradingview.. the end of the 486 matches the end of the candle from traiding view..

what happen to other 14 do i just put 0 on it? in the start?.. also some of it is inacurate

..........

also same as macd ... and also its returning inacurate result also

example data


  let test = [
        2197.3325,
        2196.625,
        2226.4525,
        2226.4925,
        2210.8275,
        2222.9024999999997,
        2241.5675,
        2289.91,
        2327.7225,
        2341.94,
        2355.76,
        2334.8575,
        2321.235,
        2356.435,
        2361.9725,
        2348.19,
        2341.2200000000003,
        2384.4249999999997,
        2444.0074999999997,
        2454.2225,
        2433.7625,
        2419.1,
        2410.9125,
        2412.4025,
        2406.4025,
        2427.0675,
        2404.925,
        2401.725,
        2427.9575,
        2452.55,
        2445.7775,
        2423.0525,
        2413.0275,
        2377.5874999999996,
        2349.6525,
        2336.1525,
        2309,
        2349.4500000000003,
        2372.5299999999997,
        2360.465,
        2367.265,
        2373.4925000000003,
        2359.255,
        2353.5950000000003,
        2331.5725,
        2298.55,
        2285.1525,
        2287.7325,
        2286.2075,

    ]

     var macdInput = {
        values: test,
        fastPeriod: 12,
        slowPeriod: 26,
        signalPeriod: 9,
        SimpleMAOscillator: false,
        SimpleMASignal: false
    }

    let macdo2 = MACD.calculate(macdInput);
    console.log(macdo2)

it returns image

signal and histogram doesn't even work

expected result .. look it returns full 49 values.. 0-48

image

I use the code

 export function _MACD(data, slowPeriods = 26, fastPeriods = 12, signalPeriods = 9) {

    const MACD = sub(
        ema(data, fastPeriods),
        ema(data, slowPeriods),
        1
    )

    const signal = ema(MACD, signalPeriods)
    const histogram = sub(MACD, signal)

    return {
        MACD,
        signal,
        histogram
    }
}

and format it like this script input

 {
            MACD: roundN(element),
            signal: roundN(macdo.signal[index]),
            histogram: roundN(macdo.histogram[index])
 }

it gives 1:1 value in tradingview macd..

example of last index-2 index-3 index-4

heres the last log of eth this time using script above.. btw ema is from moving-averages npm package

image TraidinView Snapshot image image image ..

back to my problem, I don't understand why the output is incomplete and some inaccurate... did I miss something? and some have signal and histogram errors.

all of this have same config

fastPeriod: 12,
slowPeriod: 26,
signalPeriod: 9,
muratozenc commented 2 years ago

The data provided by the indicators are correct, I am using them, maybe there is a 1% error but it can ignored.

If you need to calculate RSI(6), which means RSI calculated last 6 candles, the result provided by the function is going to be empty for the first 6 candles, which is natural because function tries to give you results by using them.

https://www.binance.com/tr/trade/COS_USDT?layout=pro

Select the weekly graphic and check the MACD and RSI indicator results, you are going to see that there is no results at the beginning.