
Forums (http://www.elitetrader.com/vb/index.php)
- Trading Software (http://www.elitetrader.com/vb/forumdisplay.php?forumid=3)
-- Dynamic Excel DDE link to TOS (ThinkOrSwim) (http://www.elitetrader.com/vb/showthread.php?threadid=223105)
Dynamic Excel DDE link to TOS (ThinkOrSwim)
I've seen many posts looking for the ability to dynamically copy and paste Excel DDE formulas containing cell references.
This is not possible in Excel because the DDE formulas can only be static.
But, here you have a quite convenient workaround which wll allow you to save a lot of time an effort.
All the effort has been applied to link to the ThinkOrSwim thinkDesktop client, but it could be taken as a model to do a similar thing with other DDE servers.
To use this piece of software you need to copy the following code to the VBA code window (you need to open the Visual Basic editor) of your Excel 2010 workbook (it could work in Excel 2003 and 2007 but I have not tested it there)
code:
Public Function TOSDDE(symbol As String, tosfield As String) ddeformula = "=TOS|" & UCase(tosfield) & "!'" & UCase(symbol) & "'" 'TOSDDE = Application.Evaluate(ddeformula) 'if you don't need to refresh the link this simple solution is good enough 'TOSDDE.Formula = ddeformula 'if this was possible that would be the perfect solution (try find a way to do that!) TOSDDE = ddeformula 'this allows the use of Activate/Deactivate subs to activate/deactivate the DDE links End Function Sub ActivateTOSDDElinks() Dim fullRange As range Dim formulaRange As range Dim cel As range Set fullRange = ActiveSheet.Cells Set formulaRange = fullRange.SpecialCells(xlCellTypeFormulas) For Each cel In formulaRange If InStr(1, cel.Formula, "=TOSDDE(", vbTextCompare) = 1 Then cel.ClearComments cel.AddComment (cel.Formula) cel.Formula = cel.Value End If Next End Sub Sub DeActivateTOSDDElinks() Dim fullRange As range Dim formulaRange As range Dim cel As range Dim comm As String Set fullRange = ActiveSheet.Cells Set formulaRange = fullRange.SpecialCells(xlCellTypeFormulas) For Each cel In formulaRange comm = "" On Error Resume Next comm = cel.Comment.Text If InStr(1, comm, "=TOSDDE(", vbTextCompare) = 1 Then cel.Value = cel.Formula cel.Formula = comm cel.ClearComments End If Next End Sub
Just wanted to say thanks. Nice clean workaround.
I appreciate your comments. You are welcome.
Hi mxpelite,
The function and macro works great!
Thank you so much, now I can ditch my OpenOffice DDE spreadsheet 
Cheers,
tangpd
Re: Dynamic Excel DDE link to TOS (ThinkOrSwim)
Quote from mxpelite:
here you have a quite convenient workaround which wll allow you to save a lot of time an effort.
Unfamiliar with VBA code/coding
I am unfamiliar with VBA code/coding and was unsuccessful getting this code to run. I pasted the code to Sheet1(Code) area (In the “Microsoft Visual Basic for Applications” window), saved the file, then went to Sheet1 and input:
=TOSDDE(“AAPL”, “BID”)
when I press enter, all I get is “#NAME?”. After that, I tried executing the macro:
Sheet1.ActivateTOSDDElinks
but nothing happens/changes. Is there something else that needs to be done in order for this code to work that I haven’t done? I would greatly appreciate any help on this!
I am using Office 2012.
Unfamiliar with VBA code/coding
I am unfamiliar with VBA code/coding and was unsuccessful getting this code to run. I pasted the code to Sheet1(Code) area (In the “Microsoft Visual Basic for Applications” window), saved the file, then went to Sheet1 and input:
=TOSDDE(“AAPL”, “BID”)
When I press enter, all I get is “#NAME?”. After that, I tried executing the macro:
Sheet1.ActivateTOSDDElinks
But nothing happens/changes. Is there something else that needs to be done in order for this code to work that I haven’t done? I would greatly appreciate any help on this!
I am using Office 2012.
Re: Unfamiliar with VBA code/coding
Quote from Squilly_D:
I am unfamiliar with VBA code/coding and was unsuccessful getting this code to run. I pasted the code to Sheet1(Code) area (In the “Microsoft Visual Basic for Applications” window), saved the file, then went to Sheet1 and input:
=TOSDDE(“AAPL”, “BID”)
when I press enter, all I get is “#NAME?”. After that, I tried executing the macro:
Sheet1.ActivateTOSDDElinks
but nothing happens/changes. Is there something else that needs to be done in order for this code to work that I haven’t done? I would greatly appreciate any help on this!
I am using Office 2012.
I appreciate the help! This was the fix I needed.
Quote from Squilly_D:
I appreciate the help! This was the fix I needed.
Using DDE with Excel to get Option Prices
This is how I do it (a Document is also attached):
Sub MakeDDE()
Dim ExpDt As Date
For CurRow = 2 To 11
DDERoot = "=TOS|MARK!'" 'Single then Double Quote at the end
StkSym = "." & Cells(CurRow, 1) '''Period is needed for Options
ExpDt = Cells(CurRow, 2)
StrkPr = Cells(CurRow, 3)
CallPut = Cells(CurRow, 4)
YYMMDD = Right(ExpDt, 2) & _
WorksheetFunction.Text(Month(ExpDt), "00") & _
WorksheetFunction.Text(Day(ExpDt), "00")
DDEFormula = DDERoot & _
StkSym & _
YYMMDD & _
CallPut & StrkPr & "'" '''Dbl, Single, Dbl Quotes
Cells(CurRow, 5) = DDEFormula
Selection.Replace What:="=", Replacement:="="
Next
End Sub
__________________
Steve
Activating dynamic Data Exchange (DDE) formulas
I know this doesn't sound logical, but I've found doing a replace on the equal sign can activate DDE formulas after they are copied in Excel.
The VBA statement is:
Selection.Replace What:="=", Replacement:="="
__________________
Steve
Turning Dynamic Data Exchange DDE on and off
Turning Dynamic Data Exchange DDE on and off
Click here to see what Microsoft says about turning DDE on/off
According to Microsoft: “When a new workbook is created, the default value for the UpdateRemoteReferences
property is True and dynamic data exchange (DDE) links and OLE links update automatically. If the value is False,
DDE links and OLE links do not update automatically or during recalculation.”
I have not been able to get UpdateRemoteReferences to do what it is advertised to do. You may have better luck.
code:
Sub DDE_OnOffSwitch() ActiveWorkbook.UpdateRemoteReferences = Not ActiveWorkbook.UpdateRemoteReferences End Sub
code:
Sub Calc_OnOffSwitch() If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic Else Application.Calculation = xlManual End If End Sub
code:
ROW COLUMN A 1 =TOS|MARK!'.SPY121117C142' 2 =TOS|MARK!'.SPY121117C143' 3 =TOS|MARK!'.SPY121117C144' 4 =TOS|MARK!'.SPY121117C145' 5 =TOS|MARK!'.SPY121117C146' 6 =TOS|MARK!'.SPY121117C147' 7 =TOS|MARK!'.SPY121117C148' 8 =TOS|MARK!'.SPY121117C149' 9 =TOS|MARK!'.SPY121117C160' 10 =TOS|MARK!'.SPY121117C161' Sub StopDDE() Range("A1:A10").Select With Selection.Font .ThemeColor = xlThemeColorDark1 '''Turn Font White .TintAndShade = 0 End With Selection.Replace What:="=", Replacement:="'=" '''Change the Formula to a Comment Range("A1").Select End Sub Sub StartDDE() Dim i As Integer Range("A1:A10").Select Selection.Copy Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats Application.CutCopyMode = False For i = 1 To 10 Cells(i, 1).Select ActiveCell.Formula = Cells(i, 1).Value '''Activate the DDE Formula Next Range("A1:A10").Select With Selection.Font .ColorIndex = xlAutomatic '''Change Font Color to Black .TintAndShade = 0 End With Range("A1").Select End Sub
__________________
Steve
Dynamic Data Exchange (DDE) with Thinkorswim and Excel
Dynamic Data Exchange (DDE) with Thinkorswim and Excel
See the attached spreadsheet for a Quick and easy way to use DDE with Thinkorswim and Excel.
__________________
Steve
Dynamic Data Exchange (DDE) with Thinkorswim and Excel
Excel-DDE-V2.xls handles both Stock and Option Quotes.
__________________
Steve
Turn any Excel Formula ON/OFF - Including DDE formulas
Excel Macros to turn formulas on/off start/stop label/formula enable/disable
code:
Sub FormulaON() Application.ScreenUpdating = False '''Makes the code run a lot faster Application.Calculation = xlManual Range("A1:A5").Select '''Cells containing the formulas With Selection .Font.ColorIndex = xlAutomatic '''Optional - Show the formula .Formula = .Formula End With Application.ScreenUpdating = True Application.Calculation = xlAutomatic Range("A1").Select End Sub Sub FormulaOFF() Application.ScreenUpdating = False Application.Calculation = xlManual Range("A1:A5").Select With Selection .Font.ColorIndex = 2 '''Optional - Hide the formula (white font) .Replace What:="=", Replacement:="'=" '’’Replacement:=double quote, single quote, equal sign, double quote End With Application.ScreenUpdating = True Application.Calculation = xlAutomatic Range("A1").Select End Sub
Remove Apostrophe from formula
Remove apostrophe from beginning of formula
The attached spreadsheet might help if your DDE shows formulas instead of results.
__________________
Steve
removing
I would like to thank all prior postersfor bringing this content forward, this is some quality content.
It should be possible to add text to column steps to any of these macros.
Millerd1
Is there a way to add a column for Deltas? What would that code be?
Delta Added
Delta has been added.
__________________
Steve
Corrected "Position Delta" for Stock positions.
__________________
Steve
Thanks so much! Sorry it took so long, but I didn't get an email to say you had responded.
How about a curveball? A routine that sends an email/text when a specified cell gets to a certain number.
I monitor certain Butterflys and Condors based on the deltas of the entire position.
So, day the short calls/put and long calls/puts and posibly an outmonth long call are all added up and they reach greater than 16 or less than -16 it triggers an email to sms alert.
You can do Delta alerts in TOS (when they are working), but complex position delta monitoring is out.
Cowtowner,
You have an interesting idea. It can be done.
Unfortunately, it would take a little more than my available time allows.
Hopefully someone will see your post and be able to help.
__________________
Steve
Going to try to tackle it myself. I used to program VBA back in the day, but have forgotten nearly everything.
All I see is =TOS|BID!'APPL' after I enter the formula =TOSDDE("AAPL", "BID").
I tried the following, but no joy.
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
It's a windows issue:
From another website, you have to run excel in admin mode:
a) In Vista or Windows 7, type "Excel.exe" in the "search programs and files" box in the start menu. An Excel icon will appear in the list, right button on it and select "Run as administrator".
b) Locate where Excel.exe is on your C drive and create an icon for it on the desktop. You may have to search for it on your C drive, the locations are different depending on where Office was installed, or by following step (a) select "Send to", and "Desktop - create shortcut". then you can right button select the icon from your desktop and choose "Run as administrator".
OR
2. Uninstall the Windows update that caused this problem. This isnt recommended, but you can go into Windows Update, click on "View Update History" then "Installed Updates", find the following updates in the list and uninstall them. The two updates I have found so far that each can create this problem are
KB2778930 and
KB2778344
Once you unselect them from the next windows update I believe it wont re-install these.
Microsoft will probably release future updates that cause this problem again, so in the long run we are going to lose this method of fixing it.
It was running in admin mode.
Maybe I missed something. I noticed if I manually ran Sub ActivateTOSDDElinks() it worked.
All times are GMT. The time now is 05:56 AM.