Excel和VBA分析
1 頁面的第 565 頁 123 ... 上一個上一個
Results 1 to 10 of 41

Thread: Excel和VBA分析

  1. #1
    歡迎,

    我將這個主題推向Excel工作表的演變。

    我希望它成為分析天堂,我準備獨自一人與我的小進化。您可能偶爾會看一下,因為我將發布我的VBA腳本,希望有些專業人員會出現並糾正我。在我的交易生涯中,我有很多次需要分析一些時間服務,並且經常想從一些奇怪的角度來看待它。不幸的是我是IT analphabet。所以我學會了編寫VBA基礎知識,將它編碼為豬,但不知何故它起作用了,我得到了我需要的東西。

    出於某種原因,我相信你們中的一些人現在或處於相同的情況,我相信如果我們分享我們的VBA代碼和優秀的組合,我們可以做出相當不錯的東西。

    我也在使用這個論壇作為代碼商店,所以他們在一個地方。我鼓勵你幫助我進化這些。如果你知道如何改進它,請說出來。

    免責聲明:這些是非常愚蠢的代碼。如果您打算使用它們,請確保在運行宏之前了解它們的用途並首先保存數據。所有代碼均已在VBA Excel 2010中編寫。

    要添加一個線程規則:
    請盡量堅持下去。也歡迎ACDC。

    請享用,

    湯姆

  2. #2
    所以我需要保存的第一個小代碼。我有時候在下載時間表的時候做了這個,不同的國家有不同的時間和日期格式,並且不能讀取日期。只是為了讓熱點改變所有那些錯誤的日期。 'datecrush Set rng = Range(Cells(1,1),Cells(1,1).End(xlDown))For each b in rng b.Offset(0,7).Value =(Left(b.Value,4) ) - 中(b.Value,6,2) - 右(b.Value,2))Next for Each b In rng b.Value = b.Offset(0,7).Value Next rng.NumberFormat = dmyyyy Second一個真的很亂。此代碼用於粉碎以* .csv格式導出的數據,並將其更改為只有關閉和日期的可讀時間序列。已經過MT4的每日歐盟Oanda數據測試。日期有一個小錯誤,現在正在修復 - 使用代碼no1。認為所有MT4出口都應該是一樣的。 Sub datecrushMT4Daily()'重新啟動工作表壓碎和最終Appliion.DisplayAlerts = False工作表(Data_crushed).Delete Worksheets.Add.Name = Data_crushed工作表(Data_crushed).Move After:= Worksheets(Data)工作表(Data_final).Delete Worksheets.Add .Name = Data_final Worksheets(Data_final).Move After:= Worksheets(Menu)Appliion.DisplayAlerts = True Appliion.ScreenUpdating = False'Date crush - MT4 Daily Worksheets(Data).Activate Range(Cells(1,1),Cells( 1,7).End(xlDown))。複製工作表(Data_crushed)。激活ActiveSheet.Paste'列分隔列(A:A)。選擇Selection.TextToColumns目的地:=範圍(A1),DataType:= xlDelimited,_ TextQualifier := xlDoubleQuote,ConsecutiveDelimiter:= False,Tab:= True,_分號:= False,逗號:= True,空格:= False,其他:= False,FieldInfo _:= Array(Array(1,4),Array( 2,4),數組(3,1),數組(4,1),數組(5,1),數組(6,1),_數組(7,1)),DecimalSeparator:=。,TrailingMinusNumbers:=真實範圍(G14)。選擇'視覺列(B)。刪除列(g) .ClearContents Rows(1:1).Insert Shift:= xlDown,CopyOrigin:= xlFormatFromLeftOrAbove Range(A1).FormulaR1C1 = Date Range(b1).FormulaR1C1 = Open Range(c1).FormulaR1C1 = High Range(d1).FormulaR1C1 =低範圍(e1).FormulaR1C1 =關閉範圍(f1).FormulaR1C1 =音量'移動到最終列表範圍(A:A,E:E)。複製工作表(Data_final)。激活表格(Data_final)。選擇ActiveSheet.Paste End子

  3. #3
    1附件這是一個簡單的MM excel表,用於管理歐盟和UJ的交易。這只是一種方式
    但如果你願意,你可以調整它。如果您發現一些錯誤,請報告。除了那些條目之外,數字是假的。
    https://www.forex-pedia.com/attachme...352376108.xlsx

  4. #4
    好的,我已經做到了。這一切都在這件小事上。如果您希望將文本格式轉換為日期,則默認.xls格式為yyyy-mm-dd。意思是如果像我一樣原始,你只是以某種方式強迫它內在和完成!所以這個工作,已經在0anda MT4出口月度,周刊和每日測試。 FF不會讓我在這裡上傳.xlsm,所以我描述它是如何工作的。您製作了一個包含四個列表的Excel工作表,名為Menu Data_crushed Data_final和Data。進入MT4圖表後,按ctrl s並保存* .csv。將數據從* .csv複製到列表數據。運行宏。它會將日期壓縮為可讀格式並且只選擇關閉,因此您可以快速製作圖表。壓碎的紙張數據包含所有OHLC和卷,最終只有那些關閉。享受,T。sub datecrushMT4Daily()'重啟工作表壓碎和最終Appliion.DisplayAlerts = False工作表(Data_crushed).Delete Worksheets.Add.Name = Data_crushed工作表(Data_crushed).Move After:= Worksheets(Data)工作表(Data_final)。刪除Worksheets.Add.Name = Data_final工作表(Data_final).Move After:=工作表(菜單)Appliion.DisplayAlerts = True Appliion.ScreenUpdating = False'Date crush - MT4 Daily Worksheets(Data).Activate Range(Cells,1,1) ),Cells(1,7).End(xlDown))。複製工作表(Data_crushed)。激活ActiveSheet.Paste列(A:A)。選擇Selection.TextToColumns目的地:=範圍(A1),DataType:= xlDelimited,_ TextQualifier:= xlNone,ConsecutiveDelimiter:= False,Tab:= True,分號_:= False,逗號:= True,空格:= False,其他:= False,FieldInfo:= Array(_ Array(1,4),Array (2,4),數組(3,1),數組(4,1),數組(5,1),數組(6,1),數組(7,1)),_ DecimalSeparator:=。,TrailingMinusNumbers: = True Selection.NumberFormat = [$ -F800] dddd,mmmm dd,yyyy'datecrush Set rng =範圍(單元格(1,1),單元格(1,1).End(xlDown))對於每個b在rng b.Offset(0,7).Value =(左(b.Value,4) - Mid (b.Value,6,2) - 右(b.Value,2))下一個rng.NumberFormat = [$ -F800] dddd,mmmm dd,yyyy'rng.NumberFormat = dmyyyy For each b in rng b.Value = b.Offset(0,7).Value Next'visual Columns(B).Delete Columns(g).ClearContents Rows(1:1).Insert Shift:= xlDown,CopyOrigin:= xlFormatFromLeftOrAbove Range(A1).FormulaR1C1 =日期範圍(b1).FormulaR1C1 =開放範圍(c1).FormulaR1C1 =高範圍(d1).FormulaR1C1 =低範圍(e1).FormulaR1C1 =關閉範圍(f1).FormulaR1C1 =音量'移動到最終範圍(A:A) ,E:E)。複製工作表(Data_final)。激活表格(Data_final)。選擇ActiveSheet.Paste End Sub

  5. #5

  6. #6
    嘿湯姆,看起來你正在使用很多錄製的宏vba。請注意,記錄的vba可能會失敗,因為活動的單元格/工作表/等與錄製時的活動狀態相關,除非您專門選擇某個活動單元格。最好使用Excel工作簿/工作表/範圍對像模型,並明確地將事物分配給變量和範圍對象。這是一種更加準確和可擴展的方法。我一直在整理一些用於處理MT4輸出的代碼如果你有興趣我會發布。您是否有使用類和對象的開發經驗?

  7. #7
    順便說一下,如果有人有excel請求,請將它們發布。我是一個非常先進的VBA開發人員,並在Excel中構建了一些非常強大的圖表應用程序。我不會為你建立一個應用程序,但我可以幫助解決任何vba問題/任務。我不能保證快速轉身,但是嘿......你得到的東西是免費的。這個優惠永遠不會擺在桌面上,所以請充分利用它。

  8. #8
    Quote Originally Posted by ;
    嘿湯姆,看起來你正在使用很多錄製的宏vba。請注意,記錄的vba可能會失敗,因為活動的單元格/工作表/等與錄製時的活動狀態相關,除非您專門選擇某個活動單元格。最好使用Excel工作簿/工作表/範圍對像模型,並明確地將事物分配給變量和範圍對象。這是一種更加準確和可擴展的方法。我一直在整理一些用於處理MT4輸出的代碼如果你有興趣我會發布。你有任何開發經驗嗎?
    嗨JR。謝謝你的表現。請告訴我如何使用類和對象
    。我已經使用錄製的宏來首先將數據排序到列。看,這就是為什麼我有這些命令:range.activate - 所以我選擇適當的範圍來運行錄製的宏。但是我知道選擇數據正在減慢程序的速度,我可以以某種方式記錄它並在不選擇單元格的情況下完成整個操作。但不知道如何。 Ť

  9. #9
    sorry I didn't get back to you sooner. I was out of town. Basically, there are two different styles to VBA. One is the macro code. The other is the object model. The object model is more akin to Visual Basic 6. The object model is a lot cleaner, easier to manipulate, and less prone to the errors you get using the macro recorder which is dependent on things such as active sheet, active cell, etc. The easy way to remember the basic model structure is that it's hierarchical. Workbook.Worksheet.Range(column_cell:column_cell).properties Below is some basic VBA to copy the Date, Time, O,H,L,C,V from an MT4 csv data file. The main thing to understand with objects and variables is that objects have to be created or instantiated using set. Variables initialized using =. By using explicit descriptions of the objects to be used and manipulated, there is no need to record what workbook,worksheet,cell, etc. needs to be highlighted or active. It's all specified by declaring which object to reference. The code is much cleaner and can be re-used in other larger routines. I call the sample below from another routine that processes multiple .csv files in one go using some for loops. The cool thing with setting Range objects is it's easier to copy/paste. You'd just say: sourceRangeName.copy then Range(A1).paste Which is a lot easier than trying to record highlighting a range, copying, and pasting. Inserted Code Sub OpenCSV() Dim sourceWb As Workbook Dim targetWb As Workbook Dim sourceWs As Worksheet Dim targetWs As Worksheet Dim sourceRng As Range Dim targetRng As Range Dim fPath As String Dim fName As String Dim lastCell As Integer 'Set target workbook, worksheet, and range. Set targetWb = ActiveWorkbook Set targetWs = targetWb.Worksheets(Mt4) 'Set file path and file name fPath = C:\MetaQuotes\MQL4\Files\ fName = [email protected] 'set sourceWb object to file to open Set sourceWb = Workbooks.Open(fPath fName, False, True) 'set the source range to the contiguous area from A1 and find the last row number Set sourceRng = sourceWb.Worksheets(1).Range(A1).CurrentRegion 'sourceRng.Copy lastCell = sourceRng.Rows.Count Debug.Print lastCell 'Clear existing data targetWs.Range(A1).CurrentRegion.Clear 'Header Row targetWs.Range(A1) = DATE targetWs.Range(B1) = TIME targetWs.Range(C1) = OPEN targetWs.Range(D1) = HIGH targetWs.Range(E1) = LOW targetWs.Range(F1) = CLOSE targetWs.Range(G1) = VOLUME targetWs.Range(H1) = fName 'set the target range values to the source range values then close the .csv file targetWs.Range(A2:G lastCell 1).Value = sourceRng.Value sourceWb.Close False End Sub There are a few other ways to get data from the csv files without opening them. You can do a file query through a connection string. That is one of the few recorded macros that is actually very useful. Another way is to an ADODB connection object and then use normal SQL (Select * from blah blah blah) to get the data into a recordset held in memory. This method is a bit slower, but allows you to get aggregate data if you want rather than read in all of the data and the aggregate. Or use a where clause if you want to be more selective.

  10. #10
    謝謝你和JR97。如果我只是需要從MT4中提取今天的OHLC而不打開甚至創建csv文件,代碼會是什麼樣子? (調製器請告訴我為什麼如果你阻止我的消息發布,你一直在無緣無故地阻止我的消息)

發布權限

  • 您不可發布新主題
  • 您不可回复
  • 您不可發布附件
  • 您不可編輯您的帖子
  •  
  • BB代碼是打開的
  • 表情符號是打開的
  • [IMG]代碼是打開的
  • [視頻]代碼是打開的
  • HTML代碼是關閉的
forex-pedia網站使用cookie 文字跟蹤
forex-pedia.com網站使用cookie 文字跟蹤,某些設定已經固定。您可以點擊此處閱讀我們的Cookie使用說明。 請點擊右鍵接受我們的cookies。如果您選擇繼續使用forex-pedia.com網站,我們將認為您接受我們的cookies。