I have the code below, is a simple strategy and somehow I manage to it up, can anyone fix this? It was working fine until I added time and ADX parts to it
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CristianPita
//@version=6
strategy("SG", overlay=true)
/////SMMA
len = input(30, minval=1, title="Length")
src = input(close, title="Source")
smma = 0.0
smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
plot(smma, color=color.red)
////EMA
len1 = input(9, minval=1, title="Length")
src1 = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
out = ema(src1, len1)
plot(out, title="EMA", color=color.blue, offset=offset)
////////////////TIME
t = time(timeframe.period, "0800-2000")
time_cond = not na(t)
/////////////ADX
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
/////////////
longCondition = (out > smma ) and (close > out)
if(longCondition and time_cond and sig>20)
strategy.entry("Longo", long=true, qty= 50000)
strategy.exit("Exit", "Longo", qty=50000, when = open < smma )
shortCondiiton = (out < smma) and ( close < out)
if(shortCondiiton and time_cond and sig>20)
strategy.entry("Shorto", long=false, qty= 50000)
strategy.exit("Exit", "Shorto", qty= 50000, when = open > smma)