Jump to content
KyleK29

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

Recommended Posts

Hi @KyleK29.  First of all thank you so much for not just the syntax but the cumbersome data assembly in excel.  I really appreciate it and I'm sure that everyone else does too. 

I'm having an elementary problem here trying to replicate the fixed $risk hotkey with a live stop.  I keep getting !Invalid Shares error.  I apologize if someone else has solved this same problem - I checked the other two instances of people experiencing similar !Share issues but their problems didn't seem a bit different.  I hope you can give me some direction.  Thank you so much. 

 

Assumptions:

Cash balance: $1,000

Risk per trade: $5 or ½%

Leverage multiplier: 3.3333333

 

Output from Excel:

;CXL ALLSYMB;StopPrice=Price+0.01; DefShare=1000*3.3333333*0.97;Price=Price-Bid+0.01;SShare=5/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;TogSShare;ROUTE=LIMIT;Price=Bid-0;TIF=DAY+;SELL=Send;DefShare=100;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice+0 ACT:BUY STOPPRICE:StopPrice QTY:Pos TIF:DAY+;

 

Broken down:

1

;CXL ALLSYMB;

Cancels existing stops in case this hotkey is used to add to an existing position (that already has a live stop) so that it can wrap up the new position in a new stop at the end.

Side note: I did manually add this one line to the original excel output. 

2

StopPrice=Price+0.01;

 

3

DefShare=5100*3.3333333*0.97;

Discounts 3% intentionally.

4

Price=Price-Bid+0.01;SShare=5/Price;

Assuming ‘SShare=5’ here means $5 risk per trade.

5

Share=DefShare-SShare;

 

6

DefShare=DefShare+SShare;

 

7

SShare=Share;

 

8

Sshare=DefShare-SShare;

 

9

Share=0.5*SShare;

 

10

TogSShare;

 

11

ROUTE=LIMIT;

 

12

Price=Bid-0;

 

13

TIF=DAY+;

 

14

SELL=Send;

 

15

DefShare=100;

 

16

TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice+0 ACT:BUY STOPPRICE:StopPrice QTY:Pos TIF:DAY+;

Now the only stop order should reflect not just this entry but the whole position. 

 

Share this post


Link to post
Share on other sites

Hey @forkey, something is wrong with your hotkey if you got that from Kyle’s spreadsheet. 
 

The DefShare=1000*3.3333333*0.97 portion of your hotkey should look like this: 

DefShare=BP*0.97;Share=DefShare*0.333*Price*0.005

I’m not sure what’s going wrong, but I’d go back to the first post and download it again.

Share this post


Link to post
Share on other sites

Hi @Justin.  I followed your recommendations and downloaded the spreadsheet again. 

My intention is to take Kyle’s buy order with a 1.0% max risk live stop, and make it 1. add liquidity, 2. on ARCAL, and 3. cancel any existing orders on the symbol beforehand.  In what step did I go wrong?

Step

Hotkey

Notes

1

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

Spreadsheet output

2

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

Now routes to ARCA

 

 

3

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

Now adds liquidity on bid

4

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

 

Now cancels existing orders beforehand

 

 

This below 4:1 profit taker order also generated an error.  Does anything look obvious?

Step

Hotkey

Notes

1

Route=Limit;Share=Pos*0.25;Price=AvgCost-StopPrice;Price=Price*1.25;Price=Price+AvgCost;Price=Round2;TIF=DAY+;SELL=Send

Spreadsheet output

2

Route=ARCAL;Share=Pos*0.25;Price=AvgCost-StopPrice;Price=Price*1.25;Price=Price+AvgCost;Price=Round2;TIF=DAY+;SELL=Send

Now routes to ARCA

3

Route=ARCAL;Share=Pos*1.00;Price=AvgCost-StopPrice;Price=Price*1.25;Price=Price+AvgCost;Price=Round2;TIF=DAY+;SELL=Send

Now sells the whole position

4

Route=ARCAL;Share=Pos*1.00;Price=AvgCost-StopPrice;Price=Price*4.00;Price=Price+AvgCost;Price=Round2;TIF=DAY+;SELL=Send

Now sells at 4:1

 

1.     Can the above entry and 4:1 profit taker hotkeys be combined into one single hotkey?  Can it become an OCO?

2.     Does !Invalid shares mean that the syntax is good but the account does not contain sufficient BP to execute?

 

 

Thank you so much @KyleK29, @Justin & community.

Edited by forkey
misspelling
  • Like 1

Share this post


Link to post
Share on other sites

@forkey  The layout is awesome...makes learning for ppl reading very easy....thks 

i will let the experts answer the questions.

Share this post


Link to post
Share on other sites

Hi fellow traders,

I'm very interested in using these hotkeys.

Can anyone tell me where to find the spreadsheet? 

Thx!

Share this post


Link to post
Share on other sites
3 hours ago, Peter de Beir said:

Hi fellow traders,

I'm very interested in using these hotkeys.

Can anyone tell me where to find the spreadsheet? 

Thx!

Hi @Peter de BeirKyle generously posted the downloadable link on the first page of this thread.  At the bottom of the page it will let you navigate to the first page of this thread.  I hope this helps. 

Share this post


Link to post
Share on other sites
On 5/23/2020 at 9:20 AM, forkey said:

1.     Can the above entry and 4:1 profit taker hotkeys be combined into one single hotkey?  Can it become an OCO?

2.     Does !Invalid shares mean that the syntax is good but the account does not contain sufficient BP to execute?

1. Maybe.... I’d have to stare at my screen and think for a good few hours 😛 Will have to wait until the markets are open to give it a shot. I’ll let you know.

2. It’s possible. The hotkey looks good now. Have you tried cranking your BP to something extreme in SIM to test?

Edited by Justin

Share this post


Link to post
Share on other sites
18 hours ago, forkey said:

Hi @Peter de BeirKyle generously posted the downloadable link on the first page of this thread.  At the bottom of the page it will let you navigate to the first page of this thread.  I hope this helps. 

Thanks, it works!

Share this post


Link to post
Share on other sites

Thanks @Justin


 

I think the original problem derived from DAS assuming BP leverage is 4:1 and IB is 3.3333:1 so I will just discount the BP in the syntax to 75% or something like I denoted in the first post: DefShare=BP*0.75; 

 

If I wanted to hard code in the SIM account into these hotkeys, would it twice throughout the syntax because there are two orders like below in red?

 

CXL ALLSYMB; StopPrice=Price-0.01;DefShare=BP*0.75;Share=DefShare*0.99*Price*0.01;Price=Ask-Price+0.01;SShare=Share/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;TogSShare;ROUTE=ARCAL;Price= Bid+0;TIF=DAY+; ACCOUNT=ABCDEFG ;BUY=Send;DefShare=100;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice-0 ACT:SELL STOPPRICE:StopPrice QTY:Pos TIF:DAY+; ACCOUNT=ABCDEFG;

 

Edited by forkey

Share this post


Link to post
Share on other sites
8 minutes ago, forkey said:

I think the original problem derived from DAS assuming BP leverage is 4:1 and IB is 3.3333:1 so I will just discount the BP in the syntax to 75% or something like I denoted in the first post: DefShare=BP*0.75; 

I think by default they make it 4:1 for everyone because US residents get that.  But canadians only get 3.333333.  If you compare your actual BP in TWS and DAS they should be equal and they probably aren't right now.

You can contact DAS and ask them to fix your BP to the actual value so you don't have to mess with the script.  That's what I did.

Share this post


Link to post
Share on other sites
3 hours ago, Yann said:

I think by default they make it 4:1 for everyone because US residents get that.  But canadians only get 3.333333.  If you compare your actual BP in TWS and DAS they should be equal and they probably aren't right now.

You can contact DAS and ask them to fix your BP to the actual value so you don't have to mess with the script.  That's what I did.

Thank you @Yann.  You just saved me from having to hard code a constant 0.75*BP in basically everything ^_^

Share this post


Link to post
Share on other sites

New to the group. In the webinar Kyle mentioned that he is updating the hotkeys into a web browser. Just curious if that has been done or is the link at the beginning of this thread still the most up to date? Thanks

  • Like 1

Share this post


Link to post
Share on other sites
4 minutes ago, Casey Gates said:

New to the group. In the webinar Kyle mentioned that he is updating the hotkeys into a web browser. Just curious if that has been done or is the link at the beginning of this thread still the most up to date? Thanks

Yeah, beginning of the thread is still the most up-to-date. Just use the spreadsheet for now 🙂

  • Like 2

Share this post


Link to post
Share on other sites

Is it possible to do hotkey with stoploss and target like range order. ( im clicking to stoploss on the chart and then hotkey and it buys stock and creates

range order for selling)

Im now using 2 different hotkeys one for buying with stoploss order and second to sell +2R target. And i need to watch if one order is filled i need to delete second. It would be amazing that

im only buying once and no need to watch stock...

If this one hotkey is not possible is it possible to do hotkey with range order -1R and +2R targets?

Edited by Peter
  • Like 2

Share this post


Link to post
Share on other sites
On 5/31/2020 at 12:54 AM, Peter said:

Is it possible to do hotkey with stoploss and target like range order. ( im clicking to stoploss on the chart and then hotkey and it buys stock and creates

range order for selling)

Im now using 2 different hotkeys one for buying with stoploss order and second to sell +2R target. And i need to watch if one order is filled i need to delete second. It would be amazing that

im only buying once and no need to watch stock...

If this one hotkey is not possible is it possible to do hotkey with range order -1R and +2R targets?

+1

I am looking for this as well. I have a frequent problem when I use the 2 separate hotkeys outlined above - if I am in a long position and the stock is not shortable, the bracket order errors out because there is already a sell order placed (the stop loss).

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.