Forex SWING Trader
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SoftKill21

//@version=4
strategy("gbpnzd 1h", overlay=true)

src = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=input.resolution, defval="60")
len = input(28, title="Moving Average Length - LookBack Period")
//periodT3 = input(defval=7, title="Tilson T3 Period", minval=1) 
factorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0) 
atype = input(2,minval=1,maxval=8,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3")

fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2000, title = "From Year", minval = 1970)
 //monday and session 
// To Date Inputs
toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2020, title = "To Year", minval = 1970)

startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = time >= startDate and time <= finishDate 

res = useCurrentRes ? timeframe.period : resCustom
resCustom2 = input(title="plm", type=input.resolution, defval="D")
res2 = resCustom2
//hull ma definition
hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
//TEMA definition
ema1 = ema(src, len)
ema2 = ema(ema1, len)
ema3 = ema(ema2, len)
tema = 3 * (ema1 - ema2) + ema3

//Tilson T3
factor = factorT3 *.10
gd(src, len, factor) => ema(src, len) * (1 + factor) - ema(ema(src, len), len) * factor 
t3(src, len, factor) => gd(gd(gd(src, len, factor), len, factor), len, factor) 
tilT3 = t3(src, len, factor) 
 

avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : atype == 7 ? 3 * (ema1 - ema2) + ema3 : tilT3

out = avg 

ema20 = security(syminfo.tickerid, res, out)



plot3 = security(syminfo.tickerid, res2, ema20)

plot33 = security(syminfo.tickerid, res, ema20)

plot(plot3,linewidth=2,color=color.red) 
plot(plot33,linewidth=2,color=color.white) 

// longC = crossover(close[2], plot3) and close[1] > close[2] and close > close[1]
// shortc = crossunder(close[2],plot3)  and close[1] < close[2] and close < close[1]

volumeMA=input(24)
ema_1 = ema(volume, volumeMA)

timeinrange(res, sess) => time(res, sess) != 0
//entrytime = timeinrange(timeframe.period, "0900-0915")

myspecifictradingtimes = input('0900-2300', type=input.session, title="My Defined Hours")


entrytime = time(timeframe.period, myspecifictradingtimes) != 0

longC = crossover(plot33,plot3)  and time_cond and entrytime
shortc = crossunder(plot33,plot3) and time_cond and entrytime

// exitlong = crossunder(plot33,plot3)
// exitshort = crossover(plot33,plot3)

distanta=input(1.0025)
exitshort = plot33/plot3 > distanta
exitlong  = plot3/plot33 > distanta

inverse = input(true)
exit = input(false)
if(inverse==false)

    strategy.entry("long",1,when=longC)
    strategy.entry("short",0,when=shortc)
if(inverse)
    strategy.entry("long",1,when=shortc)
    strategy.entry("short",0,when=longC)

if(exit)
    strategy.close("long",when=exitlong)
    strategy.close("short",when=exitshort)

// if(dayofweek==dayofweek.friday)
//     strategy.close_all()

risk = input(25)
strategy.risk.max_intraday_loss(risk, strategy.percent_of_equity)