Jump to content
KyleK29

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

Recommended Posts

19 hours ago, KyleK29 said:

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.

 

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.

Not to reply to myself, but I played around with this some more and got the Trigger queue working for the stop, so that way we only send a physical STOP to the market when the initial order is returned as a successful fill. 

I'll post an update test command in a few minutes.

 

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; TriggerOrder=RT:STOP STOPTYPE:MARKET STOPPRICE:StopPrice ACT:SELL QTY:Pos TIF:DAY+;

Just a single one for testing in SIM. If anyone wants to hammer and see if you can get some anomalies before I work it into the configuration. What it does:

Long:
- Moves Double-Clicked price to stop
- Does the dollar risk up above calculation ($120 risk)
- Setups a Trigger order in queue for STOP with MARKET ORDER at original stop click location, quantity is set to filled quantity.

 

I'll include these additional ones in the video how-to:

STOP ORDER MODIFIERS:

- On "Orders" window (shows pending orders not fulfilled, the stop will be here), double-click the STOP and it'll load into the MONTAGE
- Execute a hotkey with the following command

Update Existing Stop Order with New Position (e.g. to be done after a scale out):

Share=Pos;Replace;

 

Change Stop Position to New Price + Update Position Size (if changed):

In This Order:
- Orders Window --> Double Click Stop
- Double Click area on chart you want to set the stop price to (or type it into the price field)
- Execute the hotkey with this command:

Share=Pos;StopPrice=Price;Replace;

 

Edited by KyleK29
  • Like 1

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

Share this post


Link to post
Share on other sites
On 9/29/2018 at 2:07 PM, Seamus said:

Holy smokes. You are super smart sir.

I'm brand new and struggling to understand the setup of my initial Hotkeys. This provided version of yours is incredible. Thank you.

Now, if I can only figure out how to program this darn Genovation 24 keypad...but I digress.

seamus

I had so much trouble with my genovation 24 I sent it back for a refund. I am using windows 10 as im assuming you are as well.  I got the stream deck now and love it. GameStop has them on sale for $115.00. You want to get the 15 key and not the mini if you decide to get the stream deck. Also if you search stream deck here in this forum you will see lots of threads on it with different setups. Hope that helps and good luck.

Share this post


Link to post
Share on other sites

Added a BETA version incorporating Robert H's request for a stop order to be sent with the initial order. If anyone wants to play with this and make sure it's doing what it's supposed to do, please post back. This will likely be the version I make a how-to video on, so if a few people say this is working correctly, I can get that done.

Full notes are in the original post under "UPDATES" section.

 

From a prior post, additional hotkeys for modifying the stop-orders. IMPORTANT: If you use a physical stop order you *must* update the position size when you scale in or out, otherwise the order will flip your position. If anyone knows how to prevent that with a command (e.g. only sell/cover to zero position), please let me know. 

STOP ORDER MODIFIERS:

- On "Orders" window (shows pending orders not fulfilled, the stop will be here), double-click the STOP and it'll load into the MONTAGE
- Execute a hotkey with the following command

Update Existing Stop Order with New Position (e.g. to be done after a scale out):

Share=Pos;Replace;

 

Change Stop Position to New Price + Update Position Size (if changed):

In This Order:
- Orders Window --> Double Click Stop
- Double Click area on chart you want to set the stop price to (or type it into the price field)
- Execute the hotkey with this command:

Share=Pos;StopPrice=Price;Replace;

 

Edited by KyleK29
  • Like 1

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

Share this post


Link to post
Share on other sites

Hello,

I'm having a using this hotkey. When I hit my hotkey the following error pops up. I'm using the following scripts:

Long $20 dollar risk:

DefShare=BP*0,97;Price=Ask-Price+0,02;SShare=20/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;

Short $20 dollar risk:

DefShare=BP*0,97;Price=Price-Bid+0,02;SShare=20/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=400;

image.png.1b14c3ef8c0bbae813e9d90bd59bb361.png

Can someone help me with this problem? Thanks in advance.
 

Share this post


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

Hello,

I'm having a using this hotkey. When I hit my hotkey the following error pops up. I'm using the following scripts:

Long $20 dollar risk:

DefShare=BP*0,97;Price=Ask-Price+0,02;SShare=20/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;

Short $20 dollar risk:

DefShare=BP*0,97;Price=Price-Bid+0,02;SShare=20/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=400;

image.png.1b14c3ef8c0bbae813e9d90bd59bb361.png

Can someone help me with this problem? Thanks in advance.
 

Are you European? It seems that all of the periods were replaced with comma's, I assume this is from an Excel version setup for Europe.

 

Since DAS doesn't support the difference, I'll see if I can force periods for all regions in the spreadsheet.

 


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

Share this post


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

Are you European? It seems that all of the periods were replaced with comma's, I assume this is from an Excel version setup for Europe.

 

Since DAS doesn't support the difference, I'll see if I can force periods for all regions in the spreadsheet.

 

Yes, I am indeed European. I changed the commas into dots and now it works as it should. Thanks

Share this post


Link to post
Share on other sites
On 11/15/2018 at 10:32 PM, KyleK29 said:

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

Sorry for not replying to you sooner. I had problems the first few days but now it works flawlessly. Anyway, thank you for making this, it really helps me when I trade.

Share this post


Link to post
Share on other sites

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?  

 

Edited by Martin G

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

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!

Edited by ragycpa

Share this post


Link to post
Share on other sites

@ragycpa

Right-click in the chart and select Configure, then check the box Double-click to trade and click OK.

DCTT.JPG.4f8ec78594a78c462c52d8a43e2fb141.JPG

 

Edited by Martin G

Share this post


Link to post
Share on other sites

@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?

Share this post


Link to post
Share on other sites
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

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

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

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.