ELIA MULTI INDICATORS STRATEGY
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ally17

//@version=4
strategy("ELIA MULTI STRATEGY",overlay=false,initial_capital=1000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.00, default_qty_value=25)


//INPUT
start = timestamp(input(2021, "start year"), 1, 1, 00, 00)
end = timestamp(input(9999, "end year"), 1, 1, 00, 00)

triggerin=input(6, title="Trigger In Value", minval=1, maxval=15)
triggerout=input(3, title="Trigger Out Value", minval=1, maxval=15)

emalen=input(80, title="Ema Len")
macdfast=input(12, title="Macd Fast Len")
macdslow=input(26, title="Macd Fast Len")
macdsig=input(12, title="Macd Signal Len")
occlen=input(15, title="Occ Len")

rsilen=input(2, title="Rsi Len")
stochklen=input(11, title="Stk K Len")
stochdlen=input(3, title="Stk D Len")
stochlen=input(3, title="Stk Smooth Len")
bblength = input(10, minval=1, title="BB Len")
mult = input(2.0, minval=0.001, maxval=50, title="BB Std Dev")

momlen=input(10, title="Mom Len")


//CALCOLI
var trigger = 0.0

var emavar = 0.0
var macdvar = 0.0
var occvar = 0.0

var rsivar = 0.0
var stochvar = 0.0
var bbvar = 0.0

var donvar =0.0

ema = ema(close,emalen)

[macdLine, signalLine, histLine] = macd(close, 12, 26, 9) // MACD

occ = ema(close,occlen) - ema(open,occlen)

rsi = rsi(close, rsilen) // RSI

stoch = sma(stoch(close, high, low, stochklen), stochlen) // Stoch

basis = sma(close, bblength)
dev = mult * stdev(close, bblength)
upper = basis + dev
lower = basis - dev

moment = mom(close, momlen) // Momentum

Obv = obv // OBV


//PLOT


//STRATEGIA
emavar := (close>ema)? 3 : -3
macdvar := (macdLine>signalLine)? 3 : -3
occvar := (occ>0)? 3 : -3

rsivar := (rsi<20)? 2 : (rsi>50 and rsi<80)? 1 : (rsi>80)? -2 : (rsi<50 and rsi>20)? -1 : 0
stochvar := (stoch<20)? 2 : (stoch>80)? -2 : 0
bbvar :=  (close<lower)? 2 : (close>upper)? -2 : 0

trigger := emavar+macdvar+occvar+rsivar+stochvar+bbvar

longcondition = trigger >= triggerin
closelong = trigger < triggerout

shortcondition = trigger <= -triggerin
closeshort = trigger > -triggerout

trendcolor = longcondition ? color.green : shortcondition? color.red : (trigger>triggerout and trigger<triggerin)? #A2E1BF : (trigger<-triggerout and trigger>-triggerin)? #E19997 : na
//bgcolor(trendcolor, transp=80)
plot(trigger, color=color.white)
hline(triggerin, title="long", color=color.green, linestyle=hline.style_dashed)
hline(0-triggerin, title="short", color=color.red, linestyle=hline.style_dashed)
hline(triggerout, title="close long",color=color.blue, linestyle=hline.style_dashed)
hline(0-triggerout, title="closeshort",color=color.blue, linestyle=hline.style_dashed)


if time > start and time < end
    if longcondition
        strategy.entry("LONG", long=strategy.long)

if closelong
    strategy.close("LONG", comment="CLOSE LONG")
    
if time > start and time < end
    if shortcondition
        strategy.entry("SHORT", long=strategy.short)

if closeshort
    strategy.close("SHORT", comment="CLOSE SHORT")

//plotshape(longcondition, color=color.green, text="L", size=size.small, style=shape.triangledown)
//plotshape(shortcondition, color=color.red, "S"(trigger), size=size.small, style=shape.triangledown)
//plotshape(closelong, color=color.purple, text="LC", size=size.small, style=shape.triangledown)
//plotshape(closeshort, color=color.purple, text="SC", size=size.small, style=shape.triangledown)
