Jump to content

We have moved to Discord. Please click here to join us in the Trading Terminal Discord server.



These forums are read-only.

Recommended Posts

rom30

Hello fellow BBT's,

I have been experimenting with an automated way to manage risk in DAS. What I have so far is a set of hotkeys that can be used for trading. There are a total of 10 hotkeys, 5 for managing long positions and 5 for managing sort position. The intention is to have the the keys automatically calculate share size when entering a position and also define the exit strategy for that position based on risk to reward. These hotkeys are not trivial and require a lot of explanation. If you are interested, keep reading, beware this is a lengthy post. I would greatly appreciate feedback, especial with the math model used to calculate risk.

 

UPDATE 20190126- There is a new version of the spreadsheet and some of the functionally has changed from the original version posted (v1.4). 

 

Background concepts

The scripts are based on a number of parameters, some of which are user defined and some are obtain from DAS. Here are a list of concepts then need to be understood before using the hotkeys.

Equity: Is the amount if cash in your account. DAS has this.

Margin is the margin that your broker gives you. Some brokers give 1:4 some give 1:6. If your equity is $25,000 and you get 1:4 margin then your total baying power is $100,000.

Buying Power: DAS calculates your buying power based on your account equity and margin. Buying power is Equity X Margin.

Percentage of Buying Power to use: This is a user defined percentage to be used. In order to manage risk, the user may decide to only use 10% of the account.

Adjusted Equity: This is Equity X %Percentage of Buying Power

Adjusted Buying Power: This is Buying Power X %Percentage of Buying Power. From here on when we refer to Buying Power in the Hotkeys, we really mean Adjusted Buying Power.

Risk Tolerance: This is a percentage which indicate how much you are willing to risk (lose) in a single trade. A good guideline value for Risk Tolerance is 1% of your Adjusted Equity.

Max. Loss per Trade: This is Adjusted Equity X %Risk Tolerance

Example:

Equity= $25000

Percentage of Buying Power = 10%

Adjusted Equity = $2500

Risk Tolerance = 1%

Max. Loss Per Trade = $25

Risk Per Trade: This is value calculated using using a mathematical model that I have found to approximate the expected change in the price. It is a simple model based on a linear function of the form

f(x)= ax + b

where x is the price of the stock and the constant a is a percentage of the price (user defined) and b is a user Base Risk plus the Spread (Ask-Bid).

I found that a=0.1/100 =0.001 (or 0.1%) works very well in this model.

Base Risk: This is a user defined value which represents the minimum change that a stock can have. What this means is that a minimum a price will move this value. I have 0.05 is a good value for Base Risk. Thus be can be defined as:

b=Spread+0.05 (Spread plus 5 cents)

This is the model used:

f(x) = 0.001 x + 0.05 + Ask – Bid

The model works best with smaller spread (Ask – Bid), simply because a high spread means high risk. In general you should avoid trading when the spread is too high. I personally look for spreads that are less than 0.05.

Let's do an example of the model

Assume are have a stock where

Ask=20.22

Bid=20.2

f(20.22) = 0.001 * 20.22 + 0.05 + 20.22 – 20.2

= 0.09022

The Risk per Trade is 0.09002. What does this mean? Well if you are considering this stock for a long position, it means that the if the stock drops more than 0.09022 in price, you should get out of the trade.

Now that we know our Risk per Trade for this stock, we can define our risk to reward levels

If we take a long position at $20.22, expecting the price to go up, then our stop loss is at $20.1297 (20.22 – 0.09022). At this point we should exit the trade.

The reward at a 1:3 would be when the price gets to $20.49 (20.22 + 3 x 0.09022).

Note: Similar math applies to Shorting a position.

This Risk per Trade model explained above is used in the hotkeys to create STOP Range Order to exit a position either on a STOP Loss or on a reward ( 1:3 or 1:2) level.

Risk per Trade value is also used in some of the hotkeys to automatically determine how many shares to buy and stay within the Max. Loss Per Trade value. This is especially useful to determine how many share to take when the price of a stock is low. If a stock price is less than $30, you should determine the share size using Risk per Trade. There are a couple of hotkeys that will do this for you.

Long Position Keys are used to enter and manage long positions.

ALT+Numpad9    -   Buy X number of share based on Max Risk per Trade and staying within the Buying Power parameters.

ALT+Numpad7    -   Buy X number of shares where X is ½ of the shares of ALT+Numpad9.


ALT+Numpad8   - Send a STOP Range order to Sell with lower price at Ask – Risk per Share

                                and High Price at Ask + 3 Times Risk Per Share (1:3 Risk Reward). This key is

                                based on the current Ask price can be used repeated times while in a trade. Each

                                time that is used, the previous order is canceled and a new one submitted based on

                                the current Ask price. So if the price is moving in your direction you could

                                use this key to “trail” the price, thus protecting your gains and possibly

                                maximizing the gain.

ALT+Numpad/  - Send a STOP Range order to Sell with lower price at Ask – Risk per Share

                              and High Price at Ask + 2 Times Risk Per Share (1:2 Risk Reward)This key is

                              based on the current Ask price can be used repeated times while in a trade. Each

                              time that is used, the previous order is canceled and a new one submitted based on

                              the current Ask price. So if the price is moving in your direction you could

                              use this key to “trail” the price, thus protecting your gains and possibly

                             maximizing the gain.

ALT+Numpad- - Exit the position selling all share

Long-Position-Keys-v1.8.thumb.png.3b5e95efde518c6bcc3ef067838cea4a.png

 

 

Short Position Keys are used to enter and manage short positions.

ALT+Numpad3    -   Short X number based on Max Risk per Trade and staying within the Buying Power parameters.

ALT+Numpad1    -   Short X number of shares where X is ½ of the shares of ALT+Numpad3.


ALT+Numpad2   - Send a STOP Range order to Cover with lower price at Ask – 3 Times Risk per

                                Share and High Price at Ask + Risk Per Share (1:3 Risk Reward). This key is

                                based on the current Ask price can be used repeated times while in a trade. Each

                                time that is used, the previous order is canceled and a new one submitted based on

                                the current Ask price. So if the price is moving in your direction you could

                                use this key to “trail” the price, thus protecting your gains and possibly

                                maximizing the gain.

ALT+Numpad5   - Send a STOP Range order to Cover with lower price at Ask – 2 Times Risk per

                                Share and High Price at Ask + Risk Per Share (1:3 Risk Reward). This key is

                                based on the current Ask price can be used repeated times while in a trade. Each

                                time that is used, the previous order is canceled and a new one submitted based on

                                the current Ask price. So if the price is moving in your direction you could

                                use this key to “trail” the price, thus protecting your gains and possibly

                                maximizing the gain.

ALT+Numpad-   - Exit the position covering all share

Short-Position-Keys-v1.8.thumb.png.f4ce727acc1441adf553a98ec629f195.png

 

How to Use the Keys

The keys are layout for easy use on a full size keyboard.

Buying:

Hold the Alt Key and when ready to buy press one of the Buying (“9” or “7”) from the numeric keypad. For Ask price less than $30 use “7” for higher price use “9”.

Immediately after the order is executed, and while still holding the Alt Key, press one of the STOP Range Sell keys (“8” or “/”). This creates a STOP Range order.

Any time during the trade, you can press Alt+Numpad8 or Alt+Numpad/ to adjust your STOP Range order based on the current Ask/Bid price.

You can also Sell your position anytime during the trade with Alt+Numpad- (minus key).

Shorting:

Hold the Alt Key and when ready to short, press one of the Shorting (“3” or “1”) keys from the numeric keypad. For Ask price less than $30 use “1” for higher price use “3”.

Immediately after the order is executed, and while still holding the Alt Key, press one of the STOP Range Cover keys (“2” or “5”).

Any time during the trade, you can press Alt+Numpad2 or Alt+Numpad5 to adjust your Range order based on the current Ask/Bid price.

You can also Sell your position anytime during the trade with Alt+Numpad+ (plus key).

How to get the hotkey scripts and load top DAS

If you made this far in this, then you are probably interested in giving this a shot. Here is how to get the

scripts:

Step 1:

Read and agree to the license for the scripts:

IMPORTANT Licensing information

These hotkeys/scripts are only meant to assist traders using DASTrader to learn how to trade. They automate simple tasks like share size and creation of Stop Range orders. The scripts are experimental and provided as is with no guarantees. Use these hotkeys/scripts only in a simulator environment to avoid issues. The author is not liable for any damages. The code is licensed as open source under GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.en.html ). Read the license before you proceed to download and use the scripts.

Step 2:

Get and install the OpenOffice suite so that can use the spreadsheet configure your keys. Here is the link for Open Office: https://www.openoffice.org/

Step 3:

Get the spreadsheet from this link: https://www.dropbox.com/s/opzq1ws4005xii4/Trade-Risk-v1.8-beta.ods?dl=0

Step 4:

The default values should work fine for most cases. However should you need to do changes, you can changes these values in the configuration spreadsheet:

Account Equity

Risk Tolerance

Margin

Percentage of Buying Power to use

ROUTE

Base Risk

Percentage or Price to use

Note: Some cells in the sheet are lock/protected to avoid changing them by m,mistake. If you need to change the locked cells you will have to unlock them.

Step 5:

Follow the instructions within the configuration spreadsheet to set the parameters and copy the Hotkey Scripts from the Hotkeys tab within the spreadsheet.

Step 6:

If your DAS is running, then exit DAS.

Find the DAS Directory and make a copy of the hotkey file “Hotkey.htk”. Use a text editor, like Notepad, to open the file Hotkey.htk.  Paste the content from Hotkeys Tab in the spreadsheet above to the end of the file Hotkey.htk and save it.
When you open DAS you will have the 10 Alt keys available. You can examine the scripts in DAS by clicking Setup->Hot Key and scrolling down. The Alt+ keys should be together. Click Cancel to exit the Hot Key tool.

Note: If you are updating your ALT Hotkeys, you must first delete the old hotkey scripts from the Hotkey.htk file. For details follow the Updating Hotkeys instructions below.


Step 7:

Set your DAS to operate with your simulator account for testing.

The hotkeys are now available to for use from any Montage Window. The Montage Window needs to be selected for the keys to work.


Updating Hotkeys

If you already had a set of ALT Hotkeys, and need to update them with new scripts, follow  these steps:

Step 1:

In DAS open Hotkey Tool (Setting > Hot key) locate the Alt+keys and delete them all the Alt+ hotkeys using the Delete Item button. The click OK to Save the file.

Step 2:

Exit DAS

Step 3:

Use OpenOffice to update the hotkey configuration file as needed and save the spreadsheet. Follow the instructions within the configuration spreadsheet to set the parameters and copy the Hotkey Scripts from the Hotkeys tab within the spreadsheet.

Step 4:

Find the DAS Directory and make a copy of the hotkey file “Hotkey.htk”. Use a text editor, like Notepad, to open the file Hotkey.htk.  Paste the content from Hotkeys Tab in the spreadsheet above to the end of the file Hotkey.htk and save it.

When you open DAS you will have the 10 Alt keys. You can examine the scripts in DAS by clicking Setup->Hot Key and scrolling down. The Alt+ keys should be together. Click Cancel to exit the Hot Key tool.

Step 5:

Set your DAS to operate with your simulator account for testing.

The hotkeys are now available to for use from any Montage Window. The Montage Window needs to be selected for the keys to work.

Edited by rom30
Update to V1.8 of scripts
  • Like 6
  • Thanks 1

Share this post


Link to post
Share on other sites

[[Template core/front/global/mobileNavigation is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]]

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.