CHAMELEON TRAIL
 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SeekFind
//@version=4
study("CHAMELEON TRAIL", overlay=false)

// SET THE LENGTH by doing a Cycle Analysis prior to using 

// Supertrend indicator is best to used as a filter with other indicators. 
// Useful as a filter when back testing  CHAMELEON TRADE IDEAS generation. 

// However, this indicator is not appropriate for all the situations. It works better when the market is trending (green or red background). 
// Supertrend uses only the two parameters of ATR and multiplier which are not sufficient under certain conditions to predict the accurate direction of the market.

ma(source, length, type) =>
    type == "SMA" ? sma(source, length) : 
     type == "EMA" ? ema(source, length) :
     type == "SMMA (RMA)" ? rma(source, length) : 
     type == "WMA" ? wma(source, length) :
     type == "VWMA" ? vwma(source, length) :
     na

show_ma1   = input(true , "ma1", inline="MA #1")
ma1_length = input(8     , ""     , inline="MA #1", minval=1)
ma1 = ma(close, ma1_length, "SMA")
plot(show_ma1 ? ma1 : na, color = color.yellow, title="MA №1", linewidth=3)

show_ma2   = input(true , "ma2", inline="MA #2")
ma2_length = input(21     , ""     , inline="MA #2", minval=1)
ma2 = ma(close, ma2_length, "SMA")
plot(show_ma2 ? ma2 : na, color = color.blue, title="MA №2", linewidth=3)


atrPeriod = input (15, "Length")
factor = input (3, "Factor")

[supertrend, direction] = supertrend(factor, atrPeriod)

bodyMiddle = plot((open+close)/2, display=display.none)

upm = false
downm = true
upt = true
downt = false


Lizardcolor = color.black

if direction < 0
    upt := true
    downt := false
else if direction > 0
    upt := false
    downt := true

if ma2 > ma1
    downm := true
    upm := false
else
    upm := true
    downm := true
 
if ( downm == true and downt == true )
	Lizardcolor := color.red

if ( upm == true and upt == true )
	Lizardcolor := color.green

if  ( not ( downm == true and downt == true ) and not ( upm == true and upt == true ))
	Lizardcolor := color.orange
    
plot(upt ? supertrend : na, "Up trend", color = color.green, style = plot.style_linebr, linewidth=3)
plot(downt ? supertrend : na, "Up trend", color = color.red, style = plot.style_linebr, linewidth=3)

bgcolor(Lizardcolor, 40)

alertcondition(condition= ( downm == true and downt == true ),  title="CHAMELEON TRAIL DOWN", message="CHAMELEON TRAIL DOWN - Conditions may favour SHORTS")
alertcondition(condition=  ( upm == true and upt == true ) ,  title="CHAMELEON TRAIL UP", message="CHAMELEON TRAIL UP - Conditions may favour LONGS")
alertcondition(condition= ( not ( downm == true and downt == true ) and not ( upm == true and upt == true ))  ,  title="CHAMELEON TRAIL HIDDEN", message="CHAMELEON TRAIL MIXED SIGNAL - Conditions may favour SHORTS or LONGS or NONE!")
