DAS Trader Advanced Hotkeys part 2
Advanced hotkeys for easy order and risk management.
See the other posts about DASTrader hotkeys here
New features in DAS Trader
Since August 2023 we can use the Advanced features in the scripts. To be able to use them, we need to enable those features first.
The new features allow the use of the following use cases:
use IF/ELSE statements in scripts. For example, make a condition to open only a smaller risk position if certain conditions are not met or do not allow taking a position if one of your indicators is not where it needs to be for an entry.
attach scripts to a chart, allowing us to react to what is on the chart. For example, exit a trade once the price is below an indicator. Or just simply read any changing indicator from that chart.
use custom variables and thus store any value in a variable of your choice. This makes the syntax of the hotkeys much more intuitive and human-readable.
draw lines on a chart with a hotkey. For example, draw your target lines or show the ATR on the current chart
!!! IMPORTANT INFO !!!
Always test the hotkeys in SIM account first.
You need the latest version of DAS for this to function properly.
You need to set DAS configuration parameters as described here
All the following examples are for the use with Interactive Brokers. For different brokers, you will have to change the ROUTE parameter in all the hotkeys. Check with your broker on the route names to be used.
The usage of the route and order type affects your commission price, so be aware of the routes and order types.
I will keep this page updated for the latest syntax for the latest versions of DAS as the new features are being developed.
beware of the quotes “ is not the same as "
Entries hotkeys
Static risk of $20 with automatic stop loss order attached
For a long position, double-click on the chart, where the desired stop loss price is and press the hotkey:
CXL ALLSYMB;
$buyprice=Ask;
$risk=20;
$mystop=price;
$pricetostop=$buyprice-$mystop;
$amount=$risk/$pricetostop;
SShare=$amount;
Share=$amount;
TogSShare;
ROUTE=
"SMRTL
";
Price=$buyprice*1.005;
Price=ROUND2;
TIF=DAY+;
BUY=Send;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$mystop ACT:SELL STOPPRICE:$mystop QTY:Pos TIF:DAY+
For a short position, double-click on the chart, where the desired stop loss price is and press the hotkey:
CXL ALLSYMB;
$sellprice=Bid;
$risk=20;
$mystop=price;
$pricetostop=$mystop-$sellprice;
$amount=$risk/$pricetostop;
SShare=$amount;
Share=$amount;
TogSShare;
ROUTE=
"SMRTL
";
Price=$sellprice*0.995;
Price=ROUND2;
TIF=DAY+;
SELL=Send;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$mystop ACT:BUY STOPPRICE:$mystop QTY:Pos TIF:DAY+
Static risk with $20 and attached range (OCO) orders of 3R target
For more visibility I set few variables which are not necessary for the functionality but it is easier to understand what is going on in the hotkey
For a long position, double-click on the chart where the desired stop loss price is and press the hotkey:
CXL ALLSYMB;
$buyprice=Ask;
$risk=20;
$mystop=price;
$pricetostop=$buyprice-$mystop;
$target=3*$pricetostop+Ask;
$amount=$risk/$pricetostop;
SShare=$amount;
Share=$amount;
TogSShare;
ROUTE="SMRTL";
Price=$buyprice;
Price=ROUND2;
TIF=DAY+;
BUY=Send;
TriggerOrder=RT:STOP STOPTYPE:RANGEMKT LowPrice:$mystop HighPrice:$target ACT:SELL QTY:POS TIF:DAY+;
For a short position, double-click on the chart where the desired stop loss price is and press the hotkey:
CXL ALLSYMB;
$sellprice=Bid;
$risk=20;
$mystop=price;
$pricetostop=$mystop-$sellprice;
$target=Bid-$pricetostop-$pricetostop-$pricetostop;
$amount=$risk/$pricetostop;
SShare=$amount;
Share=$amount;
TogSShare;
ROUTE="SMRTL";
Price=$sellprice;
Price=ROUND2;
TIF=DAY+;
SELL=Send;
TriggerOrder=RT:STOP STOPTYPE:RANGEMKT LowPrice:$target HighPrice:$mystop ACT:BUY QTY:POS TIF:DAY+;
Future/stop order entries with static risk of $20 and attached range (OCO) orders of 3R target
Future entries are technically stop orders, not to be confused with stop loss orders, I keep using the term future entries as it indicates that you set up an order for an entry in the future.
In the following video I want to go short AAL when it reaches 15.22 and my stop to be at 15.25. I want to risk $20 so that is 666 shares for the 3 cents risk while I want to target 3R profit down to 15.13. All is calculated automatically by the hotkey script.
Once the trade triggers, the automatic stop loss and profit target order is created. I can then move the stop and target as I want.
For the above functionality, it is a 2-step process.
we set the desired stop
we set the desired entry price
Although it is possible to write a single hotkey for both long and short with the new features, I use separate hotkeys for long and for short positions.
The first step is the same for both of the entries, as it does not matter if we want to go long or short to set a stop loss price.
To set the desired stop, I use a MYSTOP variable to store the price. Double-click on the chart, then press the hotkey:
$MYSTOP=Price
To set the desired entry point of a LONG position, double-click on the chart and press the hotkey:
CXL ALLSYMB;
$MYRISK=Price-$MYSTOP;
$MYTARGET=Price+$MYRISK+$MYRISK+$MYRISK;
$MYSHARES=20/$MYRISK;
Share=$MYSHARES;
TogSShare;
StopPrice=Price;
TIF=DAY+;
Route="STOP";
StopType="Limit";
Price=Price+0.05;
Buy=Send;
TriggerOrder=RT:STOP STOPTYPE:RANGEMKT LowPrice:$MYSTOP HighPrice:$MYTARGET ACT:SELL QTY:POS TIF:DAY+;
To set the desired entry point of a SHORT position, double-click on the chart and press the hotkey:
CXL ALLSYMB;
$MYRISK=$MYSTOP-Price;
$MYTARGET=Price-$MYRISK-$MYRISK-$MYRISK;
$MYSHARES=20/$MYRISK;
Share=$MYSHARES;
TogSShare;
StopPrice=Price;
TIF=DAY+;
Route="STOP";
StopType="Limit";
Price=Price-0.05;
Sell=Send;
TriggerOrder=RT:STOP STOPTYPE:RANGEMKT LowPrice:$MYTARGET HighPrice:$MYSTOP ACT:BUY QTY:POS TIF:DAY+;
To change the risk in the above scripts, change the number 20 to any desired risk, meaning a dollar amount.
To change the desired entry threshold, change the 0.05 number meaning dollar amount of your desired entry threshold. For a long position, if the price is $10 this means you are willing to take the trade up to $10.05 price but no higher.
To change the profit target, just add (long) or subtract (short)more $MYRISK variables into the $MYTARGET variable line.
Future entries with static risk and attached stop loss orders
Same as above, two-step process.
To set the desired stop, I use a $MYSTOP variable to store the price. Double-click on the chart, then press the hotkey:
$MYSTOP=Price
To set the desired entry point of a LONG position, double-click on the chart and press the hotkey:
CXL ALLSYMB;
$MYRISK=Price-$MYSTOP;
$MYSHARES=20/$MYRISK;
Share=$MYSHARES;
TogSShare;
StopPrice=Price;
TIF=DAY+;
Route="STOP";
StopType="Limit";
Price=Price+0.05;
Buy=Send;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$MYSTOP ACT:SELL STOPPRICE:$MYSTOP QTY:Pos TIF:DAY+;
To set the desired entry point of a SHORT position, double-click on the chart and press the hotkey:
CXL ALLSYMB;
$MYRISK=$MYSTOP-Price;
$MYSHARES=20/$MYRISK;
Share=$MYSHARES;
TogSShare;
StopPrice=Price;
TIF=DAY+;
Route="STOP";
StopType="Limit";
Price=Price-0.05;
Sell=Send;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$MYSTOP ACT:BUY STOPPRICE:$MYSTOP QTY:Pos TIF:DAY+;
To change the risk in the above scripts, change the number 20 to any desired risk, meaning a dollar amount.
To change the desired entry threshold, change the 0.05 number meaning dollar amount of your desired entry threshold. For a long position, if the price is $10 this means you are willing to take the trade up to $10.05 price but no higher.
Exit hotkeys
Partially exit 50% of a position and set the stop loss to break-even
For a long position, press the hotkey:
CXL ALLSYMB;
ROUTE="SMRTL";
Price=BID-0.05;
Price=Round2;
Share=Pos*0.50;
TIF=DAY;
SELL=Send;
ROUTE="STOP";
StopType="Market";
StopPrice=AvgCost;
Share=Pos-share;
TIF=DAY+;
SELL=SEND;
For a short position, press the hotkey:
CXL ALLSYMB;
ROUTE="SMRTL";
Price=ASK+0.05;
Price=Round2;
Share=Pos*0.50;
TIF=DAY+;
BUY=Send;
ROUTE="STOP";
StopType="Market";
StopPrice=AvgCost;
Share=Pos-share;
TIF=DAY+;
BUY=SEND
If you need different percentage exits, just change the number 0.50 to the desired number. 0.50 meaning 50% of the position.
Exit the whole position now
To exit the whole long position, use the hotkey:
CXL ALLSYMB;
Route="SMRTL";
Share=Pos;
Price=Bid-0.05;
TIF=DAY;
SELL=Send
To exit the whole short position, use the hotkey:
CXL ALLSYMB;
Route="SMRTL";
Share=Pos;
Price=Ask+0.05;
TIF=DAY+;
BUY=Send
Add-up hotkeys
You can use any of the open position hotkeys for add-ups, and the final stop loss or range orders will be updated with the whole position automatically. It is possible to treat each order as a separate one, though. I never use it that way, so if you need such a hotkey, send me a message and I will add it.
Free roll hotkey
This powerful add-up hotkey is able to add to your position without increasing your risk. It requires that the price action moves in your favor first, then it automatically calculates the unrealized profits for your new desired stops and add so many shares to your position so that when the new stop is reached, you will exit with 0 loss.
Let’s say you buy 100 shares of a stock for $10. The price action then goes higher to $11. You want to add to your position for the break of $11 and want to risk the unrealized profits while using the new stop of $10.90. The hotkey will calculate the number of shares to add for the unrealized $90 profit, thus adding 900 shares.
100x10+900x11 = 10900 which is the same as
1000+9900 which is the same as
10900
so with 1000 shares the average price is $10.90. The hotkeys have a lot of temporary variables for now which can be perhaps simplified later on, so make sure to come back to have the latest working hotkey.
Please remember, there is some rounding involved in these calculations, so you might end up slightly off the true break-even price point.
Free roll long, double-click the desired price on the chart and press the hotkey:
CXL ALLSYMB;
$C=Ask;
$N=Pos;
$A=Price;
$P=AvgCost;
$AN=$A*$N;
$NP=$N*$P;
$ANmNP=$AN-$NP;
$CmA=$C-$A;
$X=$ANmNP/$Cma;
SSHARE=$X;
Price=Ask+0.05;
TogSShare;
TIF=DAY+;
ROUTE="SMRTL";
BUY=SEND;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$A ACT:SELL STOPPRICE:$A QTY:Pos TIF:DAY+;
Simplified version for DAS Trader pro 5.8.0.1 and later
CXL ALLSYMB;
$stopprice=Price;
SHARE=(Price*Pos-Avgcost*Pos)/(Ask-Price);
Price=ROUND(Ask*1.003,2);
TIF=DAY+;
ROUTE=SMRTL;
BUY=SEND;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$stopprice ACT:SELL STOPPRICE:$stopprice QTY:Pos TIF:DAY+;
Free roll short, double-click the desired price on the chart and press the hotkey:
CXL ALLSYMB;
$C=Bid;
$N=Pos;
$A=Price;
$S=AvgCost;
$AN=$A*$N;
$NS=$N*$S;
$ANmNS=$AN-$NS;
$X=$ANmNS/$CmA;
SSHARE=$X;
Price=Bid-0.05;
TogSShare;
TIF=DAY+;
ROUTE="SMRTL";
SELL=SEND;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$A ACT:BUY STOPPRICE:$A QTY:Pos TIF:DAY+;
Simplified version for DAS Trader Pro 5.8.0.1 and later
CXL ALLSYMB;
$STOPPRICE=Price;
Share=(Price*Pos-Avgcost*Pos)/(Bid-Price);
Price=ROUND(Bid*0.997,2);
TIF=DAY+;
ROUTE=SMRTL;
SELL=SEND;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$STOPPRICE ACT:BUY STOPPRICE:$STOPPRICE QTY:Pos TIF:DAY+;
Change stop loss hotkeys for existing positions
On the following hotkeys, it does not matter if you have a long or a short position opened. It also works with the old syntax on older versions of DAS too, as there is nothing from the new features to be used.
The hotkeys are very useful once you end up without a stop loss order. This can happen by various miss-clicks or if you try to add-up to your position and your order is denied because of insufficient buying power, margin requirements or just not being filled due to erratic price-action.
You can edit the stop orders by dragging them on the chart too, so if you have a range order set, it is more practical to drag the stop loss orders instead.
Set stop to break-even point
To set the stop loss order to your average price (break-even point) press the hotkey:
CXL ALLSYMB;
Route="Stop";
Price=AvgCost;
StopType="MARKET";
STOPPRICE=AvgCost;
StopPrice=Round2;
Share=Pos;
TIF=DAY;
Send=Reverse;
Set stop to desired price
This is a two-step process. 1st, double-click on the price where you want your stop to be set in the chart. Then press the following hotkey:
CXL ALLSYMB;
Route="Stop";
Share=Pos;
StopPrice=Price;
StopType="MARKET";
TIF=DAY;
Send=Reverse;
Set a position flip order
This is the same as above, just the position is doubled, effectively flipping the position. After the order is triggered, you will have to set the new stop in any of the previously mentioned ways.
CXL ALLSYMB;
Route="Stop";
Share=Pos*2;
StopPrice=Price;
StopType="MARKET";
TIF=DAY;
Send=Reverse;
Dude, I just discovered your blog and it's amazing. It's going to change my trading life.
Can't wait to try these hotkeys on Monday.
Hi Peter, Love your scripts, good work, thank you.
I need to ask you if is it even possible,
Static risk with $20 and attached range (OCO) orders of 3R target - for this script,
can we have two different range orders at the end with 50% position out at 3R and rest of 50% at 4R? like two different targets?