Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Supertrend indicator #96

Open
papee opened this issue Oct 11, 2020 · 4 comments
Open

Supertrend indicator #96

papee opened this issue Oct 11, 2020 · 4 comments
Milestone

Comments

@papee
Copy link

papee commented Oct 11, 2020

Sorry if this is not the right section but could you think about adding SUPERTREND indicator please ?
here it is :
https://www.netpicks.com/supertrend-indicator/

http://www.freebsensetips.com/blog/detail/7/What-is-supertrend-indicator-its-calculation

Kind regards,

@peerchemist peerchemist added this to the 1.3 milestone Oct 21, 2020
@kitt-th
Copy link

kitt-th commented Nov 16, 2020

happy to add this (I've implemented the tradingview version of supertrend V3) when I get to tidying up the code and make my first git submission :D

@mehullala
Copy link

happy to add this (I've implemented the tradingview version of supertrend V3) when I get to tidying up the code and make my first git submission :D

Will really appreciate this feature :)

@VineethKanaparthi
Copy link

@peerchemist is there any plan to add this? I’m not that experienced in python but if you have no one else working on this, I would be happy to try implementing this

@selimozbas
Copy link

You can use this code for supertrend

get_atr = ATR(high_array, low_array, close_array, atr_period, atr_multiplier)

previous_final_upperband = 0
previous_final_lowerband = 0

previous_close = 0
previous_supertrend = 0
supertrend = []
supertrendc = 0

for i in range(0, len(close_array)):

    if np.isnan(close_array[i]):
        pass
    else:
        highc = high_array[i]
        lowc = low_array[i]
        atrc = get_atr[i]
        closec = close_array[i]
       

        if math.isnan(atrc):
            atrc = 0

        hl2 = (highc + lowc) / 2
  
        basic_upperband = hl2 + atr_multiplier * atrc
        basic_lowerband = hl2 - atr_multiplier * atrc

        if basic_upperband < previous_final_upperband or previous_close > previous_final_upperband:
            final_upperband = basic_upperband
        else:
            final_upperband = previous_final_upperband

        if basic_lowerband > previous_final_lowerband or previous_close < previous_final_lowerband:
            final_lowerband = basic_lowerband
        else:
            final_lowerband = previous_final_lowerband

        if previous_supertrend == previous_final_upperband and closec <= final_upperband:
            supertrendc = final_upperband
        else:
            if previous_supertrend == previous_final_upperband and closec >= final_upperband:
                supertrendc = final_lowerband
            else:
                if previous_supertrend == previous_final_lowerband and closec >= final_lowerband:
                    supertrendc = final_lowerband
                elif previous_supertrend == previous_final_lowerband and closec <= final_lowerband:
                    supertrendc = final_upperband

        supertrend.append(supertrendc)
        previous_close = closec
        previous_final_upperband = final_upperband
        previous_final_lowerband = final_lowerband
        previous_supertrend = supertrendc

return supertrend

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

No branches or pull requests

6 participants