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
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
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
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
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
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
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?
yes the traditional stops work only during market hours. if you need premarket working stops there are different solutions with more advanced scripting syntax
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 :)
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.
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
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
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?
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?
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
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
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?
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?
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.
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?
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.
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.
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.
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
yes you can read it with the getposition() function like this
$MYPOS=GetAccountObj($MYACCOUNT).getposition($MYSYMB).share;
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
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
yes just read the ticker from the montage object like $MYSYMB=$MONTAGE.SYMBOL or from the chart window object like $MYSYMB=$MY1MINWINDOW.SYMB
Is there a way to use percent of account for risk variable?
https://open.substack.com/pub/traderpeter/p/das-advanced-hotkeys-part-4?r=1wujo4&utm_medium=ios
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
that would mean a syntax error in the order after the partial or POS being 0
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
the replay mode is a bad joke for scripting
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.
What can I do to adapt these to work with Schwab's OCO's/
you need to edit the route names for your entries
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
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
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?
yes the traditional stops work only during market hours. if you need premarket working stops there are different solutions with more advanced scripting syntax
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 :)
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.
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
Is there a way to modify the fixed risk with oco target scripts to work with Das/Schwab?
anything specific? you probably need to change just the route
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
hi Jason, which script are we talking about?
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
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
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;
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.
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+;
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
use 5.8.0.6 version
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?
hi Chris, these are limit orders entry hotkeys. What do you need to solve?
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
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
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?
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?
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
I tested it on replay, I will try it on real-time tomorrow. Thank you very much
These are great!
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
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+;
Forgot to mention that I am using Replay mode.
do not expect replay mode to work with advanced scripting as the data often does not exist
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?
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.
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.
you just place a static number at the shares part
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.
how is it not working? has the order been placed or not?
Yes, order has been placed. I am using a simulator account. Do you want me to share a screenshot with you?
that would certainly help
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+
Hi Peter, For your entry hot keys, what is the reason or purpose for putting in the line SSHARE=$amount?
that was an old school habit to toggle show share. it is not necessary and you can omit that completely