TrendAlert
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © qwertytehseen

//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradeWithTehseen_

//@version=5


indicator('TrendAlert', overlay=false)

// Trend and direction determination Step 1 en Step 2 method conform ZoneRecovery from 4x-dat.com Joseph Nemeth 
// https://www.youtube.com/watch?v=YxDAYtlQjBM
// step 1 LongTerm timefram/resolution (LT) determine general direction 
//•	color last Heikenahsi bar gives is the general direction 
// step 2 MidTerm timeframe/resolution determine trend
//•	color last Heikenahsi bar must match Direction step 1 and
//•	slope of 20EMA in direction step 1 and 
//•	price relation to EMA20: above = up, below=down 
// Step 1 AND step 2 => TrendAlert (-1 for Short, 1 for Long, 0 for No trend)

//Heiken Ashi Candles
data = ticker.heikinashi(syminfo.tickerid)
resLT = input.timeframe(title='Res LT', defval='D')
resMT = input.timeframe(title='Res MT', defval='240')


LTo = request.security(data, resLT, open)
LTc = request.security(data, resLT, close)
MTo = request.security(data, resMT, open)
MTc = request.security(data, resMT, close)

LTlong = LTc > LTo
LTshort = LTc < LTo
MTema20 = ta.ema(MTc, 20)
MTema20delta = ta.change(MTema20)

MTlong = MTc > MTo and MTc > MTema20 and MTema20delta > 0
MTshort = MTc < MTo and MTc < MTema20 and MTema20delta < 0



Long = MTlong and LTlong
Short = MTshort and LTshort

plot(Long ? 1 : Short ? -1 : 0, title='TrendAlert', color=Long ? color.lime : Short ? color.red : color.gray, style=plot.style_columns)

