Peter’s Substack

Peter’s Substack

DASTrader Hotkeys

DAS Trader Pro Advanced Hotkeys part 62

Trail to any study with an alert. A step-by-step guide.

Peter Benci's avatar
Peter Benci
Oct 27, 2025
∙ Paid

Trailing stop order

A trailing stop order is a special order type that trails the price. Traditionally, it can trail by a static offset or by percentage. But what if you need to trail to an indicator, like VWAP, that changes with the price action? I have been covering this topic in the past with some proof of concept posts, and there are multiple ways to achieve it.

DAS Trader Advanced hotkeys part 11

DAS Trader Advanced hotkeys part 11

Peter Benci
·
July 29, 2024
Read full story
DAS Trader advanced hotkeys part 15

DAS Trader advanced hotkeys part 15

Peter Benci
·
August 23, 2024
Read full story
Photo by Matthieu Rochette on Unsplash

This is a pro support plan article with a step-by-step process to achieve trailing to any indicator/study with an alert. It can be a moving average, VWAP or PSAR or any indicator that is on the chart to be crossed by the price action.

It works both extended hours (pre-market and post-market) as well as normal trading hours.

Not only that, but it indicates if the trailing is enabled or disabled by the yellow/green color of the button.

I tried to make it as few steps as possible and optimized the code as much as possible. You can make it work with little effort by following the 8-step procedure below. Even less if you have been into advanced hotkeys for a while.

Limits

You need to keep the symbol in focus, otherwise the script will not update the trailing stop with the study latest value.

You need to keep your DAS and PC running, so make sure you have sleeping of PC disabled and that your DAS and PC is stable enough and that you are not getting any popping messages on your DAS from other scripts

You need to keep the account in your montage unchanged once you enable it, otherwise the script will not be able to read the position size and thus will not work properly.

For simplicity, it deletes all the lines on the current chart. A targeted trailing alert line creation is possible but requires some extra coding. If you need to keep other lines drawn on the same chart, you might need to draw and delete the line by a line drawing function.

Functional tests

I am adding the tests here so that the free subscribers can see the functionality and how it operates before deciding for a pro support plan paid subscription.

To test, open the Alert & Trigger window

Open a position in any direction and hit the newly created Trailing button.

Expected outcome
  • the trigger button changes color to green

  • a pink line is drawn at the trailing stop price

  • a new alert is created

As the study value changes, the line on the chart changes and also the Alert value changes

When you double-click the alert,

it has to contain these values

When you click the Trailing button again

Expected outcome
  • it changes color to yellow

  • the alert is removed from the Alert & Trigger window

When the price crosses your trailing stop

  • the position is exited

  • the alert object is deleted

  • the button color remains green
    this is a detail I intentionally kept there so that it shows that there has been a triggered trailing stop existing. Otherwise, we could wonder why the position is not there anymore, as there are no other traces of the trailing stop. If changing the color of the button back to yellow is needed, it can be called in the alert script same as the other commands when exiting the position, or in the exit hotkey itself.

Step-by-Step procedure

1. enable DAS Advanced hotkeys

In DAS configuration management, enable the Advanced hotkeys

2. Named montage window - MONTAGE1

Name your montage window - right-click the header of the montage window and put the name MONTAGE1 there.

3. Named chart window - MY1MIN

do the same for the chart window where you want your indicators/studies to be trailed.

4. Name the studies - MYPSAR, MYEMA11, MYVWAP etc.

Right-click to the chart and choose study config

Add and name the studies you want to trail on.

5. Create a trigger button

This button will enable/disable the trailing

Enable the buttons area on your chart window as described here

DAS Trader Pro Feature highlight

DAS Trader Pro Feature highlight

Peter Benci
·
October 24, 2024
Read full story

and add a new button named b_trailingalert like this

with this code

$TRAILTOSTUDYNAME="MYEMA11";
if ($TRAILINGALERTENABLED==0)
{
$TRAILINGALERTENABLED=1;
$my1minchart.GetCustButObj("b_trailingalert").bkcolor="128,255,128";
$TRAILINGSTOP=0;
}
else
{
$TRAILINGALERTENABLED=0;
$my1minchart.GetCustButObj("b_trailingalert").bkcolor="255,255,128";
$montage.exechotkey("ALRTDELTRAIL");
}

Please, change the first line above to the name of the trailing indicator name of your choice from step 4.

6. Desktop load script

go to Setup→Hotkey/Script→Scripts

And add the following code to the Desktop Load Script

$MONTAGE=getwindowobj("MONTAGE1");
$MY1MINCHART=getwindowobj("MY1MIN");

hit OK, save the desktop and restart DAS Trader Pro

7. Create hotkeys

You will need to create 2 hotkeys.

  • ALRTDELTRAIL

  • TRAILING ALERT

  • EXIT

Name the hotkeys exactly as state with the exact code as below unless instructed to change

ALRTDELTRAIL
$loop=10;
while ($loop>=0)
{
$TODELALERT=GetAlertObj("Trailingstop "+SYMB);
if (IsObj($TODELALERT))
{
$TODELALERT.delete();
}
$loop=$loop-1;
}
$MY1MINCHART.RemoveALLLines;
TRAILING ALERT

This post is for subscribers in the Pro Support Plan plan

Already in the Pro Support Plan plan? Sign in
© 2025 Peter Benci
Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture