Jump to content
KyleK29

DAS - Dynamically Calculate Shares on %Risk or $Risk - Hot Key + Configuration, Updated 10/17

Recommended Posts

13 hours ago, Jason W said:

I'm not even sure if DAS knows the difference. Because DAS does not separate long BP  and short BP 

If DAS does not know the difference, then the value should still be 0.25 right ?

If DAS knows the difference, then 0.3 is fine. 

There is no way to test this in the SIM, SIM has the same buying and shorting power I think. 

So I'm gonna have to take one for the team .....   

Thanks again Kyle. 

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.

Edited by KyleK29
  • Like 1

Share this post


Link to post
Share on other sites
On 10/3/2018 at 5:41 PM, Seamus said:

Kyle. 

Appreciate the reply and quick dive on your part into Genovation. I believe that yes, installs are complete. I understand the hotkey creation in DAS without any real issue, so I believe I’ve the handle on basic practice. I’m stuck on what I’d call mapping or quite possibly, I don’t fully understand the Genovation (external keypad) concept. 

A conventional “buy now at +.05” assigned to F1 makes sense. The Geno keypad doesn’t have an F1 and for the matter, it doesn’t appear any key is fixed to the system. I also cannot locate a cell or placement in the setup Geno software where I would establish say, the top left key is recognized by the system as F1 and thus, maps the command when said Geno button is pressed. I’m pretty certain I am making the situation quite complicated.

The trading theory currently studied is rather intuitive in my brain, programming...not so much. 

Thanks again man for the reply. 

Also, take a look at this thread: 

Appears there might be an issue with the Windows 10 drivers, so you have to use Flash Drive mode for programming. They'll be able to help a tad more, as they have the device.

 

Edited by KyleK29

Share this post


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

  • Like 1

Share this post


Link to post
Share on other sites

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.

20181011_151702.thumb.jpg.4b11a6de605c008d703aad2c2a4a4052.jpg

  • Like 1

Share this post


Link to post
Share on other sites

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.

 

  • Like 1

Share this post


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

  • Like 2

Share this post


Link to post
Share on other sites

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.

  • Like 2

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