Jump to content

We have moved to Discord. Please click here to join us in the Trading Terminal Discord server.



These forums are read-only.

louisrburns

Proportional stop hotkey

Recommended Posts

louisrburns

I asked DAS this question and they didn't have any idea:

I'm trying to setup up a trigger dynamic stop loss. I would like it to buy based on a percentage of my buying power and add a proportional stop loss. 

The following script works for me. It buys with 1/8 of the buying power and places a stop at an $100 fixed risk. 

CXL ALLSYMB; ACCOUNT=XXXXX; ROUTE=MARKET; Share=BP/8; TIF=DAY+; BUY=Send; StopPrice=100/Share; StopPrice=Ask-StopPrice; StopPrice=Round2; TriggerOrder=RT:STOP STOPTYPE:MARKET ACT:SELL STOPPRICE:StopPrice QTY:Pos TIF:DAY+

I would like the stop to scale with my account size. I calculate that an $100 fixed risk is about 0.00025 of the buying power on a $100K account with 4x margin. This is what I tried:

CXL ALLSYMB; ACCOUNT=XXXXX; ROUTE=MARKET; Share=BP/8; TIF=DAY+; BUY=Send; StopPrice=BP*0.00025; StopPrice=StopPrice/Share; StopPrice=Ask-StopPrice; StopPrice=Round2; TriggerOrder=RT:STOP STOPTYPE:MARKET ACT:SELL STOPPRICE:StopPrice QTY:Pos TIF:DAY+

It places the order but does not place the stop and gives me an invalid price error. DAS said you can't use the BP command with the price command. How do I correctly script a triggered proportional stop?

Share this post


Link to post
Share on other sites
Christopher Ganuza

Hello,

I fell into a rabbit hole and figured out how to do the hotkey. Not sure if you still need this but I'll probably use it myself

 

I just modified a copy of my own hotkeys so the script you see here might look pretty different from yours, but I only changed 2 key things from your script.

The initial Share=x, mine says DefShare=x, I changed this to DefShare=BP*0.925 to allow my full buying power to be used. Because the share size of the trade is dependent on the stop level you choose and not just your buying power in this case, your position size won't be calculated here. 

The other thing I changed was the stop price to: BP/2000/Price; so the /Price was added and I just chose to divide the buying power, but multiplying the way you did should do the same thing. In my case the 2000 you can think of as the denominator of your buying power that will be risked. So if you keep it at 2000, then 1R will equal 1/2000th of your buying power, or 1/500th of your account balance. And of course, the R value will automatically grow or shrink with your account.

I hope this helps, pretty cool idea you have I thought of something similar before and now I'm gonna keep this script for myself to use one day. 

 

Disclaimer 1: I am really not an expert on hotkeys I just have some programming experience so please you or anyone reading, test this out extensively in simulator before actually using it. Also, be sure to add CXL ALLSYMB; and ACCOUNT=x if you want those in the hotkey.

Disclaimer 2: A lot of this scaling is done automatically so I see a risk of dangerous mathematical errors if not used carefully. Setting the stop too close to the entry price can calculate a huge position that you might not want. Also, be careful experimenting with appropriate R values. It's less clear what the numbers mean because now R is pretty complicated: it's now expressed as a denominator to your buying power, which is a factor of your account size - pretty complex compared to just typing in a dollar number.

The hotkey to long:

StopPrice=Price-0;DefShare=BP*0.925;Price=Ask-Price+0.00;SShare=BP/2000/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;TogSShare;ROUTE=MARKET;Price= Ask+0.05;TIF=DAY+;BUY=Send;DefShare=200;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice-0.05 ACT:SELL STOPPRICE:StopPrice QTY:Pos TIF:DAY+;

The hotkey to short:

StopPrice=Price+0;DefShare=BP*0.925;Price=Price-Bid+0.00;SShare=BP/2000/Price;Share=DefShare-SShare;DefShare=DefShare+SShare;SShare=Share;Sshare=DefShare-SShare;Share=0.5*SShare;TogSShare;ROUTE=MARKET;Price=Bid-0.05;TIF=DAY+;SELL=Send;DefShare=200;TriggerOrder=RT:STOP STOPTYPE:MARKET PX:StopPrice+0.05 ACT:BUY STOPPRICE:StopPrice QTY:Pos TIF:DAY+;

  • Like 2

Share this post


Link to post
Share on other sites

[[Template core/front/global/mobileNavigation is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]]

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.