Peter’s Substack

Peter’s Substack

Share this post

Peter’s Substack
Peter’s Substack
DAS Trader Pro Advanced Hotkeys part 35
DASTrader Hotkeys

DAS Trader Pro Advanced Hotkeys part 35

How to add into the position while keeping the risk the same. Trial and error method.

Peter Benci's avatar
Peter Benci
Feb 25, 2025
∙ Paid
2

Share this post

Peter’s Substack
Peter’s Substack
DAS Trader Pro Advanced Hotkeys part 35
Share

Thanks to one of my readers, the real world use showed that my post 5 about this topic is not correct.

DAS Trader Advanced hotkeys part 5

DAS Trader Advanced hotkeys part 5

Peter Benci
·
May 17, 2024
Read full story

The logic is flawed, and technically it does not work properly. I tried to do my best to solve the logical problem there but could not figure it out in terms of a formula because the situation changes if the add is happening before reaching unrealized profit of 1R, then it changes completely. At the same time, it does not count in the unrealized profits.

If you are interested about the details of the flawed logic, just send me a message.

I was thinking about it and really could not sort it out logically, so I tried a trial and error approach instead. It turned out to be a good exercise for a proof-of-concept as this method of trial and error can be used in other use cases as well, so you do not have to be the biggest brain in the world to make your life with DAS Trader Pro easier.

The use case

When my position is in profit, I want to add to it but still risk only 1R.

Original entry
Add into position situation

My hotkey script will do the following

  1. decide what increments we will try to add based on price

  2. check if I have enough buying power for the add

  3. check if the shares I want to add would increase my risk over 1R

  4. depending on the previous conditions, it will construct and send the order

The logical graph of the above with some example values looks like this

Prerequisites

I will be using a new approach to the order creation with newer and more bullet-proof syntax. The reason is that now having the possibility to have the buttons around any window we like the focused window where you press the button can cause issues in cases you need to read or set some values to your montage which is not in focus.

I expect you have click to trade enabled on your charts.

Variables preparations

We will need a $MONTAGE object variable for the corresponding montage window where we want the orders to be processed. The montage window is named MONTAGE1 in my case.

//desired risk definition
$DRISK=10;
//set your montage window name below
$MONTAGE=GetWindowObj("MONTAGE1");
//read the new stop
$NEWSTOP=$MONTAGE.Price;
//read the BP left
$MYBP=GetAccountObj($MYACCOUNT).BP;
$NEWSHARES=0;
//reset the loop variable
$LOOP=0;

This is valid if you want to use it as not a montage window hot button.

If you use the montage hot button, you can use the $MYMONT variable as show below instead.

//read montage window
$MYMONT=getwindowobj().name;
//desired risk definition
$DRISK=10;
//set your montage window name below
$MONTAGE=GetWindowObj($MYMONT);
//read the new stop
$NEWSTOP=$MONTAGE.Price;
//read the BP left
$MYBP=GetAccountObj($MYACCOUNT).BP;
$NEWSHARES=0;
//reset the loop variable
$LOOP=0;

Do not forget to put your actual account name or account name variable in the $MYBP line.

The calculations

Several calculations and a loop will be needed, together with some helper variables. The loop limit is 199 repetitions, so we need to make sure that we can reach the desired position size within 199 loops.

$INCREMENTS variable will be the tunable variable to decide in what increments we want the adds to be tested. It will depend on your personal settings. If you risk $10 you want the $INCREMENTS to be small, if you risk $1000 and trade penny stocks you want that number to be 500 or 1000.

$BPCHECK variable will be storing the buying power needed for the desired position. It will be compared against our BP

Increments definition

The $INCREMENTS variable will have 2 options, but it is easy to add more conditions to add more granularity with 4 or 8 options. I will be testing with $10 risk with stocks between $10 and $200 which can result in position sizes between 10 and 500 so theoretically I would be fine with an increment of 3 but to show the possibility to adapt it to the actual stock price and various needs I will use 2 increment sizes.

if($montage.last<100)
{
$INCREMENTS=10
}
else
{
$INCREMENTS=2
}

This should be enough for this example as 199 loops of 10 increments will go up to 1990 shares and 199 loops of increments of 2 would be 398.

The loop

I start the cycle of virtual add and test with some helper variables. I need to know

  1. the new number of shares

  2. the new average price

  3. the new stop

I am using a $NEWRISKTOSTOP variable to store the calculation data and a $NEWSHARES variable to store the new virtual position size and $NEWAVGPRICE to calculate the new virtual average price. The new stop comes from the chart-click on the previous code. The $NEWRISK variable finally shows the calculated virtual risk for the virtual position. As DAS Trader Pro cannot understand complex formulas like below

$NEWSHARES=$NEWSHARES+$INCREMENTS;
$NEWAVGPRICE=(($NEWSHARES*$MONTAGE.LAST)+($MONTAGE.POS*$MONTAGE.AVGCOST))/($NEWSHARES+$MONTAGE.POS);
$NEWRISKTOSTOP=$NEWAVGPRICE-$NEWSTOP;
$NEWRISK=$NEWSHARES*($NEWAVGPRICE-$NEWSTOP);

I will need to use some temporary variables instead. Each brackets section as a separate variable.

//LOOP START
while ($LOOP<199)
{
//break this into variables $NEWAVGPRICE=(($NEWSHARES*$MONTAGE.LAST)+($MONTAGE.POS*$MONTAGE.AVGCOST))/($NEWSHARES+$MONTAGE.POS);
$TEMPA=$NEWSHARES*$MONTAGE.LAST;
$TEMPB=$MONTAGE.POS*$MONTAGE.AVGCOST;
$TEMPBOTTOM=$NEWSHARES+$MONTAGE.POS;
$TEMPTOP=$TEMPA+$TEMPB;
$NEWAVGPRICE=$TEMPTOP/$TEMPBOTTOM;
$NEWRISKTOSTOP=$NEWAVGPRICE-$NEWSTOP;
$NEWRISKTOSTOP=ABS($NEWRISKTOSTOP);
$TEMPD=$NEWAVGPRICE-$NEWSTOP;
$NEWRISK=$TEMPBOTTOM*$NEWRISKTOSTOP;
$BPNEEDED=$NEWSHARES*$MONTAGE.LAST;
//bp check first
if ($BPNEEDED>$MYBP)
{
$NEWSHARES=$NEWSHARES-$INCREMENTS;
$LOOP=200;
}
else
//desired risk check
{
if ($NEWRISK<$DRISK)
{
$NEWSHARES=$NEWSHARES+$INCREMENTS;
$LOOP=$LOOP+1;
}
else
{
$NEWSHARES=$NEWSHARES-$INCREMENTS;
$LOOP=200;
}
}
}
//LOOP END

BP and desired risk check

Check if I have enough BP for the virtual position and check if the virtual risk is less than desired risk

//bp check
if ($BPNEEDED>$MYBP)
{
$NEWSHARES=$NEWSHARES-$INCREMENTS;
}
else
//desired risk check
{
if ($NEWRISK<$DRISK)
{
$NEWSHARES=$NEWSHARES+$INCREMENTS;
}
else
{
$NEWSHARES=$NEWSHARES-$INCREMENTS;
}
}

Construction of the order

At this point everything is calculated we only need to set the values into the montage and submit the order. Please note the newer syntax for order submission.

//what to do if long
if ($MONTAGE.Getcurrpos()>0)
{
$MONTAGE.PRICE=ROUND($MONTAGE.LAST*1.003,2);
$MONTAGE.BUY;
$MONTAGE.TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$NEWSTOP ACT:SELL STOPPRICE:$NEWSTOP QTY:Pos TIF:DAY;
}
//what to do if short
if ($MONTAGE.Getcurrpos()<0)
{
$MONTAGE.PRICE=ROUND($MONTAGE.LAST*0.997,2);
$MONTAGE.SELL;
$MONTAGE.TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$NEWSTOP ACT:BUY STOPPRICE:$NEWSTOP QTY:Pos TIF:DAY;
}

I am checking if the current position is negative or positive meaning short or long and depending on the current position side, the corresponding order is created to add into the position by selling or buying more shares.

TLDR

The whole hotkey for adding into a position looks like this. Let’s call it static risk add hotkey.

Keep reading with a 7-day free trial

Subscribe to Peter’s Substack to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Peter Benci
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share