SSブログ
オリジナルEA・インジケーター制作
FX自動売買ソフト製作のMagic EA Maker

データ抽出 [FX エクセル]

[システムトレード] ブログ村キーワード お久しぶりです(^O^)/

バアルです。

データ抽出をすることができました。

歯抜けの問題は、今回抽出した分に関しては問題なかったので

スルーします^^;

おそらく条件指定してInsertとかを使えばいけると思いますが、

使うところに該当箇所がないならまあいいかということでw

Insert関数にかんしてはここが参考になりそうでした。

朝あまりに早かったり、週末の引け間際とかでマイナー通貨は

「できない」ということがあるので、データが歯抜けなんですね。

そういうところは使わないのが吉だと思います。


で、以下ができあがったもの。冗長ですw


Dim lastrow(100) As Long
Dim Youbi As Integer
Dim ZikanB As Integer
Dim ZikanE As Integer
Dim HunB As Integer
Dim HunE As Integer
Dim Hajimari As Single
Dim Owari As Single
Dim HajimariV As Single
Dim OwariV As Single
Dim ownBookName As String
Dim BookName(10) As String
Dim WBK As Workbook
Dim G As Integer
Dim f1 As String
Dim f2 As String
Dim wb As Workbook
Sub main()

Set WBK = ThisWorkbook ' 自ブック
ownBookName = WBK.Name ' 自ブック名
ChDir "C:\Users\wak\Desktop\書庫\AutoForexite\HistoricalData" '\AUDJPY\1min"
f1 = Application.GetOpenFilename("テキスト ファイル (*.txt), *.txt", , "1回目")
If f1 = "False" Then
MsgBox "キャンセル"
Exit Sub
End If
ChDir "C:\Users\wak\Desktop\書庫\AutoForexite\HistoricalData" '\AUDJPY\1min"
f2 = Application.GetOpenFilename("テキスト ファイル (*.txt), *.txt", , "2回目")
If f2 = "False" Then
MsgBox "キャンセル"
Exit Sub
End If

MsgBox f1 & " を開きます"
'Workbooks.OpenText Filename:=f1, DataType:=xlDelimited, comma:=True
Dim buf As String, n As Long
Open f1 For Input As #1
Do Until EOF(1)

Line Input #1, buf
n = n + 1
Cells(n, 1) = buf
Dim i As Long, tmp As Variant
tmp = Split(Cells(n, 1), ",")

Cells(n, 1) = tmp(0)
Cells(n, 2) = tmp(1)
Cells(n, 3) = tmp(2)
Cells(n, 4) = tmp(3)
Cells(n, 5) = tmp(4)
Cells(n, 6) = tmp(5)

Loop
Close #1

'Set wb = Workbooks.Add
MsgBox f2 & " を開きます"
'Workbooks.OpenText Filename:=f2, DataType:=xlDelimited, comma:=True
Open f2 For Input As #1
n = 0
Do Until EOF(1)

Line Input #1, buf
n = n + 1
Cells(n, 10) = buf
tmp = Split(Cells(n, 10), ",")

Cells(n, 10) = tmp(0)
Cells(n, 11) = tmp(1)
Cells(n, 12) = tmp(2)
Cells(n, 13) = tmp(3)
Cells(n, 14) = tmp(4)
Cells(n, 15) = tmp(5)

Loop
Close #1
'For n = 1 To Workbooks.Count
' BookName(n) = Workbooks(n).Name
' If BookName(n) <> ownBookName Then
' G = n
' End If
'Next n


'Workbooks(BookName(G)).Activate
lastrow(0) = Cells(1, 1).End(xlDown).Row 'MA40最終行
Youbi = InputBox("何曜日を抽出しますか?(月=1:火=2:水=3:木=4:金=5")
ZikanB = InputBox("何時からを抽出しますか?(0〜23)")
HunB = InputBox("何分から抽出しますか?(0〜59)")
ZikanE = InputBox("何時までを抽出しますか?(0〜23)")
HunE = InputBox("何分まで抽出しますか?(0〜59)")

Hajimari = 0.000694445 * 60 * ZikanB + 0.000694445 * HunB
Owari = 0.000694445 * 60 * ZikanE + 0.000694445 * HunE

For t = 0 To 10 Step 9
lastrow(0) = Cells(1, 1 + t).End(xlDown).Row 'MA40最終行
For i = 1 To lastrow(0)
Cells(i, 7 + t) = WorksheetFunction.Weekday(Cells(i, 1 + t), 1)
Cells(i, 8 + t) = Month(Cells(i, 1 + t))
Next

For i = 1 To lastrow(0)
If Cells(i, 8 + t) > 2 And Cells(i, 8 + t) < 11 Then '夏時間対応
HajimariV = Hajimari - (0.000694445 * 60)
OwariV = Owari - (0.000694445 * 60)
Else: HajimariV = Hajimari
OwariV = Owari
End If

If Cells(i, 7 + t) <> Youbi Or Cells(i, 2 + t) < HajimariV Or Cells(i, 2 + t) > OwariV Then

For ii = i To lastrow(0)
If Cells(ii, 8 + t) > 2 And Cells(ii, 8 + t) < 11 Then '夏時間対応
HajimariV = Hajimari - (0.000694445 * 60)
OwariV = Owari - (0.000694445 * 60)
Else: HajimariV = Hajimari
OwariV = Owari
End If

If Cells(ii, 7 + t) = Youbi And Cells(ii, 2 + t) > HajimariV And Cells(ii, 2 + t) < OwariV Then
'Workbooks(BookName(G)).Activate
Range(Cells(i, 1 + t), Cells(ii - 2, 8 + t)).Select
Selection.Clear
i = ii + 1
Exit For
End If
Next
End If
Next

For k = 1 To lastrow(0)
If Cells(k, 1 + t) = "" Then
For kk = k To lastrow(0)
If Cells(kk, 1 + t) <> "" Then
Exit For
End If
Next
Range(Cells(k, 1 + t), Cells(kk - 1, 9 + t)).Select
'Rows(k & ":" & kk - 1).Select
Selection.Delete shift:=xlUp
lastrow(0) = lastrow(0) - (kk - k)
If k > lastrow(0) Then
Exit For
End If
'IL = IL + 1
End If
Next k

lastrow(0) = Cells(1, 1 + t).End(xlDown).Row 'MA40最終行
For i = 1 To lastrow(0)
If Cells(i, 8 + t) > 2 And Cells(i, 8 + t) < 11 Then '夏時間対応
HajimariV = Hajimari - (0.000694445 * 60)
OwariV = Owari - (0.000694445 * 60)
Else: HajimariV = Hajimari
OwariV = Owari
End If

If Cells(i, 7 + t) <> Youbi Or Cells(i, 2 + t) > OwariV Then

Range(Cells(i, 1 + t), Cells(lastrow(0), 8 + t)).Select
Selection.Clear

If t > 0 Then
GoTo Syuuryou
End If
Exit For
End If
Next
Next t
Syuuryou:

End Sub




次回はグラフに反映して可視化します(^O^)
応援お願いします。m(__)m
↓ ↓ ↓ ↓
にほんブログ村 為替ブログ FX システムトレード派へ
にほんブログ村
nice!(0)  コメント(0)  トラックバック(0) 

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

2通貨目追加歯抜けデータを埋める ブログトップ
GMOクリック証券
GMOクリック証券

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。