How do i open a trade at a specific time? Like if i want to open a trade at 9:30 am and then exit the trade at 3:00 pm
Welcome to the BEST forum for traders
Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".
How do i open a trade at a specific time? Like if i want to open a trade at 9:30 am and then exit the trade at 3:00 pm
A simple example that you can adapt to your example
//@version=4
study("Detecting a specific time (in the exchange's timezone)", "", true)
targetYear = input(0, "Year (use 0 for all)", minval = 0)
targetMonth = input(0, "Month (use 0 for all)", minval = 0, maxval = 12)
targetDay = input(0, "Day (use 0 for all)", minval = 0, maxval = 31)
targetHour = input(24, "Hour (use 24 for all)", minval = 0, maxval = 24)
targetMinute = input(60, "Minute (use 60 for all)", minval = 0, maxval = 60)
targetSecond = input(60, "Second (use 60 for all)", minval = 0, maxval = 60)
// Detect target date/time or greater, until the next higher generic value (i.e., using its default value in Inputs) changes.
targetReached =
(targetYear == 0 or year >= targetYear) and
(targetMonth == 0 or month >= targetMonth) and
(targetDay == 0 or dayofmonth >= targetDay) and
(targetHour == 24 or hour >= targetHour) and
(targetMinute == 60 or minute >= targetMinute) and
(targetSecond == 60 or second >= targetSecond)
// Plot light bg whenever target date/time has been reached and next period hasn't reset the state.
bgcolor(targetReached ? color.green : na, title = "In allowed time")
// Plot brighter bg the first time we reach the target date/time.
bgcolor(not targetReached[1] and targetReached ? color.lime : na, 50, title = "Entry into allowed time")
// Save open at the beginning of each detection of the beginning of the date/time.
var float savedOpen = na
if not targetReached[1] and targetReached
savedOpen := open
plot(savedOpen, "Saved open", change(savedOpen) ? na : color.gray, 3)
// Plot current bar's date/time in the Data Window.
plotchar(year, "year", "", location.top)
plotchar(month, "month", "", location.top)
plotchar(dayofmonth, "dayofmonth", "", location.top)
plotchar(hour, "hour", "", location.top)
plotchar(minute, "minute", "", location.top)
plotchar(second, "second", "", location.top)
I want to create a strategy which enters a long position at a specific time @ 10 am and exit the trade at 11 am and backtest it for the last few months on tradingview.
is there a simple code like if time= 10 am enter long and exit long position at 11 am which i can backtest in strategy tester
thank you i got the code
Anonymous:
thank you i got the code
Can you tell me the code? Thanks
Anonymous:
I want to create a strategy which enters a long position at a specific time @ 10 am and exit the trade at 11 am and backtest it for the last few months on tradingview.
Can u send that code in chat?
is there a simple code like if time= 10 am enter long and exit long position at 11 am which i can backtest in strategy tester - Is it possible share the code for the same?