Jump to content
Day-Meister

Defined Risk Hotkeys for multiple range orders

Recommended Posts

I have been working today on 2 hotkeys for myself.

The script(s) uses the defined R/R script from previous Kyles hotkeys.

It performs the following:

  • Cancels any previous orders for the symbol
  • Enters the trade, ensuring total shares bought is equally divisible by 4 (rounded down); this prevents having extra shares hanging around after the range trades complete or stop out.
  • Creates a range order at your stop level for 1/4 of your initial shares bought with a profit level of 2R
  • Creates a range order at your stop level for 1/4 of your initial shares bought with a profit level of 3R
  • Creates a range order at your stop level for 1/4 of your initial shares bought with a profit level of 4R
  • Creates a single order at your stop for the remaining 1/4 shares; This allows you to ride the last 1/4 to whatever level you want before exiting

As with Kyles hot key scripts, you double click your chart at the level you want to place your stop then press your button or hot key

The Script for the long entry

CXL ALLSYMB; StopPrice=Price-0.01;DefShare=BP*0.5;Share=DefShare*0.333*Price*0.01;Price=Ask-Price+0.01;SShare=Share/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= Ask+0.05;TIF=DAY+;BUY=Send;DefShare=1000;Price=Ask-StopPrice*2+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;Price=Ask-StopPrice*3+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;Price=Ask-StopPrice*4+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice-0.3 ACT:SELL STOPPRICE:StopPrice QTY:Pos*.25 TIF:DAY+;

and the Short

CXL ALLSYMB; StopPrice=Price+0.01;DefShare=BP*0.5;Share=DefShare*0.333*Price*0.01;Price=Price-Bid+0.01;SShare=Share/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= bid-0.05;TIF=DAY+;SELL=Send;DefShare=1000;Price=StopPrice-Bid*2;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;Price=StopPrice-Bid*3;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;Price=StopPrice-Bid*4;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice+0.3 ACT:BUY STOPPRICE:StopPrice QTY:Pos*.25 TIF:DAY+;

Long $50 Risk

CXL ALLSYMB; StopPrice=Price-0.01;DefShare=BP*0.5;Price=Ask-Price+0.01;SShare=50/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= Ask+0.05;TIF=DAY+;BUY=Send;DefShare=1000;Price=Ask-StopPrice*2+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;Price=Ask-StopPrice*3+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;Price=Ask-StopPrice*4+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice-0.3 ACT:SELL STOPPRICE:StopPrice QTY:Pos*.25 TIF:DAY+;

Short $50 Risk

CXL ALLSYMB; StopPrice=Price+0.01;DefShare=BP*0.5;Price=Price-Bid+0.01;SShare=50/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= bid-0.05;TIF=DAY+;SELL=Send;DefShare=1000;Price=StopPrice-Bid*2;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;Price=StopPrice-Bid*3;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;Price=StopPrice-Bid*4;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice+0.3 ACT:BUY STOPPRICE:StopPrice QTY:Pos*.25 TIF:DAY+;

 

Everything prior to defshare=1000 in each script is completely from the original Risk/Reward Hotkeys except the bit of code that ensures the number of shares is equally divisible by 4.

 

Feel free to give them a try and let me know if there are any issues.

 

2022-02-09_8-00-24.png.fc29d7a6e725ff5965eccf7aac5adbc4.png

Edited by Day-Meister
Adding an image here as suggested by miah.
  • Like 4
  • Thanks 4

Share this post


Link to post
Share on other sites

I will point out that this isn't necessarily new, I just wanted to figure it out for myself and my exact situation (I learn best that way). I know there are references in other posts to similar scripts (maybe even ones that do the exact same). If there is one out there, please don't assume this is plagiarized 🙂

  • Thanks 2

Share this post


Link to post
Share on other sites

This is awesome and exactly what I've been looking for!  I tried setting target limit orders, which has worked ok, but having it all in one hot key is a game changer.  Any idea if it is possible to have the order move the stop to b/e after the first partial is taken?  I'll see if I can script it, but just thought I would ask the professional first.  Thanks again!  

Share this post


Link to post
Share on other sites
On 1/31/2022 at 10:30 AM, TJ said:

This is awesome and exactly what I've been looking for!  I tried setting target limit orders, which has worked ok, but having it all in one hot key is a game changer.  Any idea if it is possible to have the order move the stop to b/e after the first partial is taken?  I'll see if I can script it, but just thought I would ask the professional first.  Thanks again!  

This should be possible, but very clunky. 1 way would be to have a nested trigger (if that is possible) within the 1st partial trigger that cancels all the others and recreates them with the new Stop value.

If you attempted a second script after this one completed, you wouldn't be able to capture what you determined your initial risk was, so your limit orders wouldn't be put in the right spots. Personally, I just drag my stops to manually identified levels (pivots, support/resistance) afterwards as I manage the trade.

6 hours ago, Quy Doan said:

Thank you for the amazing work @Day-Meister

Can I use the scripts to enter a long or short with a fixed dollar risk $50/trade?

This should be easy enough by substituting the calculation in the first part of the script. My heads not in it today, but I will take a look at it and see if I can do, it test it, and post it in the next few days.

 

Share this post


Link to post
Share on other sites

Not sure if the following info would help, but understand version....16, currently in beta can cancel just the STOPS only.

Then would need to figure how to put each back at the AVGCOST.

Jus my 2 cents.

 

Share this post


Link to post
Share on other sites
2 minutes ago, Alastair said:

Not sure if the following info would help, but understand version....16, currently in beta can cancel just the STOPS only.

Then would need to figure how to put each back at the AVGCOST.

Jus my 2 cents.

 

Interesting. I wonder if that will work for stops that were set as part of a range order rather than the whole range.

Edited by Day-Meister

Share this post


Link to post
Share on other sites
8 hours ago, Quy Doan said:

Thank you for the amazing work @Day-Meister

Can I use the scripts to enter a long or short with a fixed dollar risk $50/trade?

OK,

This should give you $50 long risk:

Quote

CXL ALLSYMB; StopPrice=Price-0.01;DefShare=BP*0.5;Price=Ask-Price+0.01;SShare=50/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= Ask+0.05;TIF=DAY+;BUY=Send;DefShare=1000;Price=Ask-StopPrice*2+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;Price=Ask-StopPrice*3+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;Price=Ask-StopPrice*4+Ask;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:StopPrice HighPrice:Price ACT:SELL QTY:POS*.25 TIF:DAY+;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice-0.3 ACT:SELL STOPPRICE:StopPrice QTY:Pos*.25 TIF:DAY+;

and $50 short risk

Quote

CXL ALLSYMB; StopPrice=Price+0.01;DefShare=BP*0.5;Price=Price-Bid+0.01;SShare=50/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= bid-0.05;TIF=DAY+;SELL=Send;DefShare=1000;Price=StopPrice-Bid*2;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;Price=StopPrice-Bid*3;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;Price=StopPrice-Bid*4;Price=Bid-Price;TriggerOrder=RT:STOP STOPTYPE:RANGE LowPrice:Price HighPrice:StopPrice ACT:BUY QTY:POS*.25 TIF:DAY+;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice+0.3 ACT:BUY STOPPRICE:StopPrice QTY:Pos*.25 TIF:DAY+;

 

Obviously test in SIM extensively before counting on it 🙂

Let me know how it goes

  • Like 1

Share this post


Link to post
Share on other sites

That works perfect for both Long and Short. 

Thank you so much for your help.

 

Just curious: what is "DefShare=BP*0.5" mean on the code. Does it mean the execution only take 50% the buying power to get the share size?

2022-02-09_8-00-24.png

Share this post


Link to post
Share on other sites
29 minutes ago, Quy Doan said:

That works perfect for both Long and Short. 

Thank you so much for your help.

 

Just curious: what is "DefShare=BP*0.5" mean on the code. Does it mean the execution only take 50% the buying power to get the share size?

 

Awesome. Yes, the DefShare=BP*0.5 uses half buying power. This seems necessary for trading stocks that may not allow as much leverage as DAS has calculated. (This is necessary for me at least; Feel free to experiment with that value if you want. It may not be necessary with the $ value defined risk vs. the Buying power one, but it is included in Kyle's hotkeys so I assume it is still valid)

Edited by Day-Meister

Share this post


Link to post
Share on other sites
On 2/8/2022 at 10:05 AM, Day-Meister said:

OK,

This should give you $50 long risk:

and $50 short risk

 

Obviously test in SIM extensively before counting on it 🙂

Let me know how it goes

Awesome this works great. @Day-Meister Is there a way to adjust code so there is 1 stop order for the entire position and 4 cover or sell orders for 25% each at 1.5R, 2R, 3R, 4R?

Just want to see if I can get some ECN rebates haha ROUTE would be NSDQL or smart limit.

Thanks a million!

Edited by jokajon00

Share this post


Link to post
Share on other sites
18 hours ago, jokajon00 said:

Awesome this works great. @Day-Meister Is there a way to adjust code so there is 1 stop order for the entire position and 4 cover or sell orders for 25% each at 1.5R, 2R, 3R, 4R?

Just want to see if I can get some ECN rebates haha ROUTE would be NSDQL or smart limit.

Thanks a million!

It sounds simple in theory, and you could adjust the code to create the initial orders that way by making them 4 different limit orders and 1 stop order (rather than the multiple range orders); The problem comes when your limit orders are hit, there is no way to really change the quantity of your stop order automatically. I can't think of a way to overcome that, sorry.

Edited by Day-Meister

Share this post


Link to post
Share on other sites
7 minutes ago, Day-Meister said:

It sounds simple in theory, and you could adjust the code to create the initial orders that way by making them 4 different limit orders and 1 stop order (rather than the multiple range orders); The problem comes when your limit orders are hit, there is no way to really change the quantity of your stop order automatically. I can't think of a way to overcome that, sorry.

@Day-Meister Yeh. I just cant figure out the code for 4 limit orders and 1 stop order to be triggered after entry . I will be at the trade desk so don't need the stop to change automatically. Once a limit order hits I can just load the Stop Order into the montage by double clicking it, then click P to change to current position size and then click RPL to replace and change it. If you could post the code for 4 covers and 1 stop order that'd be awesome.

 

Thanks again.

Share this post


Link to post
Share on other sites
1 hour ago, jokajon00 said:

@Day-Meister Yeh. I just cant figure out the code for 4 limit orders and 1 stop order to be triggered after entry . I will be at the trade desk so don't need the stop to change automatically. Once a limit order hits I can just load the Stop Order into the montage by double clicking it, then click P to change to current position size and then click RPL to replace and change it. If you could post the code for 4 covers and 1 stop order that'd be awesome.

 

Thanks again.

OK, Try this for long:

CXL ALLSYMB; StopPrice=Price-0.01;DefShare=BP*0.5;Share=DefShare*0.333*Price*0.01;Price=Ask-Price+0.01;SShare=Share/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= Ask+0.05;TIF=DAY+;BUY=Send;DefShare=1000;
Price=Ask-StopPrice*1.5 +Ask;TriggerOrder=RT:SMRTL; Price=Round2; PX:Price ACT:SELL QTY:POS*.25 TIF:DAY+;
Price=Ask-StopPrice*2+Ask;TriggerOrder=RT:SMRTL PX:Price ACT:SELL QTY:POS*.25 TIF:DAY+;
Price=Ask-StopPrice*3+Ask;TriggerOrder=RT:SMRTL PX:Price ACT:SELL QTY:POS*.25 TIF:DAY+;
Price=Ask-StopPrice*4+Ask;TriggerOrder=RT:SMRTL PX:Price ACT:SELL QTY:POS*.25 TIF:DAY+;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice-0.3 ACT:SELL STOPPRICE:StopPrice QTY:Pos TIF:DAY+;

and this for short:

CXL ALLSYMB; StopPrice=Price+0.01;DefShare=BP*0.5;Share=DefShare*0.333*Price*0.01;Price=Price-Bid+0.01;SShare=Share/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;Share=Share/4;Share=Share*4;TogSShare;ROUTE=SMRTL;Price= bid-0.05;TIF=DAY+;SELL=Send;DefShare=1000;
Price=StopPrice-Bid*1.5;Price=Bid-Price; Price=Round2;TriggerOrder=RT:SMRTL PX:Price ACT:BUY QTY:POS*.25 TIF:DAY+;
Price=StopPrice-Bid*2;Price=Bid-Price; TriggerOrder=RT:SMRTL PX:Price ACT:BUY QTY:POS*.25 TIF:DAY+;
Price=StopPrice-Bid*3;Price=Bid-Price; TriggerOrder=RT:SMRTL PX:Price ACT:BUY QTY:POS*.25 TIF:DAY+;
Price=StopPrice-Bid*4;Price=Bid-Price; TriggerOrder=RT:SMRTL PX:Price ACT:BUY QTY:POS*.25 TIF:DAY+;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice+0.3 ACT:BUY STOPPRICE:StopPrice QTY:Pos TIF:DAY+;

That is for sizing based on BP

Replace the first line of each with the corresponding code for $fixed risk from above.

In testing, I noticed that sometimes it would only create 3 orders (I suspect it has something to do with calculation of the 1.5R) (EDIT: pretty sure that was the issue; corrected script with ROUND2 to hopefully fix that)

Edited by Day-Meister
Corrected scripts with the round2 function to cover bad math on a 1.5R calculation

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.