How to trade "day" bar in Oanda data?

 

Hi everyone. I'm a newbie of EA trader.

Actually, I'm not using the EA in MT5, but storing the data csv out from the MT5, using my own Python engine to backtest and develop strategy.

Lately, I was trying to implement strategy with day bar which potientially could lowerize the effect of transmission costs.

However, when checking the day bar, I found that the sepatation point of time is "00:00".

In most of the simple EAs I guess, which means it would check the final OHLVC in E.g. 3/1, 23:57, and decide whether to open position at 3/2 00:03 in Oanda case.

By doing so, you would trade in a time that the market has lowest liquidity! Check the attaching figure:

(By the way, I think 00:00 in Oanda is UTC+2/UTC+3 based on summar/winter)

In the figure, although the ask price is not shown, but the spread in this time would be 3~4 times bigger than the spread in the other time.

So in this case, no matter you're buying long or selling short, it wouldn't be really worth it with such a high spread.


I'm curious how do you guys deal with this issue.

Do you add a time offset in the data? Like using the day bar data which is 3/1 12:00, 3/2 12:00 for indicator and trading time.

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
Files:
1.png  121 kb
 

wanga20000:

(By the way, I think 00:00 in Oanda is UTC+2/UTC+3 based on summar/winter)

I'm curious how do you guys deal with this issue.

Do you add a time offset in the data? Like using the day bar data which is 3/1 12:00, 3/2 12:00 for indicator and trading time.

  1. Oanda is NY+7

    Chart times are broker times.

    1. How can MetaQuotes know all brokers' (they come and go daily) Time zone and Daylight savings time (if they use it and including historical changes for back testing)? Do you have that information for just you and your broker? Only then, with code, can you convert session times to broker's time to UTC to local time. You can use offset inputs, but then you must maintain them correctly, through all three DST changes when they occur.
                When is the time zone problem going to be fixed? - General - MQL5 programming forum (2020)

    2. Foreign Exchange (FX) market opens 5 PM New York (NY)/Eastern Time (ET) Sunday and ends 5 PM NY Friday. Some brokers start after (6 PM is common) and end before (up to 15 minutes) due to low volatility.
                Checking for Market Closed - Expert Advisors and Automated Trading - MQL5 programming forum (2016)

      Swap is computed 5 PM ET. No swap if no open orders at that time.

    3. Brokers use a variety of time zones. Their local time, with or without Daylight Savings Time (DST), London, UTC, London+2, UTC+2, NY+7.

      Only with NY+7 does the broker's 00:00 equals 5 PM ET and the start of a daily bar (and H4) is the start of a new FX day.

      GMT/BST brokers, means there is a 1 or 2 hour D1/H4 bar on Sunday (depending on NY DST), and a short Friday bar. (Problems with indicators based off bars.)

      GMT+2 is close but doesn't adjust for NY DST.

      EET is closer, except when their DST doesn't match NY's. Last Sunday of March and 1:00 on the last Sunday of October vs second Sunday in March and return at 2:00 AM EDT to 1:00 AM EST on the first Sunday in November.

    4. Non-NY+7, means the chart daily bar overlaps the start, and converting broker time to NY time requires broker to UTC to NY timezone conversions.


    5. If you search the web, you will find differing answers. Those are all wrong (half the year) because they do not take DST into account (or that it changed for the US in 2007 [important when testing history.])


    6. Then there are (non-24 hour markets) with H4 candles that start on odd hours.
                Why My XAUUSD 4H candles start with 1 hour shift? - Currency Pairs - General - MQL5 programming forum (2019)
                H4 first opened candle - MT5 - General - MQL5 programming forum (2020)

      And H1 on the half hour.

    7. See also Dealing with Time (Part 1): The Basics - MQL5 Articles (21.10.01)
      and Dealing with Time (Part 2): The Functions - MQL5 Articles (21.10.08)

  2. What issue?
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  3. The daily bar starts at 3/1 00:00

 
William Roeder #:
  1. Oanda is NY+7
  2. What issue?
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  3. The daily bar starts at 3/1 00:00

Hi, thanks for the replying.
1. Not swap, the issue I'm discussing with is the high spread and low liquidity at 00:00 ( NY+7 ) in Oanda data.

2. If using EA and day bar, most of them would decide whether or not opening position at 00:03, which might give high spread at the moment.
So how do people deal with the day bar with 00:00 is NY+7? 

3. That's what I think if adding time offset would become. The original one is 3/1 00:00, after that would be 3/1 12:00. 

 
wanga20000 #: ... the issue I'm discussing with is the high spread and low liquidity at 00:00 ( NY+7 ) in Oanda data ... If using EA and day bar, most of them would decide whether or not opening position at 00:03, which might give high spread at the moment ... So how do people deal with the day bar with 00:00 is NY+7? 

There is no "rule" that says you have to place your trade at 00:00.

As long as the entry conditions for your strategy still hold, you can wait it out for a better spread condition, be it at 00:03 or even 01:00.

Adjust your strategy rules in accordance with the required market conditions.

 
wanga20000 #: So how do people deal with the day bar with 00:00 is NY+7?

Different people, different ways. I just ignore ticks with spread greater than twice average.

Not tested, not compiled, just typed.

      #define EMA(P,C,L)  EMAa(P,C,2./((L)+1))
      #define EMAa(P,C,A) ((P) + ((C)-(P))*A)
      // //en.wikipedia.org/wiki/Generalized_mean#Special_cases (Power Mean)
      #define PMA(P,C,L,PM)  MathPow( EMA(MathPow(P,PM),MathPow(C,PM),L),1.0/PM)
struct Spread{
   double     mSpreadAve, mSpreadMax; int mCount;
              Spread() : mCount(0){}
   bool       on_tick(){
      double  spreadCur = Ask - Bid;
      if(count < 400000) ++mCount; // CHFZAR=393k/day
      mSpreadAve  = EMA(mSpreadAve, spreadCur, mCount);
      mSpreadMax  = PMA(mSpreadMax, spreadCur, mCounr, 20);

      spreadAve += 2.0/(count+1) * (spreadCur - spreadAve);
      return spreadCur > 2*spreadAve;
   }
};

void OnTick(){
    static Spread spread;
    if(spread.on_tick() ) return;

Not tested, not compiled, just typed.

 

Hi folks, thanks for the replying again.
I think I know how to handle this in my own engine based on your suggestion.

In my case, I would backtest a day bar strategy hourly, so the open rules follow the day, but the time to open follow the hour.

Thanks for helping.

Reason: