0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OANDAのAPIを利用して4時間足のサポートレジスタンスを判断するコード

Posted at

表題について書いていきます。
取り敢えず暫定的なものなので、後々更新するかも…

import oandapyV20
import oandapyV20.endpoints.instruments as instruments
import pandas as pd
import datetime

# OANDAのアクセストークンとアカウントID
access_token = 'YOUR_OANDA_ACCESS_TOKEN'
account_id = 'YOUR_OANDA_ACCOUNT_ID'

# APIクライアントの初期化
client = oandapyV20.API(access_token=access_token)

# 通貨ペアと時間足の設定
instrument = "EUR_USD"
granularity = "H4"

# 過去3か月分のデータ取得
end = datetime.datetime.now()
start = end - datetime.timedelta(days=90)
params = {
    "from": start.strftime('%Y-%m-%dT%H:%M:%SZ'),
    "to": end.strftime('%Y-%m-%dT%H:%M:%SZ'),
    "granularity": granularity,
}

# APIリクエストの作成と実行
candles = instruments.InstrumentsCandles(instrument=instrument, params=params)
client.request(candles)
data = candles.response['candles']

# データフレームの作成
df = pd.DataFrame([{
    'time': candle['time'],
    'open': candle['mid']['o'],
    'high': candle['mid']['h'],
    'low': candle['mid']['l'],
    'close': candle['mid']['c'],
    'volume': candle['volume']
} for candle in data])

# 高値と安値で止まったラインを見つけるロジックの実装
df['high_swing'] = df['high'].rolling(window=10).max()
df['low_swing'] = df['low'].rolling(window=10).min()

# 結果の表示
print(df[['time', 'high', 'low', 'high_swing', 'low_swing']])

全体としてのコードは以上になります。
時間軸や通貨ペアを変更したいときは

# 通貨ペアと時間足の設定
instrument = "EUR_USD"
granularity = "H4"

ここの部分を変更してください。
期間の変更はここのdays = 90の部分を変えると良いです。
90日なので正確に3か月ではないですが…

# 過去3か月分のデータ取得
end = datetime.datetime.now()
start = end - datetime.timedelta(days=90)
params = {
    "from": start.strftime('%Y-%m-%dT%H:%M:%SZ'),
    "to": end.strftime('%Y-%m-%dT%H:%M:%SZ'),
    "granularity": granularity,
}

このコードで過去3か月にわたる4時間足でのサポートレジスタンスラインの発見をすることができると思います(後でちょっと動かしてみます)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?