Jump to content
KyleK29

DAS - Dynamically Calculate Shares on %Risk or $Risk - Hot Key + Configuration, Updated 12/13, v1.46

Recommended Posts

On 12/1/2018 at 10:11 AM, Martin G said:

Hi all!  I'm new here and currently in SIM.  I loaded two of the HotKey scripts to test.

I have $30K buying power, $5K equity configured since I'm eventually headed to CMEG.

$50 fixed risk.  (This is edited to only load the trade.)

DefShare=BP*0.95; Price = Ask - Price + 0.01;SShare = 50 / Price;Share = DefShare - SShare; DefShare = DefShare + SShare; SShare = Share; SShare = DefShare - SShare; Share = 0.5 * SShare; TogSShare; ROUTE =LIMIT; Price = Ask +  0.05; TIF=DAY+; BUY=Load; DefShare = 100

Ask 21.09, double-clicked 20.99.  20.98 populated into the Price field on my montage.  Hit the hotkey and it loaded 416 shares.  Since my 95% of my buying power can easily afford 500 shares at an Ask of 21.09 with , I was surprised.  This is 83% of my intended shares/risk.

$100 Fixed Risk:  (Also to load, not send)

DefShare=BP*0.95; Price = Ask - Price + 0.01;SShare = 100 / Price;Share = DefShare - SShare; DefShare = DefShare + SShare; SShare = Share; SShare = DefShare - SShare; Share = 0.5 * SShare; TogSShare; ROUTE =LIMIT; Price = Ask +  0.05; TIF=DAY+; BUY=Load; DefShare = 100;

With the same scenario as above, this one loaded 833 share...  also 83%.

Any ideas why it is doing this?  

 

 

It's calculating the lesser of two values. Example, you can afford 500 shares, but your risk only allows for 416. If you bought 500 shares at the .11 stop distance, you'd be risking $55.

21.09 --> 20.99 (stop + the 0.01 buffer) --> 20.98 (as you said) --> .11 stop distance = .11 * 416 = $45.76 risk. Technically, it should be 454 shares ($49.94 risk), but I think it loses that resolution as it gets rounded a few times in the sequence. The idea is that it won't be exact risk every time, but it'll be lesser and should never be more.

On 12/3/2018 at 4:53 PM, Robert H said:

@KyleK29 Thanks for adding the STOP order feature! I will test in simulator and report back. Awesome work on the Stop Order Modifiers, too.

I ran into an issue today while having multiple positions opened. Note I am using the % Equity Risk version of the hotkeys. I believe using the Dollar Risk version may avoid this.

So I opened position 1, risking 1% of my account. My buying power is now reduced by what is used by position 1. All is well.

I open position 2 using the same hotkey as above. However, I am now risking much less than 1% since the calculation is based off available buying power (of course).  This leads to a much smaller position than what was intended. It gets worst if you open a third or fourth position. Note that my buying power is never fully consumed. Each subsequent position is just calculated based off the decreasing available BP.

I'm going to manually calculate 1% of my equity and use the Dollar Risk version. Will report back on results.

I'll have to experiment, but I've switched to Dollar Risk version myself. I think it is something to do with the way DAS reserves buying power, in testing I noticed that stops had a tendency to take up buying power in certain situations.

I have a newer sheet coming that includes some improved modifiers. I found some scenarios where the posted modifiers didn't work as expected.

On 12/3/2018 at 5:16 PM, ragycpa said:

Hi All

I am new to the community and this is my second day on SIM. I have three questions about the hotkeys script. 

Does this script buys/short based on the account equity or the buying power?

I am planning to use CMEG in the future giving my small trade account, and CMEG has 16% margin maintenance for stocks over $4. How can we incorporate that into this script?

The SIM is version 5.3.31, what excel file should I use, the beta?!

 

Thanks!

 

29 minutes ago, ragycpa said:

@Martin G

Thanks for your quick response. My situation is similar to yours. I am currently trading in SIM and eventually will head to CMEG for starting with smaller account. However when I applied the script you have mentioned with the same account size $5000 and 6:1 leverage, it bought me only 4 shares for AMD $21/share. I don’t know how the script bought me this. I guess I am not using it right. Should I double click on the stop loss I am targeting, or the entry price for the trade? Also I tried to load the script but it did not work. Any advice?

It's been a long time since I've used 0.31 (I've never tested it on that version), I'm on 0.34 which includes some bug fixes needed for stops to work. If you don't plan to use the automatic stop orders, you can use the non-BETA version of the excel file.

Can you post your DAS logs? They're located in the DAS folder under the LOGS folder I think. Might want to check them to make sure they don't include anything personal.

Now, the few times I've seen it calculate a very small share size like that is when the wrong hotkey was used. E.g. you used a LONG hotkey for a SHORT position, it calculates a very small share size (acts kinda like a protection mechanism, as it could be dangerous otherwise).

 

Edited by KyleK29

Share this post


Link to post
Share on other sites

@ragycpa

 

You double-click in the chart at the price you mentally want as your stop.  If the ASK is 21 and you want a 20 cent stop you click at 19.8 on the price chart.  Doing this will enter 19.79 in the price field in the montage, then the hotkey will calculate shares needed to risk your selection.  It will also verify that with your buying power you can afford the shares.  If you cannot, it *should* send the order for the number of shares you can afford to buy.

If you change the last part of these commands to BUY=Load it will enter the number of shares into the montage but not send the order... for testing.  Then you can change it back to BUY=Send.

With 20 cent stop on a $21 stock, you can easily afford the 500 shares needed to risk $100 (Requires $2,100 buying power)  (In this scenario, for some reason, my system buys me 416 shares, I don't yet know why!)  Please let me know how it works for you.

With a 20 cent risk on a $150 stock, you cannot afford the 500 shares.  In this situation the script should calculate the number of shares you can afford to buy at 95% (or other percentage if you changed this on the first sheet in the workbook) of your buying power and send the order for that.  When I tested this for $50 and $100 risk on NVDA with ASK as shown below just now and it worked correctly.  Interestingly, when the hotkey was pressed and the order loaded, the price then changed to 158.27 which apparently would be my average price for the purchase with the ASK offers pictured.

 

ASK AvgPrice.JPG

Share this post


Link to post
Share on other sites

@Martin G

Thanks Martin for your amazing help. By the way, what’s your DAS SIM version. The one I downloaded from DAS website was .31.

I like your buttons on Montage. How did you create them?

Edited by ragycpa

Share this post


Link to post
Share on other sites

@KyleK29

Thanks for your help Kylek. I signed for two weeks trail on DAS website and they sent me a link to download the platform. When I went to Help——-About it shows the version which is .31. Is it because of the simulator?

Share this post


Link to post
Share on other sites

This spreadsheet is brilliant! This is the only place on the Internet that I could find that helps traders build hot keys for DAS, and teaches how to use advanced DAS features (like account risk settings). Without BBT, I would never have realized the power of DAS, which I am now convinced is the best trading platform out there for day trading (tried most of them without success). This spreadsheet is another example of BBT's leadership in the day trading community. I have struggled for years with how to rapidly compute  position sizing in seconds for a developing setup before I enter a trade; and here it is, in a simple spreadsheet. Now I can double-click where I want my stop loss, send my hot key, and I risk precisely what I specified in the spreadsheet that defined the hot key. Amazing! Thank you BBT! For the first time ever, I have a trading edge; I have accurate defined risk for every trade I take.

Share this post


Link to post
Share on other sites
On 12/4/2018 at 8:18 PM, ragycpa said:

@KyleK29

Thanks for your help Kylek. I signed for two weeks trail on DAS website and they sent me a link to download the platform. When I went to Help——-About it shows the version which is .31. Is it because of the simulator?

That's the official release version. The beta branch is located here: https://www.dastrader.com/download/fixes/DASInstallDEMO.5.2.0.34.exe

I'd recommend making a copy of your current DAS folder before installing that, just as a precaution.

Share this post


Link to post
Share on other sites
On 12/4/2018 at 5:33 PM, Martin G said:

@ragycpa

With a 20 cent risk on a $150 stock, you cannot afford the 500 shares.  In this situation the script should calculate the number of shares you can afford to buy at 95% (or other percentage if you changed this on the first sheet in the workbook) of your buying power and send the order for that.  When I tested this for $50 and $100 risk on NVDA with ASK as shown below just now and it worked correctly.  Interestingly, when the hotkey was pressed and the order loaded, the price then changed to 158.27 which apparently would be my average price for the purchase with the ASK offers pictured.

 

ASK AvgPrice.JPG

 

The price you see in the montage is going to be the portion of the script that is used for your limit order, you won't actually see the other values as they occur too quickly.

So what is circled is the calculation of ask + 0.05 --> 158.22 + 0.05 = 158.27.

Re: Your prior example for $50 risk, I was slightly off in my calculation. 

Stop Distance Calculation Portion: Ask - Price + 0.01 --> 21.09 - 20.99 + 0.01 --> .11 --> .11 * 416 = $45.76 risk

However, if you double clicked a fractional (e.g. 20.985), that would have populated 20.98 into the price field, on hotkey execution that would be .11 stop distance + 0.01 offset = $50 / .12 = 416 shares (416.66 with the .66 lopped off).

Share this post


Link to post
Share on other sites
On 12/3/2018 at 4:53 PM, Robert H said:

@KyleK29 Thanks for adding the STOP order feature! I will test in simulator and report back. Awesome work on the Stop Order Modifiers, too.

I ran into an issue today while having multiple positions opened. Note I am using the % Equity Risk version of the hotkeys. I believe using the Dollar Risk version may avoid this.

So I opened position 1, risking 1% of my account. My buying power is now reduced by what is used by position 1. All is well.

I open position 2 using the same hotkey as above. However, I am now risking much less than 1% since the calculation is based off available buying power (of course).  This leads to a much smaller position than what was intended. It gets worst if you open a third or fourth position. Note that my buying power is never fully consumed. Each subsequent position is just calculated based off the decreasing available BP.

I'm going to manually calculate 1% of my equity and use the Dollar Risk version. Will report back on results.

I finally got around to testing this today. Yes, it uses the available Buying Power to try and refactor the available equity. This can cause it to be smaller and smaller on subsequent orders. Ideally, we'd want an EQUITY variable to calculate the 1% for all trades equally (those without subsequent buying power would be reduced in the MIN equation), using the BP variable makes it so that it gets inaccurate pretty quickly. 

I've switched all of mine to a flat dollar risk. It helps psychologically as well, since I know in my head what my $risk is. Just have to be more cognizant of your account balance (if live) and update your hotkeys accordingly (so you don't start risking more than 1% unintentionally).

 

I did notice an issue with the automatic STOP order when long on an SSR stock, DAS may block you from scaling out with the stop in place. I went long on AMD today (it was SSR) w/ automatic stop trigger, when I tried to scale out 25% I got rejected for "Short Marketable Limit Order disabled due to SSR!" - DAS calculates that the position size is going to drop below the pending stop order and rejects it because if not updated, the STOP order can convert to a short order (for the balance offset) if triggered. You have to clear the order the order to work around. 

I wish there was a STOP order that did not convert (e.g. do not cross position 0, change with current position).

Share this post


Link to post
Share on other sites

Thanks, Kyle.

I found that even using the dollar risk version, the diminishing available BP was still an issue. I'm assuming this is because it still contains the DefShare=BP*X variable.

I've since switched to a more simple version based on @fjmocke original hotkey:

Price=Ask-Price + 0.02;Share=100 / Price;ROUTE=SMRTL;Price=Ask+0.05;TIF=DAY+;BUY=Send

As we know, the downside is being rejected based on insufficient BP. I manage this by copy/pasting my Withhold BP from DAS to Excel.

For some reason I couldn't get the STOP orders to work at all. Maybe I'm doing something wrong.

On behalf of the BBT Team: thanks again for all the work!

Share this post


Link to post
Share on other sites

@KyleK29, this spread sheet is amazing! How did you even come up with codes like these?

Quick Question though. The trigger order for stop loss seems not working. These is no stop loss order sent afterwards. I've tried to set up a hotkey for stop loss orders, but the only post I can find is 

This code is setting the stop trigger price to a set value which is $.30 below the cost, but what if I want to double click the mouse on the chart, and then press the hotkey to set the stop price right there? Can we do that? In that case we can keep changing our stop losses as the price moves.

Please assist.

Thank you.

Share this post


Link to post
Share on other sites

@Sean S, I have no trouble getting the stop orders to trigger using the spreadsheet macros. I found that they work if the Montage is set to style "STOP", and do not work if set to "DEFAULT". Give that a try.

 

montage.png

Share this post


Link to post
Share on other sites
On 12/10/2018 at 1:19 PM, Robert H said:

Thanks, Kyle.

I found that even using the dollar risk version, the diminishing available BP was still an issue. I'm assuming this is because it still contains the DefShare=BP*X variable.

I've since switched to a more simple version based on @fjmocke original hotkey:

Price=Ask-Price + 0.02;Share=100 / Price;ROUTE=SMRTL;Price=Ask+0.05;TIF=DAY+;BUY=Send

As we know, the downside is being rejected based on insufficient BP. I manage this by copy/pasting my Withhold BP from DAS to Excel.

For some reason I couldn't get the STOP orders to work at all. Maybe I'm doing something wrong.

On behalf of the BBT Team: thanks again for all the work!

 

The portion that uses BP in the $Risk is just calculating the maximum affordable shares. Can you do me a favor and post the hotkey, and the DAS version #? I'll poke around it some more to see if I can replicate the issue.

As for the stop, GaryD might be right. I may need to add that to the instructions, I'll test it in a bit.

18 hours ago, Sean S said:

@KyleK29, this spread sheet is amazing! How did you even come up with codes like these?

Quick Question though. The trigger order for stop loss seems not working. These is no stop loss order sent afterwards. I've tried to set up a hotkey for stop loss orders, but the only post I can find is 

This code is setting the stop trigger price to a set value which is $.30 below the cost, but what if I want to double click the mouse on the chart, and then press the hotkey to set the stop price right there? Can we do that? In that case we can keep changing our stop losses as the price moves.

Please assist.

Thank you.

Try GaryD's suggestion. If not, I'll look at it. I know the Trigger order hotkey is very tempermental on whether it'll work or not. So I need to try and replicate the scenarios where it doesn't.

8 hours ago, GaryD said:

@Sean S, I have no trouble getting the stop orders to trigger using the spreadsheet macros. I found that they work if the Montage is set to style "STOP", and do not work if set to "DEFAULT". Give that a try.

 


Good suggestion, forgot about that. I'll test it and update instructions if it's required.

Share this post


Link to post
Share on other sites

@KyleK29 and @GaryD,

Thank you for the response. Mine is still not working. Below is the link I got from the spread sheet. The share sizes were calculated accurately, just no stop loss order was sent afterwards.

FocusWindow MONTAGE;StopPrice=Price-0;DefShare=BP*0.99;Share=DefShare*0.25*Price*0.02;Price=Ask-Price+0;SShare=Share/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;TogSShare;ROUTE=LIMIT;Price= Ask+0.05;TIF=DAY+;BUY=Send;DefShare=1000;TriggerOrder=ROUTE:STOP;STOPTYPE:MARKET PX:StopPriceSTOPPRICE:StopPrice;Share=Pos;TIF:DAY+ ACT:SELL;

Please assist.

Thank you.

Share this post


Link to post
Share on other sites

@Sean S Yours looks different from mine. Here is mine for "Long with 50% buying power and $20 risk":

StopPrice=Price-0;DefShare=BP*0.5;Price=Ask-Price+0.01;SShare=20/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;TogSShare;ROUTE=SMRTL;Price= Ask+0.05;TIF=DAY+;BUY=Send;DefShare=100;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice STOPPRICE:StopPrice QTY:Pos TIF:DAY+ ACT:SELL;

I simply double-click on the chart (connected to my Montage) where I want my stop, and send the Hot Key. Order is filled and Stop is entered. I found I had to have the Montage set to type "Stop". 

I do not have any FocusWindow command. Also, I am using the fixed $ risk version from the spreadsheet.

Share this post


Link to post
Share on other sites

@GaryD Hi Gary 

I tried changing the Montage style to Stop but the hotkey only sends stop loss on the long side and doesn’t do the same for the short side. Did you experience the hotkey on short and still sent stop order?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use, Privacy Policy and use of We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..