#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. ;_____________________________________________________________________________________________________________________________________________________________________________ ; MARKET VIEWER LIST ACTIONS ;_____________________________________________________________________________________________________________________________________________________________________________ ; Parameter: true to include the date in the Market Viewer export file name, false to use always the same file IncludeDateMVList := true ; Delete Selected Row(s) ~!D:: SetTitleMatchMode, 1 if WinActive("Market Viewer") { MouseClick, right Send, d } Return ; Delete All Rows ~+!D:: SetTitleMatchMode, 1 if WinActive("Market Viewer") { Send ^a MouseClick, right Send, d } Return ; Add New Row ~!N:: SetTitleMatchMode, 1 if WinActive("Market Viewer") { MouseClick, right Send, n } Return ; Export list to the file mylist.csv to the default directory ~!E:: SetTitleMatchMode, 1 if WinActive("Market Viewer") { MouseClick, right Send, e WinWaitActive, Save As if (IncludeDateMVList) { sleep 500 Send, mylist-%A_YYYY%-%A_MM%-%A_DD%.csv{enter} WinWaitActive, Confirm Save As, , 1 if (!ErrorLevel) Send, y } else { Send, mylist.csv{enter} WinWaitActive, Confirm Save As WinWaitActive, Confirm Save As, , 1 if (!ErrorLevel) Send, y } } Return ; Import list from the previously exported file mylist.csv from the default directory ~!I:: SetTitleMatchMode, 1 if WinActive("Market Viewer") { MouseClick, right Send, i WinWaitActive, Import Market View list if (IncludeDateMVList) Send, mylist-%A_YYYY%-%A_MM%-%A_DD%.csv{enter} else Send, mylist.csv{enter} } Return ; Add the current symbol selected in Montage to the Market Viewer ; NOTE: the Market Viewer window shall be the only one located in the same screen containing the montage window. In order to insert the symbol in a specific Market Viewer, ; the WinGet command can be modified to select a specific Market Viewer (e.g. WinGet, id, list, Market Viewer6), and the verification of the windows's coordinates can be removed ; Usage: select the symbol in the montage window and click the hotkey. ; The symbol will be inserted in the currently selected row of the Market Viewer (i.e. a row must be selected in the Market Viewer previously) !+:: ; Read current symbol ControlGetText, symbol, Edit1, A if (symbol != "") { ; Get the position of the Montage window WinGetPos, X, Y, Width, Height, A ; Loop through the monitors in order to find the one containing the Montage window SysGet, MonitorCount, MonitorCount Loop, %MonitorCount% { ; Read monitor area SysGet, MonitorWorkArea, MonitorWorkArea, %A_Index% ; If the Montage window is contained in the current monitor if (X >= MonitorWorkAreaLeft && Y >= MonitorWorkAreaTop && X < MonitorWorkAreaRight && Y < MonitorWorkAreaBottom) { ; Loop through the Market Viewer windows SetTitleMatchMode, 1 WinGet, id, list, Market Viewer Loop, %id% { ; Retrieve the position of the current Market Viewer window this_id := id%A_Index% WinGetPos, mvX, mvY, mvWidth, mvHeight, ahk_id %this_id% ; If the Market Viewer is containing in the same screen of the Montage if (mvX >= MonitorWorkAreaLeft && mvY >= MonitorWorkAreaTop && mvX <= MonitorWorkAreaRight && mvY <= MonitorWorkAreaBottom) { ; Activate the Market Viewer and paste the symbol WinActivate, ahk_id %this_id% ControlFocus, MFCGridCtrl1, ahk_id %this_id% Send, %symbol%{enter} } } } } } return ;_____________________________________________________________________________________________________________________________________________________________________________ ; CALCULATE PROFIT TARGET ; Calculate the profit target based on the desired risk/reward ratio and sets the Montage price accordingly ; Usage: ; - Assign in DAS Trader a hotkey setting the SShare field to the desired R (risk) in dollars (100$ in the example): ; Share=Pos;Price=AvgCost;SShare=100 ; - Assign the same hotkey (in the example SHIFT+F11 for long, CTRL+F11 for short) in the script below, in order to trigger AutoHotkey when the hotkey is pressed ; - A dialog will appear for the choice of the R profit target and how to calculate it: ; - Target R is the desired risk/reward (e.g. if your risk is 100$ and you select 2R, the script will calculate the target price to earn 200$) ; - Remaining position is, in case you took some partials, the percentage of your initial position that you still have ; If you didn't take any partials, just leave 100%. If you took 50% partials, set it to 50%, if you took 75% partials, set it to 25%, etc. ; If you previously sent in DAS a stop order setting the StopPrice equal to your stop loss price, you can also select the Base on SL option. ; If you select the options based on the % of position remaining, the target price will be calculated in order to obtain a potential reward in $ proportionate ; to the initial risk in $ and the remaining % of position ; If you select the option based on SL the price is calculated based on the difference between the AvgCost and the StopPrice, multiplied by the R/R ratio ; - When you press Calculate, AutoHotkey will fill the Price field in the Montage window to the target price, so that you can send use it to send an order ;_____________________________________________________________________________________________________________________________________________________________________________ ; * Case Long ~+F11:: ; Read current symbol ControlGetText, symbol, Edit1, A if (symbol != "") { ; Show Dialog Dir := 1 Gui, New Gui, Add, Text,, Target R: Gui, Add, Radio, vTarget1, 1 Gui, Add, Radio, vTarget2 Checked, 2 Gui, Add, Radio, vTarget3, 3 Gui, Add, Radio, vTarget4, 4 Gui, Add, Radio, vTarget5, 5 Gui, Add, Text,, Remaining position: Gui, Add, Radio, gCheck vRemaining100 Checked, 100`% Gui, Add, Radio, gCheck vRemaining75, 75`% Gui, Add, Radio, gCheck vRemaining50, 50`% Gui, Add, Radio, gCheck vRemaining25, 25`% Gui, Add, Radio, gCheck vBaseOnSL, Base on SL Gui, Add, Radio, gCheck vCustom, Custom `% Gui, Add, Edit, vMyEdit Disabled Gui, Add, Button, Default w80, Calculate Gui, Show, , %symbol% } return ; * Case Short ~^F11:: ; Read current symbol ControlGetText, symbol, Edit1, A if (symbol != "") { ; Show Dialog Dir := -1 Gui, New Gui, Add, Text,, Target R: Gui, Add, Radio, vTarget1, 1 Gui, Add, Radio, vTarget2 Checked, 2 Gui, Add, Radio, vTarget3, 3 Gui, Add, Radio, vTarget4, 4 Gui, Add, Radio, vTarget5, 5 Gui, Add, Text,, Remaining position: Gui, Add, Radio, gCheck vRemaining100 Checked, 100`% Gui, Add, Radio, gCheck vRemaining75, 75`% Gui, Add, Radio, gCheck vRemaining50, 50`% Gui, Add, Radio, gCheck vRemaining25, 25`% Gui, Add, Radio, gCheck vBaseOnSL, Base on SL Gui, Add, Radio, gCheck vCustom, Custom `% Gui, Add, Edit, vMyEdit Disabled Gui, Add, Button, Default w80, Calculate Gui, Show, , %symbol% } return ; Enable/Disable the custom % edit box Check: Gui, Submit, NoHide if (Custom){ GuiControl, Enable, MyEdit GuiControl, Focus, MyEdit } else { GuiControl, Disable, MyEdit } return ; Calculate target price ButtonCalculate: Gui, Submit ; Read current symbol ControlGetText, symbol, Edit1, A if (symbol != "") { ;Read Montage window's fields ControlGetText, share, Edit2, A ; Share ; Remove "-" for negative shares (short) share := StrReplace(share, "-") ControlGetText, risk, Edit9, A ; SShare ControlGetText, price, Edit3, A ; Price ControlGetText, stop, Edit6, A ; StopPrice ;Read Target R targetR := 0 if (Target1){ targetR := 1 } if (Target2){ targetR := 2 } if (Target3){ targetR := 3 } if (Target4){ targetR := 4 } if (Target5){ targetR := 5 } ; Read remaining pos % remaining := 0 if (Remaining100){ remaining := 100 } if (Remaining75){ remaining := 75 } if (Remaining50){ remaining := 50 } if (Remaining25){ remaining := 25 } if (Custom){ remaining := MyEdit } ; Calculate target price if(BaseOnSL){ target := Round(price + (price - stop) * targetR) } else { ; Long if(Dir > 0) { target := Round(price + risk / share * remaining / 100 * targetR, 2) } ; Short if(Dir < 0) { target := Round(price - risk / share * remaining / 100 * targetR, 2) } } ; Fill Montage window's fields ControlSetText, Edit9, , A ; SShare ControlSetText, Edit3, %target%, A ; Price } return GuiClose: Gui, Cancel ; Reset SShare ControlSetText, Edit9, , A return ;_____________________________________________________________________________________________________________________________________________________________________________ ; DISPLAY PROFIT TARGETS ; Calculate the profit targets in terms of multiples of the defined risk ; Usage: ; - Assign in DAS Trader a hotkey setting the SShare field to the desired R (risk) in dollars (100$ in the example): ; Share=Pos;Price=AvgCost;SShare=100 ; - Assign the same hotkey (in the example SHIFT+F12 for long, CTRL+F12 for short) in the script below, in order to trigger AutoHotkey when the hotkey is pressed ; - A dialog will appear for the choice of how to calculate the R profit target: ; - Remaining position is, in case you took some partials, the percentage of your initial position that you still have ; If you didn't take any partials, just leave 100%. If you took 50% partials, set it to 50%, if you took 75% partials, set it to 25%, etc. ; If you previously sent in DAS a stop order setting the StopPrice equal to your stop loss price, you can also select the Base on SL option. ; If you select the options based on the % of position remaining, the target price will be calculated in order to obtain a potential reward in $ proportionate ; to the initial risk in $ and the remaining % of position ; If you select the option based on SL the price is calculated based on the difference between the AvgCost and the StopPrice, multiplied by the R/R ratio ; - When you press Calculate, a message box displaying the R-multiple targets is displayed ;_____________________________________________________________________________________________________________________________________________________________________________ ; * Case Long ~+F12:: ; Read current symbol ControlGetText, symbol, Edit1, A if (symbol != "") { ; Show Dialog Dir := 1 Gui, New Gui, Add, Text,, Remaining position: Gui, Add, Radio, gCheck vRemaining100 Checked, 100`% Gui, Add, Radio, gCheck vRemaining75, 75`% Gui, Add, Radio, gCheck vRemaining50, 50`% Gui, Add, Radio, gCheck vRemaining25, 25`% Gui, Add, Radio, gCheck vBaseOnSL, Base on SL Gui, Add, Radio, gCheck vCustom, Custom `% Gui, Add, Edit, vMyEdit Disabled Gui, Add, Button, Default w80 gCalculate, Calculate Gui, Show, , %symbol% } return ; * Case Short ~^F12:: ; Read current symbol ControlGetText, symbol, Edit1, A if (symbol != "") { ; Show Dialog Dir := -1 Gui, New Gui, Add, Text,, Remaining position: Gui, Add, Radio, gCheck vRemaining100 Checked, 100`% Gui, Add, Radio, gCheck vRemaining75, 75`% Gui, Add, Radio, gCheck vRemaining50, 50`% Gui, Add, Radio, gCheck vRemaining25, 25`% Gui, Add, Radio, gCheck vBaseOnSL, Base on SL Gui, Add, Radio, gCheck vCustom, Custom `% Gui, Add, Edit, vMyEdit Disabled Gui, Add, Button, Default w80 gCalculate, Calculate Gui, Show, , %symbol% } return ; Enable/Disable the custom % edit box ;Check: <- Already defined above Gui, Submit, NoHide if (Custom){ GuiControl, Enable, MyEdit GuiControl, Focus, MyEdit } else { GuiControl, Disable, MyEdit } return ; Calculate target price Calculate: Gui, Submit ; Read current symbol ControlGetText, symbol, Edit1, A if (symbol != "") { ;Read Montage window's fields ControlGetText, share, Edit2, A ; Share ; Remove "-" for negative shares (short) share := StrReplace(share, "-") ControlGetText, risk, Edit9, A ; SShare ControlGetText, price, Edit3, A ; Price ControlGetText, stop, Edit6, A ; StopPrice ; Read remaining pos % remaining := 0 if (Remaining100){ remaining := 100 } if (Remaining75){ remaining := 75 } if (Remaining50){ remaining := 50 } if (Remaining25){ remaining := 25 } if (Custom){ remaining := MyEdit } ; Calculate target price if(BaseOnSL){ 1R := Round(price - stop, 2) target1R := Round(price + (price - stop) * 1) target2R := Round(price + (price - stop) * 2) target3R := Round(price + (price - stop) * 3) target4R := Round(price + (price - stop) * 4) target5R := Round(price + (price - stop) * 5) } else { 1R := Round(risk / share * remaining / 100, 2) target1R := Round(price + dir * risk / share * remaining / 100 * 1, 2) target2R := Round(price + dir * risk / share * remaining / 100 * 2, 2) target3R := Round(price + dir * risk / share * remaining / 100 * 3, 2) target4R := Round(price + dir * risk / share * remaining / 100 * 4, 2) target5R := Round(price + dir * risk / share * remaining / 100 * 5, 2) } ; Reset SShare ControlSetText, Edit9, , A MsgBox,,%symbol%, R: %1R%`n`n1R: %target1R%`n2R: %target2R%`n3R: %target3R%`n4R: %target4R%`n5R: %target5R% } return ;GuiClose: <- Already defined above Gui, Cancel ; Reset SShare ControlSetText, Edit9, , A return ;_____________________________________________________________________________________________________________________________________________________________________________ ; DRAG MARKET VIEWER ELEMENT(S) TO CHART(S) ; The function DragListToChart(listX, listY, chartX, chartY) drags an element of a market viewer list to a chart, in order to display the same symbol in the chart ; It can be used if you want to populate some charts with your watchlist without useing montage windows ; Usage: ; - Get the coordinates of the row N of the Market Viewer that you want to drag, and set the parameters listX and listY accordingly ; - Get the coordinates of the chartto which you want to drag the symbol N, and set the parameters chartX and chartYaccordingly ; - Call the function like in the examples for each chart ;_____________________________________________________________________________________________________________________________________________________________________________ DragListToChart(listX, listY, chartX, chartY) { CoordMode, Mouse, Screen ;MouseMove, listX, listY MouseClick, , listX, listY Sleep 750 MouseClick , Left, listX, listY, , , D Sleep 250 MouseMove, chartX, chartY, 100 MouseClick , Left, chartX, chartY, , , U Return } ; Example 1: populate 6 charts with the first 6 symbols of a market viewer window F23:: DragListToChart(1550, 655, 2000, 750) DragListToChart(1550, 670, 2750, 750) DragListToChart(1550, 685, 3500, 750) DragListToChart(1550, 700, 2000, 1250) DragListToChart(1550, 715, 2750, 1250) DragListToChart(1550, 735, 3500, 1250) Return ; Example 2: populate 12 charts with the first 6 symbols of a market viewer window !F23:: DragListToChart(1550, 655, 2000, 750) DragListToChart(1550, 670, 2750, 750) DragListToChart(1550, 685, 3500, 750) DragListToChart(1550, 700, 2000, 1250) DragListToChart(1550, 715, 2750, 1250) DragListToChart(1550, 735, 3500, 1250) DragListToChart(1550, 655, 2000, -250) DragListToChart(1550, 670, 2500, -250) DragListToChart(1550, 685, 3000, -250) DragListToChart(1550, 700, 2000, 250) DragListToChart(1550, 715, 2500, 250) DragListToChart(1550, 735, 3000, 250) Return ;_____________________________________________________________________________________________________________________________________________________________________________ ; CHANGE MONTAGE WINDOWS HEIGHT ; You can use this script to increase the montage window height temporarily to display more level 2 depth ; When you press the hotkey the 1st time the window is extended, the 2nd time is restored ; Usage: ; - Set the width to the width of your montage window(s), in the example 384 pixels; this is for cross-check that the correct window is selected ; - Retrieve the standard height of the montage window, 648 in the example ; - Retrieve the extended height of the montage window that you want to obtain by pressing the hotkey, 1080 in the example ; - Replace 384, 648, 1080 with the correct values ;_____________________________________________________________________________________________________________________________________________________________________________ F24:: WinGetPos, X, Y, Width, Height, A if Width = 384 Switch Height { Case 648: WinMove, A, , X, Y, 384, 1080 Case 1080: WinMove, A, , X, Y, 384, 648 }