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.

NaxFM

Help with advanced hotkeys

Recommended Posts

NaxFM

Hello everyone. I really need help understanding how some of the script function really work, because it seems that every time i click the hotkey, the same exact script does different things. 
In particular I'm having troubles understanding why Round2 seems to not work the way it should. 
I have this simple script, which adds 50 shares to an already existing position and moves the stop loss to the new average price. I would like to round the stop loss price to avoid setting the stop loss to something like 206.36344534... dollars.
However it seems that Round2 does not round the price to the two decimals, but in reality adds to it. It is weird but i can't explain it.
the script is this one:

if(pos >0){
CXL ALLSYMB;

ROUTE=LIMIT;
Price=Ask+0.05; 
Share=50;
TIF=DAY+;
BUY=Send;
$mystop = avgcost;
$mystopround = $mystop;
$mystopround = Round2;
TriggerOrder=RT:STOP STOPTYPE:MARKET PX:$mystop ACT:SELL STOPPRICE:$mystop QTY:Pos TIF:DAY+;
}

When executed, the variables mystop and mystopround have completely different values. Mystop has the correct value but it has way more decimal places than needed, while mystopround is 30 cents above mystop. I do not execute other scripts, so these variables get set by this script only. 
I've read the documentation and I can't find what i'm doing wrong. 
Thank you

stop_loss.png

Share this post


Link to post
Share on other sites
peterB

ROUND2 is old syntax to be used like PRICE=ROUND2 to round the PRICE field on the montage. With advanced hotkeys you should use the round() function eg.
 

$mystop = ROUND(avgcost,2);

for more info go here

Share this post


Link to post
Share on other sites
NaxFM

Thank you Peter! After many tries i understood that Round2 worked only on values which are fields on the montage, but still I didn't know how to round a number outside of the montage. Thank you!
And also thanks for your site. I keep finding lots of useful information there!

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.