0

I'm having trouble figuring out which tradings session any particular time is in.

There are four possible sessions, show in this picture taken from ForexFactory.com

enter image description here

I have this method that I need to check is currentTime is during the specified trading session.

public bool IsTradingSession(TradingSession tradingSession, DateTime currentTime)
{

    //Regular session is 5PM - next day 5PM, this is the session in the picture.
    //Irregular sessions also occur for example late open (3AM - same day 5PM)  or early close (5PM - next day 11AM)
    DateTime sessionStart = Exchange.CurrentSessionOpen;
    DateTime sessionEnd = Exchange.CurrentSessionClose;

    if(tradingSession == TradingSession.Sydney)
        return ....... ? true : false;
    if(tradingSession == TradingSession.Tokyo)
        return ....... ? true : false;        
    if(tradingSession == TradingSession.London)
        return ....... ? true : false;
    if (tradingSession == TradingSession.NewYork)
        return ....... ? true : false;

    return false;
}

Use:

    bool isSydneySession = IsTradingSession(TradingSession.Sydney, CurrentTime);
    bool isTokyoSession = IsTradingSession(TradingSession.Tokyo, CurrentTime);
    bool isLondonSession = IsTradingSession(TradingSession.London, CurrentTime);
    bool isNewYorkSession = IsTradingSession(TradingSession.NewYork, CurrentTime);

Thanks for any help

4

1 に答える 1

1

まず、各市場の DateTime (開始と終了) のデータソースが必要です。次に、引数に基づいて、次のcurrentTimeような簡単なチェックを行うことで、それが範囲内にあるかどうかを確認できます。

if (currentTime.Ticks >= marketOpen.Ticks && currentTime.Ticks <= marketClose.Ticks)
{
    //Market is open!
} 

上記はcurrentTime、市場と同じ時間帯にあるという仮定です。そうでない場合は、問題のすべての時刻を UTC に変換することをお勧めします。これにより、適切なタイムゾーンがあるかどうかに問題がなくなります。

于 2012-07-10T18:57:08.873 に答える