## Stock Market Calculator with projected sells

Here you can link to screenshots and demos etc. of programs made using BBC BASIC
mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

### Stock Market Calculator with projected sells

This small side tool I crafted for myself to make it easier to make small trades (Because tight trades are tough with small amounts of money)

I offer this program for testing.
No holds barred. Be tough on this program.. If you find any problems, feel free to state the flaws. (I used cross reference and received no warnings)

This program is aimed at a device with a keyboard and mouse.(mouse for moving the calculator to a nice spot)
How to use:

* First type the value of the stock you want to buy and press ENTER

* Then type the amount of money you want to invest and press ENTER

*The amount of stocks you can buy will be displayed bellow that AND

3 optional sell prices with projected profits for each one.

After you are done with the current display press ENTER and a new calculator will be ready

Code: Select all

``````
LET bf=10:REM  <<<<< Your Banking fee per transaction   ***
PROCgraphics(155,505)
REM You must accept ALL financial risks from using this program before using it
REM This program is a demo.
REM The Author of this program offers no promise of reliability or usefullness
REPEAT
CLS

PROCsbox(5,10,300,200,"7")

PROCsbox(5,215,300,405,"10")
PROCsbox(5,415,300,605,"3")
PROCsbox(5,620,300,810,"15")
PROCsbox(5,815,300,1000,"15")

MOVE 10,190:GCOL 4: PRINT"STOCK SELL PRICE "
MOVE 10,380:PRINT"STOCK SELL PRICE "
MOVE 10,580:PRINT"STOCK SELL PRICE "
GCOL 0
MOVE 10,980:PRINT"STOCK PRICE "
MOVE 10,910:PRINT"AMOUNT TO SPEND "
amount=0:vlu=0:tt=0:e\$="":round%=0

GCOL 0
GCOL 128+15:REM background color black for text
MOVE 5,950:INPUT " : ",amount

REPEAT
MOVE 5,880: INPUT "\$\$ ",vlu
GCOL 0
REM INPUT " Amount you want to invest : ",value
UNTIL vlu>0
vlu=vlu-10:REM this is the amount your bank charges you for transaction. (adjust for you)
tt=vlu/amount
round%=tt
MOVE 10,760:PRINT "  SHARES "+STR\$(round%)

REPEAT
otheramt+=0.01
profit=round%*otheramt
UNTIL profit>vlu+30 :REM you must make this work out to around \$30 profit
MOVE 10,150:PRINT " "+STR\$(otheramt)
PRINT" PROFIT \$ "+STR\$(profit-vlu-bf)

REPEAT
otheramt+=0.01
profit=round%*otheramt
UNTIL profit>vlu+50 :REM you must make this work out to around \$50 profit
MOVE 10,350:PRINT " "+STR\$(otheramt)
PRINT " PROFIT \$ "+STR\$(profit-vlu-bf)
REPEAT
otheramt+=0.01
profit=round%*otheramt
UNTIL profit>vlu+100 :REM you must make this work out to around \$100 profit
MOVE 10,550
PRINT " "+STR\$(otheramt)
PRINT " PROFIT \$ "+STR\$(profit-vlu-bf)

PRINT
MOVE 0,0
INPUT "@",e\$
PRINT "************************************************************"
CLS
UNTIL FALSE
END
REM lets stick with 16 colors **********************************************************************
DEF PROCsbox(x%,y%,w%,h%,c\$)
LOCAL ry%,sx%,sy%
sx%=x%:sy%=y%
IF x%>w% THEN x%=w%:w%=sx%
IF y%>h% THEN y%=h%:h%=sy%
ry%=y%
GCOL VAL(c\$)
REPEAT
LINE x%,y%,w%,y%
y%=y%+1
UNTIL y%=h%
y%=ry%
IF c\$<>"0" THEN GCOL 0 ELSE GCOL 15
LINE x%+2,y%+2,w%-2,y%+2
LINE w%-2,y%+2,w%-2,h%-4
LINE w%-2,h%-4,x%+2,h%-4
LINE x%+2,h%-4,x%+2,y%+2
ENDPROC
DEF PROCgraphics(x,y)
VDU 23,22,x;y;8,15,16,1
VDU 5
ENDPROC
``````
Focus is on code subject. Feel free to judge the quality of my work.

David Williams

### Re: Stock Market Calculator with projected sells

mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

### Re: Stock Market Calculator with projected sells

Take a look at this:
Yes. I did also have a smaller sell profit that tried to get near \$ 20.oo. I gave the display price a bit of flexibility because its hard to get near
exact tiny profit amounts if say, you are dealing with large amounts of money. The projected profits are factored with banking fees factored in.

IF say, I could get the live RSS feed for stocks like (HNU) betapro natural gas Daily Bull ETF and (HND) betapro natural gas Daily bear,
I could make a calculator that only requires the \$\$\$ amount you want to invest and it could give a LIVE stock price and amounts to buy so I am not
needing to move my eyes away from the calculator.
(stocks can move fast and with tight trades, you may only have so many cycles before it drops or leaves you behind)

My problem with finding a live RSS feed is, when using developer tools to extract I am seeing java in the HTML info. So I am not sure where to look. AND when I google the latest HNU price it is off by A LOT.
I can of course get live prices from my dashboard, and Investing.com for Natural gas futures.
A note that Investing.com is delayed by a lot. Also Horizons ETF home page doesnt give me a live price so it is a tough search.

Its not a big deal. I can just work with my calculator, and its small enough to tuck in the side of the screen. (needing to adjust a buy price takes too much time sometimes.)
Focus is on code subject. Feel free to judge the quality of my work.

RichardRussell

### Re: Stock Market Calculator with projected sells

mikeg wrote:
Sat 07 Dec 2019, 14:47
My problem with finding a live RSS feed is, when using developer tools to extract I am seeing java in the HTML info.
Do you mean HTML or XML here? RSS feeds are XML, and can be decoded using 'xmllib.bbc' supplied with both BB4W and BBCSDL. The example programs 'banner.bbc' and 'ceefax.bbc' both decode RSS feeds that way (coincidentally I am currently extending ceefax.bbc to extract traffic and weather news). If there is Javascript in the XML file you can probably ignore it, from the point of view of extracting the primary data (xmllib may ignore it anyway, depending on how you use it).

The only problem I've had with reading RSS feeds in BBC BASIC is that occasionally they are behind encrypted (https) connections, with no standard http alias, and socklib.bbc will of course not connect to such sites. The workaround I've adopted is to set up a proxy that fetches the XML data from the https URL and then returns it unencrypted, but to do that you need your own website.

ceefax.bbc (the current version shipped with BBCSDL and the new version I am working on) is compatible with both BBC BASIC for Windows and BBC BASIC for SDL 2.0.

mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

### Re: Stock Market Calculator with projected sells

This is what I was looking at:
https://www.investing.com/commodities/natural-gas

Far top right side there is ... click on that and move mouse down to (more tools)
* a developer tools option shows up in the side pop up and that should display what I described

There is no problem with this particular stock, as it is basically the Central guide
for the world. HNU and HND are the Canadian bull and bear stocks that follow it.

If I can find the RSS feeds for these stocks, I can make a live calculator that gives
a updated number of stocks I can buy without constantly needing to verify the latest
ask price for stocks that can be bought.

Also, The HNU and HND (gas bull and bear stocks) and HOU and HOD (oil bull and bear stocks) are delayed on
Investing.com, because they are not local to United States, so the read from the Toronto Stock Exchange
in Canada would be better. ( am researching the different sites)

So the search is still being worked on.

Another option is to somehow extract the live price from my screen dashboard and use a graphics scan to extract the
numbers at the location. (a type of camera snapping timed pictures and BBC Basic viewing the image file fast
every second to extract the numbers and do the updates.)

I prefer just getting the feeds.

UPDATE: I have found a way to take quality screen shots using built in windows 10 tools. So I will now use my Raspberry Pi3 to run a couple relays every second to press the FN and Printscreen buttons and then the pictures will be accessed by BBC Basic to extract the info and then the picture gets deleted after extraction. Of course I will only attempt deletion of images once I ensure that the timing is perfect, because the image has the date and a number is added to the new file. (increments of 1)
Of course this means I need to do some wiring in my wireless keyboard to hook to the relay leads or make a mechanical keystroke robot. (shouldn't be too hard)

Problem - getting rid of the notification after capture.. must be solved
Focus is on code subject. Feel free to judge the quality of my work.

RichardRussell

### Re: Stock Market Calculator with projected sells

mikeg wrote:
Sun 08 Dec 2019, 00:26
So I will now use my Raspberry Pi3 to run a couple relays every second to press the FN and Printscreen buttons
Seriously? You plan to press the keys electrically? Why would you do that rather than using software to 'press' them virtually (in the usual way using keybd_event or SendInput)? I'm pretty sure that PrintScreen can be simulated that way just like any other keyboard input can be. Or you could even grab the screen contents yourself in code; if the documented BBC BASIC methods don't work for you, Google finds plenty more examples in C or C++ that could be translated.

mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

### Re: Stock Market Calculator with projected sells

OH cool ! Now you just saved me tonnes of work. And with the tool David Williams just linked to me for .png display, I believe I have the rest of the tools I need to do it just with one program on one device. Awesome!!
Thanks Richard.
Focus is on code subject. Feel free to judge the quality of my work.