SWITCH STATS-Andean Oscillator

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.5 kB
3
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 buycondition,title="Buys",text="B",location=location.belowbar,style=shape.labelup,textcolor=color.new(#FFFFFF,0),color=color.green)
plotshape(ScapingMode and sellcondiion,title="Sell",text="S",location=location.abovebar,style=shape.labeldown,textcolor=color.new(#FFFFFF,0),color=color.red)

exitbuycondition = ta.crossover(signal,bull) 
exitsellcondition = ta.crossover(signal,bear) 

plotshape(ScapingMode and exitbuycondition,title="Exit Buy",location=location.abovebar,style=shape.xcross,textcolor=color.new(#FFFFFF,0),color=color.purple,size=size.tiny)
plotshape(ScapingMode and exitsellcondition,title="Exit Sell",location=location.belowbar,style=shape.xcross,textcolor=color.new(#FFFFFF,0),color=color.purple,size=size.tiny)


barcolor(ScapingMode and buyconditioncolor ? color.teal : na)
barcolor(ScapingMode and sellcondiioncolor ? color.orange : na)
alertcondition(buycondition or sellcondiion, "Andean Oscillator Entry")
alertcondition(exitbuycondition or exitsellcondition, "Andean Oscillator Exits")



Leave a Comment