DAS Trader Advanced hotkeys part 5
How to build up a position while keeping the risk the same
This article is edited 3rd time thanks to my readers. The same can be achieved with a trial and error method, which is shown in the part 35. As I made the correction to the incorrect formulas, I will add a new syntax for those who use multiple montage windows.
See the other posts about DASTrader hotkeys here.
One of you readers asked me for this hotkey and I must admit it was a challenging one to crack.
The objective of this hotkey is to add into a position (or lower the number of shares) while changing the stop loss and keep the risk on the desired level.
It can be very practical to build up a position or to get back into full size after a partial. You can use the hotkey to open a position too which is also very practical as you press only one hotkey for opening the position or to add into a position.
Example:
You buy a stock that costs $100, and you set your stop to $99 while you want to risk $100.
You open the position with the previous hotkeys or any other way you like. In this case you buy 100 shares.
Now when the price action moves to $101 you want to add to your position while having the new stop loss at $100.50.
This means you are now opening a new position at $101 with a stop loss of $0.5 while having a $100 of unrealized profit.
Normally you would open the position with 200 shares but having 100 shares already from the previous entry makes things a bit different now as 200 shares would bring you to 300 shares and if the new stop loss would be hit you would lose $100 from the new position plus $50 from the unrealized gains from the position you stared.
The formula for counting the correct number of shares needed for a long trade is:
Simple Hotkey to add into a long position while keeping the desired risk
$DRISK=20;
//change this for the desired risk;
CXL ALLSYMB;
//cancel previous order
//start of calculation
$NEWSTOP=Price;
$DIFF=ASK-Price;
$TBRLS=POS*AVGCOST;
$TBRRS=POS*$NEWSTOP;
$TBR=$TBRLS-$TBRRS;
$TOP=$DRISK-$TBR;
$X=$TOP/$DIFF;
//end of calculations
SHARE=$X;
Price=Ask+0.05;
TogSShare;
TIF=DAY+;
ROUTE="LIMIT";
//change this for your broker’s route;
BUY=SEND;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$NEWSTOP ACT:SELL STOPPRICE:$NEWSTOP QTY:Pos TIF:DAY+;
…or with the newer syntax to allow multiple montage windows and hot buttons around charts. You need to name your montage window (MONTAGE1 in this example)
$MONTAGE=getwindowobj("MONTAGE1");
$DRISK=20;
//change this for the desired risk;
$MONTAGE.CXL ALLSYMB;
//cancel previous order
//start of calculation
$NEWSTOP=Price;
$DIFF=ASK-Price;
$TBRLS=POS*AVGCOST;
$TBRRS=POS*$NEWSTOP;
$TBR=$TBRLS-$TBRRS;
$TOP=$DRISK-$TBR;
$X=$TOP/$DIFF;
//end of calculations
$MONTAGE.SHARE=$X;
//change to 4 for sub dollar stock price
$MONTAGE.Price=ROUND($MONTAGE.Ask*1.003,2);
$MONTAGE.TIF=DAY+;
$MONTAGE.ROUTE="LIMIT";
//change this for your broker’s route;
$MONTAGE.BUY;
$MONTAGE.TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$NEWSTOP ACT:SELL STOPPRICE:$NEWSTOP QTY:Pos TIF:DAY+;
Similarly, the same can be applied for short trades
The formula for counting the number of shares needed for a short trade is:
Simple Hotkey to add into a short position while keeping the desired risk
$DRISK=20;
//change this for the desired risk;
CXL ALLSYMB;
//cancel previous order
//start of calculation
$NEWSTOP=Price;
$DIFF=Price-BID;
$TBRLS=POS*$NEWSTOP;
$TBRRS=POS*AVGCOST;
$TBR=$TBRLS-$TBRRS;
$TOP=$DRISK-$TBR;
$X=$TOP/$DIFF;
//end of calculations
SHARE=$X;
Price=Bid-0.05;
TogSShare;
TIF=DAY+;
ROUTE="LIMIT";
//change this for your broker’s route;
SELL=SEND;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$NEWSTOP ACT:BUY STOPPRICE:$NEWSTOP QTY:Pos TIF:DAY+;
…or with the newer syntax to allow multiple montage windows and hot buttons around charts. You need to name your montage window (MONTAGE1 in this example)
$MONTAGE=getwindowobj("MONTAGE1");
$DRISK=20;
//change this for the desired risk;
$MONTAGE.CXL ALLSYMB;
//cancel previous order
//start of calculation
$NEWSTOP=Price;
$DIFF=Price-BID;
$TBRLS=POS*$NEWSTOP;
$TBRRS=POS*AVGCOST;
$TBR=$TBRLS-$TBRRS;
$TOP=$DRISK-$TBR;
$X=$TOP/$DIFF;
//end of calculations
$MONTAGE.SHARE=$X;
//change to 4 for sub dollar stocks
$MONTAGE.Price=round($MONTAGE.Bid*0.997,2);
$MONTAGE.TIF=DAY+;
$MONTAGE.ROUTE="LIMIT";
//change this for your broker’s route;
$MONTAGE.SELL;
$MONTAGE.TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$NEWSTOP ACT:BUY STOPPRICE:$NEWSTOP QTY:Pos TIF:DAY+;
I call the hotkeys above simple as they contain no conditions. Advanced Hotkey that will drop shares from your position using conditions might be one of the future posts so keep subscribed so you do not miss it.
Hi Peter,
coming from part 35, there is a correct math formula to calculate the adding size, I wrote my code by my own and tested hundreds of times and it's no problem. I did a careful look into your code, and found your math formula used a wrong variable and thus flawed. Since I'm not a subscriber I can't DM you, so I'll leave it here and hope you can see:
for example adding long position, the correct math using your way should be
{RISK - (CURRENT POS * AVG PRICE - CURRENT POS * YOUR_NEW_STOP_PRICE}/{CURRENT PRICE - NEW STOP}
the difference is this YOUR_NEW_STOP_PRICE part, and the hotkey shall work again. hope it helps!
Hello Peter,
So if I understand correctly, this is very similar to the Free roll hotkey from part 2, but in free roll along with adding more we are moving stop loss to breakeven. In this case we are adding more but also specifying the new stop loss risk dollar amount (which is different than breakeven) . Can you please confirm.