User avatar
Posts: 414
Joined: Tue Jul 12, 2005 12:55 pm
Location: Charlotte, NC
Contact: Send private message

Figuring gain/loss with MLStockInfo

Sun Sep 10, 2006 9:18 pm

I've been playing around with MLStockInfo a bit. One of the things I set out to do is be able to see gain or loss as a percentage for the stocks I own.

I got it working, so I thought I'd post the calculations to save others some time.

Here's how it works:

(For this example, let's say the basis cost for IBM is $50.00 per share, and it's trading at $60.00)

set a variable at startup with the basis cost per share for each stock:

Code: Select all

Then set up a server rule or an MLTimer to run a macro made from these commands:

Code: Select all

Subtracts the basis cost from the current price - (60 - 50 = 10) and puts the result in {{stocktemp1))

Code: Select all

Divides the result of the first equation by the basis cost (10 / 60 = 0.166666) and puts the result in {{stocktemp2}}

Code: Select all

Multiplies the results of the second calculation by 100 to get a percentage and puts it in {{stocktemp3}}

Code: Select all

Truncates the result of the third calculation at 6 characters. (chosen so as to get two characters after the decimal even when dealing with negative :shock: numbers) and puts the result in {{stockIBM_gainloss}}

Here's the whole macro:

Code: Select all


Return to “MLStockInfo”

Who is online

Users browsing this forum: No registered users and 1 guest