100 Comments
User's avatar
Nax's avatar

Hello Peter, I have a question.

Is there a way to know in a script if you are currently in a long or short position? I've checked the documentation but I can't find anything.

The Pos variable is always positive, so i can't use that.

I need this info because I want to implement checks in the hotkeys.

It already happened to me that while I am in two different trades with two different montages opened, one long and one short, I click the wrong buy or sell key.

So I'd like to add a check: if the script is dedicated to a short, then it must run only when i'm in a short position, and vice versa for a long.

To do this I just want to add something like if (short) and if (long) at the start of the script.

The problem is that I don't know how to read from the script if i am in a long or short position

Expand full comment
Peter Benci's avatar

yes you can read it with the getposition() function like this

$MYPOS=GetAccountObj($MYACCOUNT).getposition($MYSYMB).share;

Expand full comment
Nax's avatar

Thank you really for your quick answers. Where do you find this information? I tried to search the getposition on the documentation and can't find anything.

Also, another thing. I assume that $MYSYMB is the ticker. Is there a way to get this information automatically? I just want to select the ticker already selected in the montage. Possibly without having to name the montage window, because the same script needs to work on two different montages.

I'd usually try to do it alone, but detailed info on Das scripts is almost non existent, even the official guide is hardly useful at all. I'm really glad to have found this website

Expand full comment
Peter Benci's avatar

and regarding finding the info it is hard work of trial and error and communication with das support that is failing to provide usable documentation for years

Expand full comment
Peter Benci's avatar

yes just read the ticker from the montage object like $MYSYMB=$MONTAGE.SYMBOL or from the chart window object like $MYSYMB=$MY1MINWINDOW.SYMB

Expand full comment
Korey's avatar

Is there a way to use percent of account for risk variable?

Expand full comment
Nax's avatar
Jul 16Edited

Hello Peter. I have a problem with the script to take partials and move the stop loss to BE. The partial gets taken correctly, but for the stop loss the montage window tells me " Error: invalid shares". I really can't get it to work, and it's the same both live and in replay mode. Can you help me. Thanks. I don't know what i'm doing wrong, the montage is already in stop order style

Expand full comment
Peter Benci's avatar

that would mean a syntax error in the order after the partial or POS being 0

Expand full comment
Nax's avatar

Hello Peter, thank you for your answer. The script was fine and there was no error. I found that these scripts that work well live, fail in replay mode.

For example in replay mode, if I have 100 shares and sell 10% while placing a new stop loss at break even, the stop loss is set for 100 shares instead of 90. Trading live instead it set the stop loss to 90.

It seems that in replay mode it does not update some variables like the position size inside the same script

Expand full comment
Peter Benci's avatar

the replay mode is a bad joke for scripting

Expand full comment
Nax's avatar

Yeah. Unfortunately I didn't know that and I thought that every single script that I found online was wrong, as I was testing them in replay mode.

Expand full comment
Korey's avatar

What can I do to adapt these to work with Schwab's OCO's/

Expand full comment
Peter Benci's avatar

you need to edit the route names for your entries

Expand full comment
Jurg Daku's avatar

Hey Peter, I tried these keybinds but I can't see the drag stop loss on my chart. I've setup the chart based on part 1 and enabled advanced hotkeys. I use version 5.8.0.6 x64 with Cobra

Expand full comment
Peter Benci's avatar

Helo,

probably this:

right click the chart -> chart area -> config area

check boxes for

-enable placing alert on chart

-show trades

-show orders

- enable order entry and order line movement

- hide order trype/qty

Expand full comment
Jurg Daku's avatar

Thank you so much for replying, I managed to get it to work. It was placing a stop order where I expected and I could actually drag it but it never gets triggered and I guess that's because I'm testing it during extended hours?

Expand full comment
Peter Benci's avatar

yes the traditional stops work only during market hours. if you need premarket working stops there are different solutions with more advanced scripting syntax

Expand full comment
Jurg Daku's avatar

ah right, I think that's one of the ones from your more recent posts. It's a shame das doesn't support this out the box and we have to resort to scripts :)

Expand full comment
Jurg Daku's avatar

Peter have I understood this post part 2 and part 8 correctly in that for part 8 to work I still have to enter my positions via the script on this part 2 first?

Also I get the error that many others get where by there is an error on line 7.

Expand full comment
Peter Benci's avatar

yes you enter the usual way. i do not know about the error until you say exactly what you are doing and what error you get

Expand full comment
Korey's avatar

Is there a way to modify the fixed risk with oco target scripts to work with Das/Schwab?

Expand full comment
Peter Benci's avatar

anything specific? you probably need to change just the route

Expand full comment
Jason's avatar

Hi Peter, thanks for the hot keys. I use the same script to exit partials but I’m trying to figure something out. For example, after a long position has progressed into profit I’d manually move the stop up. The issue I’m having is that when I take partial profits using the script the stop moves back to the initial location (double clicked location on chart). Do you know how the script could be modified to keep the stop from moving? Thanks

Expand full comment
Peter Benci's avatar

hi Jason, which script are we talking about?

Expand full comment
Jason's avatar

50% Partial Exit (updates stop shares)

CXL ALLSYMB;Route=SMRTL;Share=Pos*0.50;Price=Ask-0.01;TIF=DAY+;SELL=Send;ROUTE=STOP;StopType=Market;StopPrice=StopPrice;Share=Pos-share;TIF=DAY+;SELL=SEND

Expand full comment
Peter Benci's avatar

that does not seem to be a script from me... neither it is advanced hotkeys syntax. anyway you need to keep track of your original stop in a variable since the moment you entered the trade (only with advanced hotkeys enabled), or define a new stop by clicking on the chart and execute the hotkey that sets your stopprice to PRICE and position to POS

Expand full comment
Jason's avatar

My apologies, sent the wrong script. I was referring to the script below to close partials.

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;

Expand full comment
Peter Benci's avatar

that script sets the stop to average cost of your position not to original stop so i am confused

i you want the stop to remain where you set it, change the Stopprice=$Mystop; instead of StopPrice=AvgCost;

it expects that you entered with the hotkey i provided for the entry too which sets the variable $mystop to a clicked price on the chart.

Expand full comment
Keith Allen's avatar

The hotkey for a buy stop limit doesn't seem to work any longer. It sets a buy stop for the top limit price, but does not seem to trigger at the actual price you'd like to enter. So if I do a price of $1.00 - it crosses $1.00, but doesn't seem to trigger, so it doesn't do anything til the top of the limit at $1.05.

Using DAS 5.8.0.3 Any ideas to make it work with this version?

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+;

Expand full comment
Peter Benci's avatar

Anyway, if you see the order placed then there is no issue your order just got skipped because of the lack of liquidity at the price you wanted

Expand full comment
Peter Benci's avatar

use 5.8.0.6 version

Expand full comment
Chris M's avatar

these are great, thank you. ive been trying to come up with a fixed risk hot key long/short but instead of using market to enter the order, been trying to do something like split the spread with a limit order. any idea?

Expand full comment
Peter Benci's avatar

hi Chris, these are limit orders entry hotkeys. What do you need to solve?

Expand full comment
Chris M's avatar

sorry, should've been a little more clear. instead of buying the ask with a limit order im wanting to fill closer to the bid. i guess i could do something like this?

CXL ALLSYMB;

$buyprice=Bid+0.01; // Adjust to buy at the bid price plus 0.01

$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+

Another one I've been struggling with is the same kind of order (fill slightly above bid) but use a stop limit order to exit - mostly for premarket small cap crazy stocks

but when I try this script

CXL ALLSYMB;

$buyprice=Bid+0.01; // Adjust to buy at the bid price plus 0.01

$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:LIMIT PX:$mystop ACT:SELL STOPPRICE:$mystop LIMITPRICE:($mystop-0.20) QTY:Pos TIF:DAY+

i get "invalid shares" as the error

Expand full comment
Peter Benci's avatar

you probably have not enabled advanced hotkeys in das trader pro settings or you are using version 5.8.0.5 which has a bug

Expand full comment
Albert's avatar

I am indeed running version '5.8.0.5 x64' which I can't change because it's part of a training program, so I understand your hotkeys unfortunately don't work with this version?

Expand full comment
Dan Steel's avatar

Peter, I use the short with the oco 3r script. However, when I double-click and hit the hotkey, I don't see the short order entered, only the limit order. Do you know how to fix this?

Expand full comment
Peter Benci's avatar

hi Dan,

it will be placed only after your limit entry hotkey is fully filled as it uses the TRIGGER ORDER command which has this limit

Expand full comment
Dan Steel's avatar

I tested it on replay, I will try it on real-time tomorrow. Thank you very much

Expand full comment
Korey's avatar

These are great!

Expand full comment
shridhar kumar's avatar

Good day Peter,

When i use your Static risk of $20 with automatic stop loss order attached it pops up a message stating

"trigger order only work in montage window."

What should i do for this error?

Thanks

Expand full comment
Komal's avatar

I get the following error.

Msg Box Script : Invalid operator

and this error in Montage Error:Invalid Shares!

When I run the below script using hot Button ($20 risk with 3x target ), I first double click on chart where I want the stop price and then click this Hot Button then I get the above error.

I have latest version of DAS 5.8.0.4 9 Nov 29th, 2024.

Please help.

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+;

Expand full comment
Komal's avatar

Forgot to mention that I am using Replay mode.

Expand full comment
Peter Benci's avatar

do not expect replay mode to work with advanced scripting as the data often does not exist

Expand full comment
EJ's avatar

Hi Peter, is there a way to store and change a variable's value in just one place, so that you can include that variable in multiple hotkeys, but only have to change the value in the one place, instead of having to change the value in each individual hotkey?

Expand full comment
Peter Benci's avatar

hi EJ, sure there is a way. You can have a prompt for that if you need to change it often or use it as a switch between two values as i do in one of the later posts with the account switcher. Also you csn have it changed based on any calculated or measured indicator value.

Expand full comment
Wahid's avatar

love your work and just started following your blog for the scripts. Quick question: For the 'Static risk of $20 with automatic stop loss order,' how do I set up a fixed number of shares (like 100 shares) instead of having it automatically calculate the number of shares. Thanks.

Expand full comment
Peter Benci's avatar

you just place a static number at the shares part

Expand full comment
Wahid's avatar

Thanks for your reply, Peter. I did as you mentioned but the stop loss is not working. It is simply not stopping when the loss is over $20. Appreciate your suggestion.

Expand full comment
Peter Benci's avatar

how is it not working? has the order been placed or not?

Expand full comment
Wahid's avatar

Yes, order has been placed. I am using a simulator account. Do you want me to share a screenshot with you?

Expand full comment
Peter Benci's avatar

that would certainly help

Expand full comment
Wahid's avatar

https://postimg.cc/DW3Ppvvv

here is the script:

---------

CXL ALLSYMB;

$buyprice=Ask;

$risk=20;

$mystop=price;

$pricetostop=$buyprice-$mystop;

$amount=$risk/$pricetostop;

SShare=100;

Share=100;

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+

Expand full comment
Bill's avatar

Hi Peter, For your entry hot keys, what is the reason or purpose for putting in the line SSHARE=$amount?

Expand full comment
Peter Benci's avatar

that was an old school habit to toggle show share. it is not necessary and you can omit that completely

Expand full comment