チャートギャラリーの株価データを EXCELからピンポイントで参照する方法

パンローリング社の「チャートギャラリー」 というソフトは、
全銘柄の株価を過去30年分持っていて、そのデータを、
ActiveXコントロール で、VB や EXCEL等で利用することができる。

ところが、この機能については、
ソフトのヘルプ画面には記載されているが、
それ以外の情報があまりなく、
活用している人は多くないと思う。

パンローリング社のサイトで、
無料のサンプルプログラムが、
https://www.panrolling.com/etc/users/sakurai/
のサイトで公開されているけど、

株価を一括で読み出す方法は参考になるけれども、
ピンポイントで、たとえば

・「9101 日本郵船」の 「2019年7月17日」の「終値」を参照したい

というような場面で、どう使えばよいのか、分かりづらい。

メタトレーダー等、他のソフトとは違って、
「チャートギャラリー」は、プログラミングの専門家でなくても

EXCELから気軽に株価データをピンポイントで参照することができる

というのが特長であってほしい と思う。

先週、私がちょっと作ってみたので、
ノウハウを共有しておこうと思う。

「EXCELの関数」を作っておけば気軽に使える、

ので、独自関数として定義しておけばよい、ということになる。

次のような準備の後に、

・EXCELの「開発」タブの「Visual Basic」を選択

Visual Basic 設定

 

・マクロのセキュリティを押して、セキュリティセンターを表示

マクロのセキュリティ

 

・ActiveX の設定を確認

ActiveXの設定

 

・マクロの設定を確認

マクロの設定

 

・VBAの開発画面で、標準モジュールに追加して、プログラムを描き込む。

 

その後に、以下の関数を貼り付ければよい。
急いで作ったので、本格的に使うには、アレンジは必要かと思う。

関数の一覧

機能 関数名 引数 記述例
当日の始値を求める yori (銘柄コード, 取引日) =yori(1001, DATEVALUE(“2019/7/16”))
当日の高値を求める taka (銘柄コード, 取引日) =taka(1001, DATEVALUE(“2019/7/16”))
当日の安値を求める yasu (銘柄コード, 取引日) =yasu(1001, DATEVALUE(“2019/7/16”))
当日の終値を求める hike (銘柄コード, 取引日) =hike(1001, DATEVALUE(“2019/7/16”))
翌営業日の始値を求める yokuyori (銘柄コード, 取引日) =yokuyori(1001, DATEVALUE(“2019/7/16”))
翌営業日の終値を求める yokuhike (銘柄コード, 取引日) =yokuhike(1001, DATEVALUE(“2019/7/16”))
N営業日後を求める kdate (銘柄コード, 取引日, 加算日数N ) =kdate(1001, DATEVALUE(“2019/7/16”), 1)
銘柄名を求める kname (銘柄コード) =kname(1001)

 


'当日始値
Public Function yori(kcode As String, kdate As Date) As Long

    Dim Calendar As New ActiveMarket.Calendar
    Dim Prices As New ActiveMarket.Prices
    Dim DatePos As Long
    
    DatePos = Calendar.DatePosition(kdate, 1)
    
    Prices.AdjustExRights = True
    Prices.Read kcode
       
    '翌日が休場日ならば、
    If Prices.IsClosed(DatePos) Then
       DatePos = DatePos + 1
       
       '2日後が休場日ならば、
       If Prices.IsClosed(DatePos) Then
          DatePos = DatePos + 1
                
          '3日後が休場日ならば、
          If Prices.IsClosed(DatePos) Then
             DatePos = DatePos + 1
          
          End If
       End If
    End If
    
    yori = Prices.Open(DatePos)

End Function

'当日高値
Public Function taka(kcode As String, kdate As Date) As Long

    Dim Calendar As New ActiveMarket.Calendar
    Dim Prices As New ActiveMarket.Prices
    Dim DatePos As Long
    
    DatePos = Calendar.DatePosition(kdate, 1)
    
    Prices.AdjustExRights = True
    Prices.Read kcode
       
    '翌日が休場日ならば、
    If Prices.IsClosed(DatePos) Then
       DatePos = DatePos + 1
       
       '2日後が休場日ならば、
       If Prices.IsClosed(DatePos) Then
          DatePos = DatePos + 1
                
          '3日後が休場日ならば、
          If Prices.IsClosed(DatePos) Then
             DatePos = DatePos + 1
          
          End If
       End If
    End If
    
    taka = Prices.High(DatePos)

End Function

'当日安値
Public Function yasu(kcode As String, kdate As Date) As Long

    Dim Calendar As New ActiveMarket.Calendar
    Dim Prices As New ActiveMarket.Prices
    Dim DatePos As Long
    
    DatePos = Calendar.DatePosition(kdate, 1)
    
    Prices.AdjustExRights = True
    Prices.Read kcode
       
    '翌日が休場日ならば、
    If Prices.IsClosed(DatePos) Then
       DatePos = DatePos + 1
       
       '2日後が休場日ならば、
       If Prices.IsClosed(DatePos) Then
          DatePos = DatePos + 1
                
          '3日後が休場日ならば、
          If Prices.IsClosed(DatePos) Then
             DatePos = DatePos + 1
          
          End If
       End If
    End If
    
    yasu = Prices.Low(DatePos)

End Function

'当日終値
Public Function hike(kcode As String, kdate As Date) As Long

    Dim Calendar As New ActiveMarket.Calendar
    Dim Prices As New ActiveMarket.Prices
    Dim DatePos As Long
    
    DatePos = Calendar.DatePosition(kdate, 1)
    
    Prices.AdjustExRights = True
    Prices.Read kcode
       
    '翌日が休場日ならば、
    If Prices.IsClosed(DatePos) Then
       DatePos = DatePos + 1
       
       '2日後が休場日ならば、
       If Prices.IsClosed(DatePos) Then
          DatePos = DatePos + 1
                
          '3日後が休場日ならば、
          If Prices.IsClosed(DatePos) Then
             DatePos = DatePos + 1
          
          End If
       End If
    End If
    
    hike = Prices.Close(DatePos)

End Function

'翌営業日の始値
Public Function yokuyori(kcode As String, kdate As Date) As Long

    Dim Calendar As New ActiveMarket.Calendar
    Dim Prices As New ActiveMarket.Prices
    Dim DatePos As Long
    
    DatePos = Calendar.DatePosition(kdate, 1) + 1
    
    Prices.AdjustExRights = True
    Prices.Read kcode
       
    '翌日が休場日ならば、
    If Prices.IsClosed(DatePos) Then
       DatePos = DatePos + 1
       
       '2日後が休場日ならば、
       If Prices.IsClosed(DatePos) Then
          DatePos = DatePos + 1
                
          '3日後が休場日ならば、
          If Prices.IsClosed(DatePos) Then
             DatePos = DatePos + 1
          
          End If
       End If
    End If
    
    yokuyori = Prices.Open(DatePos)

End Function

'翌営業日の終値
Public Function yokuhike(kcode As String, kdate As Date) As Long

    Dim Calendar As New ActiveMarket.Calendar
    Dim Prices As New ActiveMarket.Prices
    Dim DatePos As Long
    
    DatePos = Calendar.DatePosition(kdate, 1) + 1
    
    Prices.AdjustExRights = True
    Prices.Read kcode
       
    '翌日が休場日ならば、
    If Prices.IsClosed(DatePos) Then
       DatePos = DatePos + 1
       
       '2日後が休場日ならば、
       If Prices.IsClosed(DatePos) Then
          DatePos = DatePos + 1
                
          '3日後が休場日ならば、
          If Prices.IsClosed(DatePos) Then
             DatePos = DatePos + 1
          
          End If
       End If
    End If
    
    yokuhike = Prices.Close(DatePos)

End Function

'取引日
Public Function kdate(kcode As String, startdate As Date, addcount As Integer) As Long

    Dim Calendar As New ActiveMarket.Calendar
    Dim Prices As New ActiveMarket.Prices
    Dim DatePos As Long
    
    DatePos = Calendar.DatePosition(startdate, 1) + addcount
    
    Prices.AdjustExRights = True
    Prices.Read kcode
    
    '翌日が休場日ならば、
    If Prices.IsClosed(DatePos) Then
       DatePos = DatePos + 1
       
       '2日後が休場日ならば、
       If Prices.IsClosed(DatePos) Then
          DatePos = DatePos + 1
                
          '3日後が休場日ならば、
          If Prices.IsClosed(DatePos) Then
             DatePos = DatePos + 1
          
          End If
       End If
    End If
    
    kdate = Calendar.Date(DatePos)

End Function

'銘柄名
Public Function kname(kcode As String) As String

    Dim Names As New ActiveMarket.Names
    Dim C() As String, N() As String
    
    Names.AllNames AM_KINDFLAG_SPOTS, C, N
    
    mpos = Application.Match(kcode, C, False)
    
    If IsError(mpos) Then
       kname = mpos
    Else
       kname = N(mpos)
    End If
    
End Function

 

「チャートギャラリーの株価データを EXCELからピンポイントで参照する方法」への3件の返信

  1. 内容は分かりました。ありがとうございます。
    細野さんのトレード練習 損益計算シート ver2.03を起動して、銘柄名に別のコードを入力しても何の変化がありません。
    チャートギャラリーも起動しております。
    EXCELで開発でVBAも使用できる状態になってるようです。
    もう少し使い方を教えて頂けませんでしょうか。
    よろしくお願い致します。

  2. インターネットからダウンロードしたままの状態で開くと、
    セキュリティが最高の状態で開くので、
    VBAがどうやっても動作しないかもしれません。

    ですので、ダウンロードしたZIPファイルを一旦、
    PCのローカルハードディスク(Dドライブ等)で完全に解凍して

    「トレード練習の損益計算v203.xlsm」

    というファイル名になった後に、EXCELで開いてみて下さい。

  3. 株式分割や併合があった銘柄は、

    Prices.AdjustExRights = True

    という行を入れておくと、
    調整後の株価が取得できるので、
    これを入れることにしました。

コメントは受け付けていません。


My Company Links

合資会社ユースマネージメント
ドメインサービス
インターネット活用の入り口

My Website Links

細野俊一のトレーディング日記
日経225+JPX400銘柄の PPP(パンパカパン) 一覧
株価指数+外国為替(FX)の PPP(パンパカパン) 状態
「生命の科学」学習メモ
大安心と大冒険を求めて

Facebook Pages

ポイント&フィギュア活用研究会
合資会社ユースマネージメント
アダムスキー「生命の科学」活用研究会
細野俊一 (宇宙哲学研究家)