InvestorsHub Logo
Followers 4
Posts 174
Boards Moderated 1
Alias Born 01/10/2003

Re: neko post# 260

Wednesday, 10/28/2015 1:47:56 AM

Wednesday, October 28, 2015 1:47:56 AM

Post# of 289
Hi Neko,

Below is the modified awk script.

Notice I added a "vcontrol" and "vshares" to track virtual shares. I defaulted to twice the control, but you can change it to any amount ( a multiple of control or an absolute number like "vcontrol = 1300").

It calculates the new virtual shares and then adds or subtracts actual shares based on the change to virtual shares. (it uses oshares and ovshares to store the old value).

So if virtual shares go up by 300, then you would buy 300 shares.



BEGIN {
control = 2000
vcontrol = 2 * control
cash = control
orig = control
}

{
price = $1
value = shares * price + cash
ovshares = vshares
oshares = shares
vshares = int(vcontrol / price)

if (vshares > ovshares)
shares = oshares + (vshares - ovshares)
else
shares = oshares - (ovshares - vshares)

if (shares < 0)
shares = 0

cash = value - shares * price
if (cash < 0)
{
value += -1*cash
orig += -1*cash
cash = 0
}
print price" "shares" "cash" "value" "orig
}

Praveen Puri
Author of "Stock Trading Riches"
The Stock Trading Riches System discussion board: http://investorshub.advfn.com/boards/board.aspx?board_id=19287

Join InvestorsHub

Join the InvestorsHub Community

Register for free to join our community of investors and share your ideas. You will also get access to streaming quotes, interactive charts, trades, portfolio, live options flow and more tools.