# SWITCH STATS-Andean Oscillator

unknown
plain_text
a month ago
2.5 kB
2
Indexable
Never
```// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/

//@version=5
indicator("SWITCH STATS-Andean Oscillator",overlay=true)
//------------------------------------------------------------------------------
//-----------------------------------------------------------------------------{
length     = input(50)

sig_length = input(9,'Signal Length')

ScapingMode=input(true, "Plot signals")
//
//-----------------------------------------------------------------------------}
//Exponential Envelopes
//-----------------------------------------------------------------------------{
var alpha = 2/(length+1)
//
var up1 = 0.,var up2 = 0.
var dn1 = 0.,var dn2 = 0.

C = close
O = open

up1 := nz(math.max(C, O, up1[1] - (up1[1] - C) * alpha), C)
up2 := nz(math.max(C * C, O * O, up2[1] - (up2[1] - C * C) * alpha), C * C)

dn1 := nz(math.min(C, O, dn1[1] + (C - dn1[1]) * alpha), C)
dn2 := nz(math.min(C * C, O * O, dn2[1] + (C * C - dn2[1]) * alpha), C * C)

//Components
bull = math.sqrt(dn2 - dn1 * dn1)
bear = math.sqrt(up2 - up1 * up1)

signal = ta.ema(math.max(bull, bear), sig_length)

buycondition = ta.crossover(bull,signal) and  bear <=0 and close > close[1]
sellcondiion = ta.crossover(bear,signal) and  bull <=0 and close < close[1]

buyconditioncolor = bull > signal and  bear <=0
sellcondiioncolor = bear > signal and  bull <=0

plotshape(ScapingMode and sellcondiion,title="Sell",text="S",location=location.abovebar,style=shape.labeldown,textcolor=color.new(#FFFFFF,0),color=color.red)

exitsellcondition = ta.crossover(signal,bear)