Jason W 17 Posted October 11, 2018 1 hour ago, KyleK29 said: I wouldn't take one for the team testing it, use a NASDAQ testing symbol. It sends the order in to the market, but they don't actually fulfill with anything (as it's not a real company). These: TEST TESTB TESTE TESTX ATEST Additionally, a few different ways to test it to wait until the market closes and switch the "SELL=SEND;" to "SELL=LOAD;", click a price really close to the current. See what it puts in the share box, as that's likely to be the maximum-affordable calculation. That's how I tested a lot of it, with the market closed you don't have to worry about the price jumping around and can consistently click different stop distances (e.g. .10c back, .20c back) to see what it is calculating. I assume that DAS is likely using the buying power for long for both calculations (since it doesn't know you're planning to go short when it loads the values), so you'd need to factor that into the hotkey, 0.33 should be the right number on the short side. **EDIT** I think I may have figured out how to go about this: Example Numbers: Equity: $25,000 Buying Power Long 4:1 - $100,000 : $25,000 Buying Power Short 3:1 - $75,000 : $25,000 Assuming $10 stock and that DAS is going to use the LONG number for both: BP = 100,000 / $10 = 10,000 "Shares" 10,000 * 0.25 [equity] = 2,500 [at account equity] BP * 0.75 = 75,000 / $10 = 7,500 "Shares" 7,500 Shares * 0.33 [equity] = 2,475 So try this: DefShare=BP*0.73; Share=DefShare*0.333333333333333* Price * 0.01; That opening DefShare=BP*0.73 is saying "Calculate using 73% of Buying Power [assuming it's using the LONG number]" (It's 75% minus 2% for a buffer for price fluctuations/spreads). Please let me know if you test it and if it works or not. If it does, I'll add it to the configuration and instructions. OMG you are so smart. I'm gonna testing this one out right now. Thank you so much !! 1 Share this post Link to post Share on other sites
Jason W 17 Posted October 11, 2018 Hey Kyle: I tested it out. This seems to be the configuration that works best for IB short. Shorting with 1% account risk with AUTO size based on selected stop price DefShare=BP*0.8; Share=DefShare*0.3* Price * 0.01; Price = Price - Bid + 0.02;SShare = Share / Price; Share = DefShare - SShare; DefShare = DefShare + SShare; SShare = Share; SShare = DefShare - SShare; Share = 0.5 * SShare; TogSShare; ROUTE =LIMIT; Price = Bid - 0.05; TIF=DAY+; SELL=Send; DefShare = 500; IB requires 30% equity as margin for short, and 25% equity as margin for long. Therefore, the discount on BP should be 0.25/0.3= 0.833333, so I just used 0.8 to be safe. For the same reason, I used 0.3 instead of 0.333333333333333. I just want to say Thank you again for figuring this out. Smart people like you are hard to find. If you ever need help with anything, pm me and let me know. BTW I just finished set up the new Genovation 48 key control pad. I highly recommend it. It's nicer than the 24. 1 Share this post Link to post Share on other sites
TonyC 1 Posted October 12, 2018 Great script! I've been looking for information on the user defined variables but can't seem to find any. Do you know if it's possible to define variables for price? Basically, instead of a b/e hotkey, i wanted to create one that allows to keep half/quarter of your winnings. For easy math, say you went short at $100 per share, the current price is at $90. You want to let it run buy want to protect at least half of your current winnings.. to do so, you need a stop order @ $95. If the DAS scripting allowed for parentheses, you could just do StopPrice=AvgCost+((AvgCost-Bid)*.5) which would equal StopPrice=$95; $100+(($100-$90)*.5)=$95 If I could define 2 variables I could do: DefVar1=AvgCost-Bid; DefVar2=DefVar1*.5; StopPrice=AvgCost+DefVar2; However, I can't seem to get the variable definitions to work, any thoughts? Thanks. 1 Share this post Link to post Share on other sites
KyleK29 258 Posted October 17, 2018 On 10/12/2018 at 12:11 PM, TonyC said: Great script! I've been looking for information on the user defined variables but can't seem to find any. Do you know if it's possible to define variables for price? Basically, instead of a b/e hotkey, i wanted to create one that allows to keep half/quarter of your winnings. For easy math, say you went short at $100 per share, the current price is at $90. You want to let it run buy want to protect at least half of your current winnings.. to do so, you need a stop order @ $95. If the DAS scripting allowed for parentheses, you could just do StopPrice=AvgCost+((AvgCost-Bid)*.5) which would equal StopPrice=$95; $100+(($100-$90)*.5)=$95 If I could define 2 variables I could do: DefVar1=AvgCost-Bid; DefVar2=DefVar1*.5; StopPrice=AvgCost+DefVar2; However, I can't seem to get the variable definitions to work, any thoughts? Thanks. From what I can tell, the user can't assign/create variables. The way I did the one in this thread was to use available variables that the user can access via the hotkey / montage. These can change depending on what ROUTE is selected. SSHARE --> Display Box (next to share), this is an unsigned INT, read/write SHARE --> Share Box, this is an INT, read/write PRICE --> Price Box, this is a FLOAT, read/write DEFSHARE --> Default Shares (not displayed, but accessible), this is an INT, read/write TRAILPRICE --> Trailing Price, FLOAT, but only available if STOP is selected and stop type = Trailing, read/write STOPPRICE --> Trigger Price, FLOAT, only available if STOP is selected and "trigger price" box is writeable, read/write CAPSHARE --> String, write only PREF --> String, write only. Because prices are floats and the majority of variables available are INT based, you can always convert a float to an INT by multiplying by 100 and then dividing by 100 later (to get it back to float), otherwise moving a FLOAT to an INT variable will drop the decimal portion ($100.99 becomes $100). For your request, if I'm understanding it correctly, you don't need to do too much. See if this works, it's hard to test these as you have to get a stock to move to really see it. Again, SIM or a test symbol for trying it out. SHORT: Share = Pos; Price = AvgCost - Bid * .5; Price = AvgCost - Price; Route=STOP;StopType=Market;StopPrice=Price; BUY LONG: Share = Pos; Price = Ask - AvgCost * .5; Price = AvgCost + Price; Route=STOP;StopType=Market;StopPrice=Price; SELL What it's doing is: Short Entry Price: $100 Current Bid: $90 Share = Pos (our current position) Price = AvgCost - Bid * .5 ---> $100 - $90 * .5 ---> $10 * .5 = $5 (Note: DAS calculates in the order seen, I believe), "Price" is our temporary calculation of the midpoint (* .5). Price = AvgCost - Price --> $100 The rest is just a standard STOP order. From what I tested, this worked for finding the midpoint and setting stop midway between the current value. Unfortunately, the hotkey commands for REPLACE (replace an existing order) don't seem to work correctly for STOP order types, so if the stock continued to move in your favor, you'd need to cancel the current STOP and then set the new one (rerun the hotkey). 2 --------------------------------------------------------- ○ Profile / Project Pages (Dynamic Hotkeys, StreamDeck Files, and other contributions are located here) Share this post Link to post Share on other sites
KyleK29 258 Posted October 17, 2018 Added a newer version of the configuration sheet. See original post up above under "UPDATES" to see. Includes a Dynamic Scale-In hotkey command now. 2 --------------------------------------------------------- ○ Profile / Project Pages (Dynamic Hotkeys, StreamDeck Files, and other contributions are located here) Share this post Link to post Share on other sites
Jason W 17 Posted October 18, 2018 Thanks a lot for the new update Share this post Link to post Share on other sites
Robert H 453 Posted October 25, 2018 @KyleK29 I am amazed by how much effort you've put into this solution. Thank you on behalf of the entire Bear Bull Traders Team! Would it be possible to automatically send a STOP MARKET order along with the buy/sell execution? The following script only sends a STOP with some arbitrary price relative to Average Cost: Share=Pos;ROUTE=STOP;StopType=Market;StopPrice=AvgCost-0.10;TIF=DAY+;SELL=SEND How cool would it be to double-click your stop level, automatically calculate share size, send the order, and send a stop order with the press of one hotkey. Thanks! 3 1 Share this post Link to post Share on other sites
Michael P 4 Posted October 28, 2018 This script was a revelation. Especially that there is some user space variables. Kudos Kyle and Franco!! The change to export to excel is simple. Excel, at least my version, does not translate the range formula "=$A$3:$D:3". Where there is a cell range in a formula replace it with each cell. For example: =$A$3:$D:$3 would be rewritten =$A$3, $B$3, $C$3, $D$3, The three formulas ( E11, E25 and E40) become: =CONCATENATE($A$3,$B$3,$C$3,$D$3, $E$3, B11, $G$3, IF(D11 = "long", " Ask - Price + ", " Price - Bid + "), $I$3, $J$3, "Share", $L$3, $M$3, $N$3, $O$3, IF(D11 = "long", " Ask + ", " Bid - "), $Q$3, $R$3, $S$3, $T$3, IF(D11 = "long", " BUY=", " SELL="), $V$3, $W$3, $X$3, $Y$3) =CONCATENATE($A$3, $B$3, B25, $G$3, IF(D25 = "long", " Ask - Price + ", " Price - Bid + "), $I$3, $J$3, $A25, $L$3, $M$3, $N$3, $O$3 , IF(D25 = "long", " Ask + ", " Bid - "), $Q$3, $R$3, $S$3, $T$3, IF(D25 = "long", " BUY=", " SELL=") , $V$3, $W$3, $X$3, $Y$3) =CONCATENATE($A$3, $B$3, ";Share=Pos;SShare=Share *", A40, $M$3, $N$3, $O$3 , IF(D40 = "long", " Ask + ", " Bid - "), $Q$3, $R$3, $S$3, $T$3, IF(D40 = "long", " BUY=", " SELL=") , $V$3, $W$3, $X$3, $Y$3) -- then copy each cell to the others -- For example copy E11 to E12 through E20, You can make the changes in google doc then download to excel. Share this post Link to post Share on other sites
Raymond.l 3 Posted October 28, 2018 (edited) Hi Kyle, Great stuff, I think this is very useful for a lot of traders. It will be great if you can make a short instruction video too, just a suggestion. Thanks heaps. Edited October 28, 2018 by Raymond.l Share this post Link to post Share on other sites
Michael P 4 Posted October 29, 2018 Possible problem. I don't think the SShare variable works as an unsigned int. This script SShare=256; Share = SShare-300 Sets the display to 256 and Share to -44 (as expected) But this script: SShare=-256; Share = SShare-300 Unsets the display and sets the Share as -300, and evidently, 'SShare = -256' results in SShare equal to 0. If you are using: 'SShare = Share' to function like 'ABS(Share)', I think it will fail when Share < 0 Also important, the scripts are too long to use in the button hot keys. They work in the hot key file when assigned to a keyboard shortcut, but the buttons' text boxes, that holds the script, are limited to 200 characters.If you paste a 300 character script, only the first 200 characters are saved in the text box. Share this post Link to post Share on other sites
KyleK29 258 Posted October 30, 2018 (edited) On 10/28/2018 at 7:08 PM, Michael P said: Possible problem. I don't think the SShare variable works as an unsigned int. This script SShare=256; Share = SShare-300 Sets the display to 256 and Share to -44 (as expected) But this script: SShare=-256; Share = SShare-300 Unsets the display and sets the Share as -300, and evidently, 'SShare = -256' results in SShare equal to 0. If you are using: 'SShare = Share' to function like 'ABS(Share)', I think it will fail when Share < 0 Also important, the scripts are too long to use in the button hot keys. They work in the hot key file when assigned to a keyboard shortcut, but the buttons' text boxes, that holds the script, are limited to 200 characters.If you paste a 300 character script, only the first 200 characters are saved in the text box. I'll look into the problem. Did you notice this by manually doing hotkeys with SShare = -256; SShare - 300 or was it during an actual order operation? I noticed this exact behavior when developing the hotkey and worked around it in how I formatted the order that it calculates in. I'd have to look at my notes, but if I recall, display (SShare) behaves as an unsigned INT when it's being transferred from Share (it loses the sign), this is because Share swaps from -300 to 300- on box refresh (you'll notice this when going short). However, oddly, manually setting SShare to a negative INT will cause the Display Box to show 0. The typed explanation of how the script works is a simplified version - to develop this I flowcharted all of the memory containers so I could properly "see" what I needed to do, I just didn't feel like typing up a really detailed explanation. As for the hotkey button limitation, there's no real solution for that. This is a very hack-like way of doing what is normally a very simple string of operations because of limitations in DAS. I hope that someday they give proper script support with some user variables and functions that we can do this properly. The entire command would be a lot smaller with a few built-ins. Also, I'll look into making the Google Sheet a tad more Excel friendly with your suggestions. Edited October 30, 2018 by KyleK29 --------------------------------------------------------- ○ Profile / Project Pages (Dynamic Hotkeys, StreamDeck Files, and other contributions are located here) Share this post Link to post Share on other sites
KyleK29 258 Posted October 30, 2018 On 10/24/2018 at 8:40 PM, Robert H said: @KyleK29 I am amazed by how much effort you've put into this solution. Thank you on behalf of the entire Bear Bull Traders Team! Would it be possible to automatically send a STOP MARKET order along with the buy/sell execution? The following script only sends a STOP with some arbitrary price relative to Average Cost: Share=Pos;ROUTE=STOP;StopType=Market;StopPrice=AvgCost-0.10;TIF=DAY+;SELL=SEND How cool would it be to double-click your stop level, automatically calculate share size, send the order, and send a stop order with the press of one hotkey. Thanks! If it's something the community wants, I can look into it. I'd have to figure out some trickery to store the stop price (the double-clicked price) and retrieve it since I used up all the variables for the main part of the script. 2 1 --------------------------------------------------------- ○ Profile / Project Pages (Dynamic Hotkeys, StreamDeck Files, and other contributions are located here) Share this post Link to post Share on other sites
KyleK29 258 Posted October 30, 2018 (edited) 14 hours ago, KyleK29 said: If it's something the community wants, I can look into it. I'd have to figure out some trickery to store the stop price (the double-clicked price) and retrieve it since I used up all the variables for the main part of the script. @Robert H So I looked into this last night. It doesn't appear currently possible because of either a design limitation or a bug in DAS. The way I was going to do it was to store the double-clicked value (which gets filled into the montage PRICE field, the "initial stop") in the "StopPrice" variable (switching to ROUTE=Stop and back again). However, it appears that when ROUTE=Stop, the "price" variable is set to "StopPrice", so it's a circular reference (doing StopPrice = price is doing StopPrice = StopPrice). I couldn't find any other places to store the initial price temporarily, as the only floats are available in the STOP route. I also tried converting the datatype, but DAS doesn't support it. Contrary, when ROUTE=Limit, StopPrice is still a valid variable to use. So I'm not sure if this intended or a bug - doesn't seem like it should be this way, as it only has limitations and no upsides I can see. Edited October 30, 2018 by KyleK29 1 --------------------------------------------------------- ○ Profile / Project Pages (Dynamic Hotkeys, StreamDeck Files, and other contributions are located here) Share this post Link to post Share on other sites
Robert H 453 Posted October 30, 2018 Thanks for looking into it! Share this post Link to post Share on other sites
jcgraybeal 0 Posted October 30, 2018 Can/will this work with Trader Workstation (TWS)? John Share this post Link to post Share on other sites