get rid of empty bars when market is closed (between days)

Posted By: konorti

get rid of empty bars when market is closed (between days) - 03/09/17 19:21

I try my code on demo fxcm server. How can I get rid of these empty bars (not seen during backtest) when the market was closed? An indicator will use these bars for the calculation which is not good. Sorry for the small screenshot, it was taken on GER30 but it is similar to any indices that the market is closed for the night but FXCM generates a bar with same OHLC. The problem is that it affects the indicators.

Posted By: jcl

Re: get rid of empty bars when market is closed (between days) - 03/10/17 11:43

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.
Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 03/11/17 15:09

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.
Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 03/15/17 15:03

Unfortunatelly it doesnt work. Any idea why these bars appear or whdt is the problem with my code?


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.
Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 05/07/17 19:34

I tried to skip these bars different ways but couldnt. Can somebody try on FXCM demo (only GER30 is traded) to somehow get rid of them? Any code would be fine, just not to see those empty bars while market is closed. Thanks!
Posted By: jcl

Re: get rid of empty bars when market is closed (between days) - 05/09/17 12:18

I'll look into that.

- Update: The bars are probably ok. FXCM apparently sends GER30 price quotes all around the clock, so you still get bars and see them in the chart.

If you don't want those bars, use the TimeFrame mechanism as described. Of course you'll then still see the bars in the chart, but they won't affect the series and indicators.
Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 05/12/17 13:35

Thanks! Still i dont understand that when i download history from the server, these bars are not there. My live trades are different than what i have backtested. Timeframe mechanism didnt work for me. I tried the demo trading on mt4 than i had trading errors with limit orders not being enterred as they were too close to market price. For me would be advantage to trade with fxcm, but can try to fix this stop level issue with mt4 bridge (or maybe this was already fixed as i tried this with 1.51 version only)
Posted By: jcl

Re: get rid of empty bars when market is closed (between days) - 05/15/17 07:43

I cannot answer the question why the prices outside market hours are removed from the price history, but when you ask FXCM they probably have an answer.

Why does the timeframe mechanism not work for you?
Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 05/17/17 05:33

The bars are still there with the code above. I tried to also remove each bar after it closed and had same high and low value. They are just there. Maybe the code has error, but after changing sg i have to wait for a night to test it laugh
Posted By: jcl

Re: get rid of empty bars when market is closed (between days) - 05/17/17 08:24

Yes, that's what I said - the bars won't go away, so you need to set TimeFrame to 0 when you don't want them to affect your series.

Code:
static int SkippedBars = 0;
if(between(hour(),21,6)) {
  TimeFrame = 0;
  SkippedBars--; 
} else if(TimeFrame == 0)
  TimeFrame = SkippedBars;
  SkippedBars = 0;
} else {
  TimeFrame = 1;
}

Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 05/18/17 08:51

Thanks! It looks different than my code, hopefully helps, i will report back on result.
Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 05/22/17 07:38

I made a test program just having codes given by you and adding BarPeriod 15, but the bars still come back. Is there anything missing in my code?
I will try on Real FXCM server tonight, maybe it is different.

Code used:
Quote:

function run()
{

BarPeriod = 15;
static int SkippedBars = 0;

if(between(hour(),21,6)) {
TimeFrame = 0;
SkippedBars--;
}

else if(TimeFrame == 0) {
TimeFrame = SkippedBars;
SkippedBars = 0;
}

else {
TimeFrame = 1;
}}


Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 05/23/17 07:45

It is the same on Live server (with version 1.56). Do you have any other method for removing these bars? Thanks!

Posted By: konorti

Re: get rid of empty bars when market is closed (between days) - 05/25/17 08:23

Comparison of indicator before and after empty bars ( this didnt happen when was trying to trade it on MT4 bridge):

© 2024 lite-C Forums