Hi, how can I sell on the close of this bar or on the opening of the next, preferably on the close.
It is impossible to sell at the close of a bar as all orders (except pending ones) are carried out at the next bars open.
You could use MTF to create a simulated candle so as to trade at a time that is very close to say the 1 hour bars close by trading at the 59 minutes and 58 seconds bar which would mean that your trade opens just 1 second before the 1 hour bar closes. There is not much benefit to this though unless the instrument that you are trading has large gaps in price from close to open.
Thanks, I understand, do you know how to sell at the open of the next bar in code?
If you are on the market then any SELL (for long) or EXITSHORT (for short) instruction will close positions at the open of the next bar.
Ok, sorry for asking such fundamental questions. Just double checking, if I issue a SELL or EXITSHORT on the Monday of a weekly bar there will be a SELL/EXITSHORT in 7 days?
You simply cannot sell on a Monday, because you can only place entry/exit orders at market when a bar closes.
So if you SELL/EXITSHORT when the weekly bar closes, it will be executed when the next one opens.