PaulParticipant
Master
Hi,
You can use time to set a exit-time to close a position for intraday. But is it possible to automatically close at the last bar of a intraday chart? Which adjust itself based on timeframe. If selected daily it should be disregarded.
Regards,
Paul
I don’t think so. Would be convenient to have though.
You have to take care of this yourself and even keep in mind that there can be differences in the time when a market closes when there is a shift from summer time to winter time or vice versa. And this is different for different instruments. 🙂
Perhaps something like this? You could make an indicator that knows which bar is the last in each time frame.
IF INTRADAYBARINDEX >= 800 THEN
This won’t work. Number of bars is dependent on the TF. So I think you have to take care of this yourself.
You can recognize on which timeframe you are on with this little code snippet:
once NbBar = 1
if BarIndex < NbBar+2 then
MyDay=openday
dayminutes = 1440*(MyDay-MyDay[1])
MyHour=openhour
hourminutes = 60*(MyHour-MyHour[1])
MyMin=openminute
barminutes = MyMin - MyMin[1] + hourminutes + dayminutes
barminutes=abs(barminutes)
Mybarminutes = lowest[NbBar](barminutes)[1]
endif
return Mybarminutes as "Timeframe"
So it would be possible to set a different “intradaybarindex” for each of the found timeframe to close your orders (or event a different Time).
PaulParticipant
Master
Thanks for the responses.
That’s an interesting snippet Nicolas. It gives new possibilities to play with.
A look at intradaybarindex set as indicator shows that not everyday has the same number of bars although the longer the timeframe the more consistent they become.
Because of that I guess it doesn’t work to set a close at a specific bar based on selected timeframe.
Even if intraday bars are not the same exact number each day, a range of bars quantity could be determined for each of the timeframe?
Anyway, with the timeframe code snippet I posted, you should also be able to set a time to close the orders, for example, if the timeframe is 5 minutes, close the trade @ 235500 or if the timeframe is 1 minute, close orders @ 235900.. etc.
PaulParticipant
Master
yes set time to close orders based on timeframe should work indeed. I focused on a bar. Going to try that way! Thanks