SuperTrend equation used by Zerodha Kite

ziptaptoe
Hey guys, I'm trying to implement the supertrend indicator (similar to the one provided by the https://kite.zerodha.com/ charts) however I can't find a credible source for it. So far I've found three and all three are conflicting:

1. http://www.freebsensetips.com/blog/detail/7/What-is-supertrend-indicator-its-calculation
2. https://www.tradingview.com/script/IcKpRQ6s-SuperTrend-BF/
3. https://github.com/arkochhar/Technical-Indicators/blob/master/indicator/indicators.py#L203

I'm super confused. Please let me know if you know of something more credible, specifically the formual kite.zerodha uses.
  • Vaga
    Vaga edited December 2019
    @ziptaptoe did you verify the results with kite using all the three sources? Attached excel working of supertrend which match with kite on nifty. It's not in good format but you should be able to figure out the formulas.
  • ziptaptoe
    @Vaga Thanks! This is exactly what I needed
  • baruns
    None of them are matching with Zerodha Kite. I tested with APOLLOTYRE daily candle data. On 20 Feb 2020, it was showing as Uptrend where as in Zerodha Kite, it was Downtrend since 30 Jan 2020 till today.

    Please help if anybody having working Supertrend formula which matches Zerodha Kite indicator. Zerodha Kite is not wrong as similar trend is shown on Upstox as well as chartink.
  • baruns
    baruns edited March 2020
    I got the issue with data
  • RajeshSivadasan
    Can anyone share the buy / sell condition for supertrend indicator?
  • Vaga
    @baruns if your formula are right then it should match. It just that your initial working would not match as the numbers need to be smoothened. If you check the excel shared by me in above comments, values did not match for initial period from April 16 till June 16, after that all the values are matching. So when you building any indicator you need to give a buffer for computation to get on track.

    @RajeshSivadasan you can check inuvest.tech and build the strategy using supertrend on any stock.

  • manishareddy
    I got the issue with data
  • Thippeswamy
    @Vaga I have tried the same formula which you have used but I am not getting the exact output as compared with zerodha kite. Do we need to have previous day data for better accuracy?
  • debashis88
    Even after so much time, I am facing the same issue. Super trend values obtained from our custom definition do not match with the indicator provided on Kite Web. But I have observed those are matching with trading view indicator values.
    @kiteapi Kite Team, kindly look into this matter. If you want I can share the CSV file or script with you.
    Any future suggestions are really welcome.
  • sujith
    @debashis88,
    The indicator values are provided by the chart vendors. We don't do any kind of calculations.
  • Bharathi352
    try with the below function module for super trend .
    While I use it on 5 min candle pass day's prior(yesterday's) data also to get exact signals for current day's( which matched with zerodha)
    def Supertrend(df, atr_period, multiplier):

    high = df['high']
    low = df['low']
    close = df['close']
    y = close.shift()
    price_diffs = [high - low,
    high - close.shift(),
    close.shift() - low]
    true_range = pd.concat(price_diffs, axis=1)
    true_range = true_range.abs().max(axis=1)
    atr = true_range.ewm(alpha=1/atr_period, min_periods=atr_period).mean()
    hl2 = (high + low) / 2
    upperband = hl2 + (multiplier * atr)
    lowerband = hl2 - (multiplier * atr)
    final_upperband = upperband
    final_lowerband = lowerband
    for i in range(1, len(upperband)):
    if close[i-1] < upperband[i-1]:
    final_upperband[i] = min(upperband[i], upperband[i-1])
    else:
    final_upperband[i] = upperband[i]

    if close[i-1] > lowerband[i-1]:
    final_lowerband[i] = max(lowerband[i], lowerband[i-1])
    else:
    final_lowerband[i] = lowerband[i]

    # initialize Supertrend column to True
    supertrend = [True] * len(df)

    for i in range(1, len(df.index)):
    if (supertrend[i-1] == False and close[i] > final_upperband[i-1]):
    supertrend[i] = True
    # if current close price crosses below lowerband
    elif (supertrend[i-1] == True and close[i] < final_lowerband[i-1]):
    supertrend[i] = False
    # else, the trend continues
    else:
    supertrend[i] = supertrend[i-1]


    return pd.DataFrame({
    'Supertrend': supertrend,
    'Final Lowerband': final_lowerband,
    'Final Upperband': final_upperband})
Sign In or Register to comment.