VBA to Google sheet script
- or -
Post a project like this€20(approx. $21)
- Posted:
- Proposals: 4
- Remote
- #3076201
- Expired
Description
Experience Level: Entry
I would like to change a VBA macro in excel to a googlesheet script. :
function MonteC1() {
' Macro1 Macro
' Macro recorded by Kevin Davey - www.kjtradingsystems.com
' Do not change anything in this macro, unless you absolutely know what you are doing.
Worksheets(1).EnableCalculation = False 'manually calculate to allow faster processing
timex = Time
Randomize (Timer)
'first clear last results
Range("E4:k14").Select
Selection.ClearContents
startequity = Range("B2")
equityincrement = startequity / 4#
margin = Range("b3") 'this is also the ruin number
lotsize = 1 'always trade 1 contract
trades = Range("B4") 'trades in one year
niters = 2500 'run full simulation 2500 times
'find the last row that has data in it
i = 10
Do Until (Range("A" & i) = "")
i = i + 1
Loop
lastrow = i - 1
'
upperbound = lastrow - 10 + 1 'total # of trades in group
irow = 4 'for the output
'copy cells for output up until last iteration
Range("w1:aa5000").Select
Selection.ClearContents
For c1 = startequity To startequity + 10 * equityincrement Step equityincrement
Beginequity = c1
totalriskofruin = 0
For Iteration = 1 To niters
equity = Beginequity
drawdown = 0#
maxequity = equity
ruin = 0
For itrades = 1 To trades
'MsgBox "itrades " & itrades & " " & ruin & " " & equity & " equity"
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
tradenumber = Int(((lastrow - 10 + 1) * Rnd) + 10)
tradevalue = Range("A" & tradenumber)
ncontracts = lotsize
'don't trade if equity is below margin for one lot (you are RUINED)
If equity drawdown Then drawdown = dd
End If
Next itrades
totalriskofruin = totalriskofruin + ruin
' MsgBox " totalriskofruin " & totalriskofruin & " " & Iteration & " iteration"
Range("w" & Iteration) = equity
Range("x" & Iteration) = drawdown
Range("y" & Iteration) = ((equity / c1) - 1) 'rate of return in decimal
If drawdown 0
Worksheets(1).EnableCalculation = False 'auto calculate to allow faster processing
irow = irow + 1
Next c1
Worksheets(1).EnableCalculation = True 'auto calculate to allow faster processing
Range("a1").Select
'MsgBox "time is " & (Time - timex) * 60 * 60 * 24
Beep
End Sub
}
function MonteC1() {
' Macro1 Macro
' Macro recorded by Kevin Davey - www.kjtradingsystems.com
' Do not change anything in this macro, unless you absolutely know what you are doing.
Worksheets(1).EnableCalculation = False 'manually calculate to allow faster processing
timex = Time
Randomize (Timer)
'first clear last results
Range("E4:k14").Select
Selection.ClearContents
startequity = Range("B2")
equityincrement = startequity / 4#
margin = Range("b3") 'this is also the ruin number
lotsize = 1 'always trade 1 contract
trades = Range("B4") 'trades in one year
niters = 2500 'run full simulation 2500 times
'find the last row that has data in it
i = 10
Do Until (Range("A" & i) = "")
i = i + 1
Loop
lastrow = i - 1
'
upperbound = lastrow - 10 + 1 'total # of trades in group
irow = 4 'for the output
'copy cells for output up until last iteration
Range("w1:aa5000").Select
Selection.ClearContents
For c1 = startequity To startequity + 10 * equityincrement Step equityincrement
Beginequity = c1
totalriskofruin = 0
For Iteration = 1 To niters
equity = Beginequity
drawdown = 0#
maxequity = equity
ruin = 0
For itrades = 1 To trades
'MsgBox "itrades " & itrades & " " & ruin & " " & equity & " equity"
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
tradenumber = Int(((lastrow - 10 + 1) * Rnd) + 10)
tradevalue = Range("A" & tradenumber)
ncontracts = lotsize
'don't trade if equity is below margin for one lot (you are RUINED)
If equity drawdown Then drawdown = dd
End If
Next itrades
totalriskofruin = totalriskofruin + ruin
' MsgBox " totalriskofruin " & totalriskofruin & " " & Iteration & " iteration"
Range("w" & Iteration) = equity
Range("x" & Iteration) = drawdown
Range("y" & Iteration) = ((equity / c1) - 1) 'rate of return in decimal
If drawdown 0
Worksheets(1).EnableCalculation = False 'auto calculate to allow faster processing
irow = irow + 1
Next c1
Worksheets(1).EnableCalculation = True 'auto calculate to allow faster processing
Range("a1").Select
'MsgBox "time is " & (Time - timex) * 60 * 60 * 24
Beep
End Sub
}
FELIX L.
0% (0)Projects Completed
-
Freelancers worked with
-
Projects awarded
0%
Last project
4 May 2024
France
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
Hello, There seems to be a lot of syntax errors in the code that you have copied to the job description. Do you have a working Excel file containing the code which is functional? If yes, can you please attach the Excel file containing the code? Thanks,
Partha Sarathi
958561
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies