Jump to content
KyleK29

DAS - Dynamically Calculate Shares on %Risk or $Risk - Hot Key + Configuration, Updated 9/10/19, v2.1

Recommended Posts

1 hour ago, jcgraybeal said:

Can/will this work with Trader Workstation (TWS)?

 

John

 

Not likely as this is DAS specific, although I'm sure there's probably a way to do something similar in TWS. I don't have or use it, so I'm unfamiliar with what options they have available.


---------------------------------------------------------
Profile / Project Pages (Dynamic Hotkeys, StreamDeck Files, and other contributions are located here)

Share this post


Link to post
Share on other sites
23 hours ago, KyleK29 said:

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. 

I put the script in exactly as above. No Buy, Price, or Route tokens.

The excel thing is kind of a shame as the range variables in Sheets are more elegant, but referring to each cell instead works in both Sheets and Excel. I recommend a small edit. Add a variable settings.send_load = {Send, Load} to the settings sheet and refer to it in the Hot Keys sheet V3.

For the stop loss, it seems it ought to be possible to get StopPrice from something like StopPrice= Price-100/Share where 100 is the amount risked set in your Sheets app. I can't get it to work. Maybe you can. It doesn't seem to be willing or able to set a float (StopPrice) using an int (Share).  Here is the script i was trying. The first part is entirely from your configuration. And I added :

Share=Pos;ROUTE=STOP;StopType=Market;StopPrice=Price-75/Share;TIF=DAY+;SELL=SEND 

to get:

DefShare=BP*0.5; StopPrice=Price; Price = Ask - Price + 0.01;SShare = 75 / 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 = 500;Share=Pos;ROUTE=STOP;StopType=Market;StopPrice=Price-75/Share;TIF=DAY+;SELL=SEND 
 

Note that it does create both orders if I use StopPrice = Price - .15

But of course, .15 is just arbitrary.

Share this post


Link to post
Share on other sites
14 hours ago, Michael P said:

I put the script in exactly as above. No Buy, Price, or Route tokens.

The excel thing is kind of a shame as the range variables in Sheets are more elegant, but referring to each cell instead works in both Sheets and Excel. I recommend a small edit. Add a variable settings.send_load = {Send, Load} to the settings sheet and refer to it in the Hot Keys sheet V3.

For the stop loss, it seems it ought to be possible to get StopPrice from something like StopPrice= Price-100/Share where 100 is the amount risked set in your Sheets app. I can't get it to work. Maybe you can. It doesn't seem to be willing or able to set a float (StopPrice) using an int (Share).  Here is the script i was trying. The first part is entirely from your configuration. And I added :

Share=Pos;ROUTE=STOP;StopType=Market;StopPrice=Price-75/Share;TIF=DAY+;SELL=SEND 

to get:

DefShare=BP*0.5; StopPrice=Price; Price = Ask - Price + 0.01;SShare = 75 / 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 = 500;Share=Pos;ROUTE=STOP;StopType=Market;StopPrice=Price-75/Share;TIF=DAY+;SELL=SEND 
 

Note that it does create both orders if I use StopPrice = Price - .15

But of course, .15 is just arbitrary.

 

I'll look at adding that to the new configuration.

 

I tried a lot of combinations for the stop order and saw the same things you saw. Here's what I tried.

Move "PRICE" to StopPrice --> Nothing is filled
Move "PRICE" to Shares / DefShares / SShares * 100, move to StopPrice / 100 --> Error Message (it'll go into a share container, but it won't come out without error), same with multiplying by 1.00 (to try and force it to be a float)
Move "PRICE" to High Price, Low Price, Trail Price --> Error Message

From what I can tell, PRICE can write to Shares/DefShares/SShare just fine. StopPrice can write to PRICE. Shares/DefShares/SShares can't convert to write to PRICE (error message). When Route=STOP, "Price" variable = StopPrice variable. That's why if you do StopPrice = Price + .10, it's actually adding .10 to the prior stored StopPrice. Keep hitting that hotkey and it keeps adding .10c to the prior value.

Edited 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

I'm new to Dastrader, I installed it in on Friday. I created hot keys for the command scripts generated by your spreadsheets. The problem I'm having is that most of the time these hot keys do not work (nothing happens), sometimes the buy hot key works and sometimes only the short hot key works. What am I doing wrong? Am i supposed to first double click on the chart then click on the Montage window before I press the order hotkeys? Is there a problem with the hot keys I have chosen (CTRL+numpad1 for long and ALT+numpad1 for short) for the script commands? Is there a setting I have to change in Dastrader in order for them to work correctly?

Share this post


Link to post
Share on other sites
1 hour ago, altqer said:

I'm new to Dastrader, I installed it in on Friday. I created hot keys for the command scripts generated by your spreadsheets. The problem I'm having is that most of the time these hot keys do not work (nothing happens), sometimes the buy hot key works and sometimes only the short hot key works. What am I doing wrong? Am i supposed to first double click on the chart then click on the Montage window before I press the order hotkeys? Is there a problem with the hot keys I have chosen (CTRL+numpad1 for long and ALT+numpad1 for short) for the script commands? Is there a setting I have to change in Dastrader in order for them to work correctly?

Yes double click is to set your stop loss: above current price for short below for long. 

  • Like 1

Abiel Guerra

BBT Team

abiel@bearbulltraders.com

 @abielguerra 

Find your answers in our Knowledge Base 

Share this post


Link to post
Share on other sites
Just now, Abiel said:

Yes double click is to set your stop loss: above current price for short below for long. 

I understand that, the prices are correctly entered in the Price field in the Montage window after I double click on the chart. It's just that the hot keys don't work most of the time.

Share this post


Link to post
Share on other sites

Just to clarify, the default shares really doesn't matter right? Since it will change depending on the stop loss. 

Share this post


Link to post
Share on other sites

It actually works, amazing. No more big losses because the stock had a higher movement range than I realized. 

Share this post


Link to post
Share on other sites
8 hours ago, nmarnson said:

Do I need to create a new hotkey whenever my account equity changes?

These hotkeys are risk based ($$ or account %). If your account size significantly changes and you want to risk more, or less, yes, you can change (edit) the risk criteria in your hotkeys. I hope this answers your question.

  • Like 1

Abiel Guerra

BBT Team

abiel@bearbulltraders.com

 @abielguerra 

Find your answers in our Knowledge Base 

Share this post


Link to post
Share on other sites
On 11/11/2018 at 9:18 PM, stephenlee said:

Quick question! 

 

What does SMRTL mean?

SMRTL is Interactive Brokers' proprietary route for limit orders. SMRTM is for market orders.

  • Like 2

Share this post


Link to post
Share on other sites

Sorry I've been away guys, a lot of people at Horseshoe Overlook have been counting on me for provisions .... but seriously, I have been very busy.

 

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!

So they fixed the issues that prevented this from working. If you have version 0.34 and want to be a guinea pig (in SIM of course), try this for a long: 

 

StopPrice=Price;DefShare=BP*0.97; Price = Ask - Price + 0.02; SShare = 120 / 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 = 400; ROUTE=STOP;StopType=Market;StopPrice=Round2;SELL=Send;

 

That particular one should: BUY shares adjusted to a maximum risk of $120 (from stop location) and then send the original double-clicked price (your stop) as a STOP market order. I had a few issues with trying to use POS as the stop-order would beat the initial order to market, thus being rejected because you have no open position. To get around that, I sent the stop with the initial share. Now, I'm not sure if that will create an issue with getting a stop in place but having the initial order rejected - hence why it needs to be thoroughly tested.

Hopefully they eventually add the ability to "queue" orders via hotkeys that only process once the prior order returns success. 

Also a note, be very conscious of this when you scale out a position as you have to update the stop's position size, otherwise it'll flip your position. I've tried some of the CANCEL/REPLACE/AUTOCOVER stuff, but I haven't found one that will automatically update a stop's position with each change. An alternative approach would be to create a hotkey to update the position, I've been testing that myself it just requires a separate action elsewhere in the program to do it (better explained in a video).

If these pan out, I'll roll them into the configurator sheet.

On 11/4/2018 at 2:17 PM, altqer said:

I understand that, the prices are correctly entered in the Price field in the Montage window after I double click on the chart. It's just that the hot keys don't work most of the time.

Did you get everything sorted and working? I'll try and throw together a video to help some people out.

On 11/6/2018 at 9:19 AM, nmarnson said:

Just to clarify, the default shares really doesn't matter right? Since it will change depending on the stop loss. 

It doesn't matter in the sense that it's just the value that gets loaded when you click a new symbol (the template value). It's set in the hotkey as we use the DEFSHARE container to store a rather large value that we don't want as the template default shares. So just set it to what you would have set your default-shares in the template manager (I think default in DAS is either 500 or 1000).

 

On 11/9/2018 at 6:22 AM, nmarnson said:

Do I need to create a new hotkey whenever my account equity changes?

No. As long as DAS is correctly getting your buying power from the broker (or sim), it will adjust. The script auto calculates what you can afford at the moment of execution (e.g. if you already have a position size of 80,000, it'll only let you use 20,000 .. preventing a rejection).

Some of the settings in the config sheet are just to help people understand the values.

 

On 11/11/2018 at 9:18 PM, stephenlee said:

Quick question! 

 

What does SMRTL mean?

As RobertH answered, it's a route type. The config sheet includes a ton of routes for the validation dropdown pulled from DAS's route list. The basic ones are usually suffice.

Edited 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

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

×
×
  • Create New...

Important Information

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.