Exit from position in exact time

220 views Asked by At

Help me please) I want to add exit from position in 22:00 every day and new input in the morning at 11:00.

// MA
len = input(6, minval=1, title="Length")
src = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
out = sma(src, len)
plot(out, color=color.blue, title="MA", offset=offset)

price = close
x = price > out
x2 = price < out

//Logic
if (out > out[1]) and metka and x 
    strategy.entry("ConsUpLE", strategy.long, comment="ConsUpLE")

if (out < out[1]) and metka and x2 
    strategy.entry("ConsDnSE", strategy.short, comment="ConsUpLE")
1

There are 1 answers

0
e2e4 On

You can use the hour function and specify any hour. Note that:

1)You have to stay on intraday chart

2)hour function use the exchange's timezone that could differ from your's.

timeIs2200 = hour == 22 ? true : false
// highligh the bar
bgcolor(timeIs2200 ? color.red : na, transp = 0)

Then use this boolean as a trigger for your exit condition

if timeIs2200
    ...