pine-scriptpine-script-v5pine-script-v6

Supertrend delivers opposite result


I want to check in the current Timeframe (as example 5 min ), the supertrend in the 60min timeframe. But the supertrend delivers allways opposite results. If it is true the backcolor should be blue.

I tried with direction > 0, > 1 with 1 no result, and with 0 shows allways the wrong = the Shortsetup, instead of the longsetup of the Supertrend. ( direction > 0 = Longsetup)

Do anyone have advise for me? Maybe I'm completly confused and cant see the tree in front of me, standing in the wood :-).

//@version=6
indicator("Z-Score Indikator", overlay=true)

// Eingabeparameter
supertrendFactor   = input.int(3,   "Supertrend Faktor")
supertrendATR      = input.int(10,      "Supertrend ATR Perioden")

// 3. H1 Supertrend Richtung
[h1Supertrend, h1Direction] = request.security(syminfo.tickerid, "60", ta.supertrend(supertrendFactor, supertrendATR))
condition3 = h1Direction > 0

bgcolor(condition3 ? color.new(color.blue, 85) : na)

kind regards


Solution

  • Your code is fine. But you need to read the documentation.

    RETURNS
    Tuple of two supertrend series: supertrend line and direction of trend. Possible values are 1 (down direction) and -1 (up direction).

    So, up trend is indicated by direction < 0 actually.

    enter image description here