Thanks! I found out the next code. I will see what happens on live but with backtesting it is not trading (though there are no night bars as well for history data):

if (hour(0)==21 || hour(0)==22 ||hour(0)==23 ||hour(0)==0 ||hour(0)==1 ||hour(0)==2 ||hour(0)==3 ||hour(0)==4 ||hour(0)==5 ||hour(0)==6)
{TimeFrame=0;}
if (hour(0)==7 && minute(0)==1) {TimeFrame=-40;} //on M15, market is closed between 9:00PM-6:59AM
if (hour(0)==7 && minute(0)==2) {TimeFrame=1;}

Originally Posted By: jcl
There are 3 ways to get overnight bars:

- Setting Weekend at 0
- Trading another asset at the same time that is traded overnight.
- The asset still gets some price quotes overnight. This sometimes happens with CFDs.

You can use the TimeFrame mechanism for skipping overnight bars so that they don't affect indicators. Set TimeFrame to 0 when the market closes, count the skipped bars, set TimeFrame to the negative number of skipped bars when the market opens again, and to 1 while the market is open.

Last edited by konorti; 03/11/17 15:09.