Stock Trader May 10, 2021 (more abilities)

Here you can talk about anything related to BBC BASIC, not covered in another category
mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

Stock Trader May 10, 2021 (more abilities)

Post by mikeg »

This version uses .3% to 1% of CPU
There is a lot of delay to reduce CPU time, so you will need to hold your mouse over controls for a bit to get them to sense your intentions.

( I use this program every day, all day. Feel free to try it out. **** The Author of this program does NOT promise this program will help you become a better trader, nor does the author offer any guarantee that this program will help you in any way. Use at your own risk)

NEW -* Top black section is for changing BOUGHT share amount. Use left mouse button on box near arrow in that zone and a text box will show and you can change your share amount (press ENTER) after input the new amount (useful when splitting shares) *Hold mouse over box
How the 3 lower zones work:
-----> Top is normally the sell point. Adjust that and determine an approximate sell point. (Also adjust also for sell point for DOUBLE DOWN)
-----> Center is for BOUGHT share value and amount of money invested after bank fees (adjust your bank fees in program bellow)
*************************************************************************************************************************************************************************
-----> ((Bottom)) is for predicting a lower BUY shares with existing money (TOP of that box) if say you are predicting a possible lower buy
* the information bellow that is DOUBLE DOWN shares
*how that works: So you adjust your sell price say to a lower point, say your in a bad spot and then you adjust the ((bottom)) zone with arrows till you see a lower stock price that can give you some share recovery.
>>>>> The DOUBLE DOWN price and share info is determined after your bank fees are determined (so in this case sold -$10 and bought -$10 cost off your money)

Code: Select all

          REM Stock trader share calculator 3 ranges (MAY 10,2021)
      REM ************* BEGINNING OF USER AREA (modify for your stock) ******************Still required even with manual input section
      LET low=2.30: REM replace this number with the lowest your stock is likely to go
      LET high=2.45: REM replace this number with the highest your stock is likely to go
      LET bought=2.32: REM this will be your current stock purchase (static)
      LET money=0:REM  you can put a default value here but you can just edit within the active app
      PROCgraphics(280,605)
      PROCsbox(5,5,555,1000,"7")
      REM USER INPUT for money and stock price to buy at
      PROCpr(5,400,"money $","7"):r$=FNinput(150,400,20):money=VAL(r$):PROCpr(145,400,r$,"7")
      PROCpr(5,350,"Stock $","7"):r$=FNinput(150,350,20):bought=VAL(r$)
      CLG
      high=bought
      low=bought
      name$="WHATEVER": REM replace this with your stock name
      LET bf=10: REM  <<<<< Your Banking fee per transaction   ***
      REM ************************************ END OF USER INFO AREA ********************
      money2=0
      nde%=0
      bres=0:REM bought shares value
      lres=0:REM low share prediction
      sbou=0:REM variable for high bought cash display
      dif=0:diff$=""
      ldif=0:bldif=0:REM ldif amount before bank fees if you sold at current price. bldif after bank fees
      wutever=0:REM dummy variable
      round%=0
      mx=0:my=0:mb=0
      money=money-bf

      REM You must accept ALL financial risks from using this program before using it
      REM The Author of this program offers no promise of profit or functionality
      *REFRESH OFF

      REM live adjustable low (shares needed to buy at this level)
      PROCsbox(10,10,500,300,"6")
      PROCsbox(10,305,500,600,"6")
      PROCsbox(10,605,500,900,"6")
      PROCsbox(10,905,500,1000,"6")
      PROCsbox(505,10,560,900,"0")
      PROCsbox(505,10,560,600,"0")
      PROCsbox(505,10,560,300,"0")
      PROCsbox(10,1005,500,1200,"8")
      PROCcolor("f","15")
      MOVE 10,1080:PRINT"ADJUST BOUGHT SHARE AMOUNT ":LINE 430,1080,460,1050:LINE 460,1050,460,1070
      LINE 460,1050,440,1050
      GCOL 1:MOVE 20,790:PRINT"*** CHANGE ***"
      MOVE 20,880:PRINT"SELL POINT"
      GCOL 0
      MOVE 10,940:PRINT " Stock Trading Tool "
      GCOL 15:MOVE 20,970:PRINT name$
      MOVE 20,350:PRINT "(1/2 shares)"
      MOVE 20,450:PRINT "PLAY MONEY $ "
      GCOL 1:MOVE 20,580:PRINT "BOUGHT POINT"
      MOVE 20,280:PRINT" LOW BUY and DOUBLE DOWN"
      REPEAT
        REM Share adjustment zone
        *REFRESH ON
        poneg$=FNabutton(450,1010,30,"15","click")
        IF poneg$="click" THEN  money=VAL(FNinput(10,1030,20))*bought
        *REFRESH OFF
        REM Share adjustment zone ends
        GCOL 6:MOVE 250,450:PRINT STR$(money)
        v=0
        LET v= FNau(530,210)
        lres= FNlsharecalc(20,200,low,money)
        wutever=FNsblsharecalc(10,160,low,bldif)
        IF v=1 THEN
          MOVE20,230:GCOL 6:PRINT STR$(low)
          low=low+.01
          WAIT 7
        ENDIF
        v=0
        LET v= FNad(530,90)
        IF v=1 THEN
          MOVE20,230:GCOL 6:PRINT STR$(low)
          low=low-.01
          WAIT 7
        ENDIF
        GCOL 0
        MOVE 20,230:PRINT STR$(low)
        REM live adjustments bought location
        v=0
        LET v= FNau(530,495)
        bres= FNsharecalc(20,520,bought,money)
        IF v=1 THEN
          MOVE20,550:GCOL 6:PRINT STR$(bought):nde%=money/bought/2:MOVE 250,350:PRINT STR$(nde%)
          bought=bought+.01
          WAIT 5
        ENDIF
        v=0
        LET v= FNad(530,390)
        IF v=1 THEN
          MOVE20,550:GCOL 6:PRINT STR$(bought):nde%=money/bought/2:MOVE 250,350:PRINT STR$(nde%)
          bought=bought-.01
          WAIT 7
        ENDIF
        GCOL 0
        MOVE 20,550:PRINT STR$(bought)
        GCOL 6:MOVE 250,450:PRINT STR$(money)
        MOVE 250,350:GCOL 15:nde%=money/bought/2:PRINT STR$(nde%): GCOL 0:MOVE 250,450:PRINT STR$(money):*REFRESH
        WAIT 5
        REM live adjustable high location
        MOVE 20,820:GCOL 6:PRINT "$ "+STR$(sbou)
        MOVE 250,350:GCOL 6:PRINT STR$(money/bought/2)
        GCOL 6:MOVE 250,450:PRINT STR$(money)
        nnm=0
        REM:nnm=FNnewcash: IF nnm>0 THEN money= nnm:bres=FNsharecalc(20,520,bought,money)
        sbou=money/bought
        sbou=sbou*high
        v=0
  
        LET v= FNau(530,800)
        IF v=1 THEN
          MOVE20,850:GCOL 6:PRINT STR$(high)
          high=high+.01
          WAIT 5
        ENDIF
        v=0
        LET v= FNad(530,690)
        IF v=1 THEN
          MOVE20,850:GCOL 6:PRINT STR$(high)
          high=high-.01
          WAIT 5
        ENDIF
        MOVE 20,820:GCOL 0:PRINT "$ "+STR$(sbou)
        GCOL 0
        MOVE 20,850:PRINT STR$(high)
        wutever=FNsblsharecalc(5,160,low,bldif)
        GCOL 6:MOVE 20,760:PRINT "$ "+diff$
        IF sbou>money THEN dif=sbou-money:diff$=STR$(dif):ldif=money+dif:bldif=ldif-20
        IF sbou<money THEN dif=money-sbou:diff$="-"+STR$(dif):ldif=money-dif:bldif=ldif-20
        GCOL 0
        MOVE 20,760:PRINT "$ "+diff$
        WAIT 5
        PROCsleep(505,34,550,870)
        REM PROCtick(50,50)
  
      UNTIL FALSE
      *REFRESH ON
      END
      REM FNabutton added October 22 2017
      REM This is being modified for positive and negative controls with com$ being the response
      REM Modified on March 21, 2021
      DEFFNabutton(x,y,size%,c$,com$)
      MOUSE mx,my,mb
      LOCAL ret$
      PROCcolor("f","5")
      PROCrect(x,y,x+size%,y+size%)
      IF com$="fill" THEN
        PROCpaint(x+5,y+5,c$)
      ENDIF
      IF mx>x AND mx<x+size% AND my>y AND my<y+size% THEN
        PROCcolor("f","15"):PROCrect(x,y,x+size%,y+size%)
        IF mb=4 THEN ret$=com$
      ENDIF
      =ret$
      DEFPROCrect(x%,y%,w%,h%)
      LOCAL sx%,sy%
      sx%=x%:sy%=y%
      IF x%>w% THEN x%=w%:w%=sx%
      IF y%>h% THEN y%=h%:h%=sy%
      LINE x%,y%,w%,y%
      LINE w%,y%,w%,h%
      LINE w%,h%,x%,h%
      LINE x%,h%,x%,y%
      ENDPROC
      DEFFNnumstr(num)
      LOCAL cov$,l%
      cov$=STR$(num)
      l%=LEN(cov$)
      IF l%=1 THEN ret$="00"+cov$
      IF l%=2 THEN ret$="0"+cov$
      IF l%=3 THEN ret$=cov$
      =ret$
      DEFPROCpaint(x%,y%,co$)
      PROCcolor("b",FNrgb(x%,y%)):PROCcolor("f",co$)
      FILL x%,y%
      ENDPROC
      REM experimental
      DEFFNrgb(x%,y%)
      LOCAL rgb%, r&, g&, b&
      rgb%=TINT(x%,y%)
      r&=rgb%    :REM Use byte variable as mask.
      g&=rgb% >>8
      b&=rgb% >>16
      =FNnumstr(r&)+","+FNnumstr(g&)+","+FNnumstr(b&)
      REM EFFICIENCY COUNTER program cycles ( faster numbers= inefficient )
      REM x,y is location of the counter
      REM USE- if you are counting program cycles in an area you want to keep low activity (mouse areas)
      DEFPROCtick(x,y)
      PRIVATE t%
      t%+=1
      MOVE x,y:GCOL 15:PRINT STR$(t%):*REFRESH
      GCOL 128+0:WAIT 5
      GCOL 6:MOVE x,y:PRINT STR$(t%)
      ENDPROC
      REM for active area. If mouse is outside this area SLEEP (bx%,by% lower left tx%,ty% upper right corner)
      DEFPROCsleep(bx%,by%,tx%,ty%)
      LOCAL mx%,my%,mb%,pass%
      REPEAT
        MOUSE mx%,my%,mb%
        IF mx%>bx% AND mx%<tx% AND my%>by% AND my%<ty% THEN pass%=1 ELSE WAIT 70:pass%=1
      UNTIL pass%=1
      ENDPROC


      DEF FNnewcash
      LOCAL x,y,b,p,money2
      MOUSE x,y,b
      MOVE 20,400:GCOL 12: PRINT"CHANGE PLAY MONEY"
      IF x>20 AND y>370 AND x<300 AND  y<410 THEN
        MOVE 20,400:GCOL 15:PRINT"CHANGE PLAY MONEY"
        IF b=4 THEN money2=VAL(FNinput(20,400,25))-10
      ENDIF
      =money2
      REM remember this allows input message to be completed before it cycles.
      REM this command takes control until message is entered.
      REM I am working on a more flexible version that can be left and revisited like in windows
      REM so sorta like live multi processes
      REM H,V,TEXTLIMIT (simpler?)
      DEF FNinput(bx,by,textlimit)
      LOCAL fill,MESSAGE$,bkgndcol%
      bkgndcol%=7:REM background color
      initialx%=0:sl%=0:key$="":MESSAGE$="":MES$=""
      initialx%=textlimit*16.2
      FOR fill=1 TO 58
        GCOL  bkgndcol%:LINE bx-4,by+20-fill,bx+initialx%,by+20-fill
      NEXT fill
      GCOL 0:LINE bx+3,by+20,bx+initialx%,by+20:LINE bx+3,by+20-fill,bx+initialx%,by+20-fill
      REPEAT
        REPEAT
          key$ =INKEY$(1)
          GCOL 0
          MOVE bx,by:PRINT MESSAGE$;"_" :* REFRESH
          sl%=LEN(MESSAGE$)
        UNTIL key$ <>""
        sl%=LEN(MESSAGE$)
        IF INKEY(-48) sl%=LEN(MESSAGE$)-1:key$=""
        REPEAT UNTIL INKEY(0)=-1
        IF sl%<LEN(MESSAGE$) THEN
          GCOL bkgndcol%
          MOVE bx,by
          PRINT MESSAGE$;"_"
        ENDIF
        MES$=MID$(MESSAGE$,0,sl%)
        MESSAGE$=MES$
        GCOLbkgndcol%:MOVE bx,by:PRINT MESSAGE$;"_"
        IF LEN(key$) = 1 THEN
          IF LEN(MESSAGE$)<textlimit THEN GCOL bkgndcol%:MOVE bx,by:PRINT MESSAGE$;"_": MESSAGE$=MESSAGE$+key$:* REFRESH OFF
          REM (jump)
        ENDIF
      UNTIL INKEY(-74)
      =MESSAGE$
      REM low buy shares predict
      DEFFNlsharecalc(x,y,p,cash)
      PRIVATE oldres%
      LOCAL result%
      MOVE x,y
      result%=cash/p
      GCOL 6
      round%=bldif
      PROCpr(x,y,STR$(result%)+" shares $"+STR$(money)+"cost","6")
      =result%
      REM low buy shares predict
      DEFFNsblsharecalc(x,y,p,cash)
      PRIVATE oldres%
      LOCAL result%
      MOVE x,y
      result%=cash/p
      round%=bldif
      PROCpr(x,y,STR$(result%)+" Shares $"+STR$(round%)+" DD","6")
      =result%
      REM bought
      DEFFNsharecalc(x,y,p,cash)
      PRIVATE oldres%
      LOCAL result%
      MOVE x,y
      result%=cash/p
      GCOL 6
      PRINT STR$(oldres%)+" shares"
      GCOL 0
      MOVE x,y
      PRINT STR$(result%)+" shares"
      oldres%=result%
      =result%
      REM arrowup function
      DEF FNau(x,y)
      LOCAL c
      MOUSE mx,my,mb
      IF mx>x-20 AND mx<x+10 AND my>y AND my<y+50 THEN c=15 ELSE c=7
      PROCarrowup(x,y,c)
      IF c=15 AND mb=4 THEN =1
      =0
      DEF FNad(x,y)
      LOCAL c
      MOUSE mx,my,mb
      IF mx>x-20 AND mx<x+10 AND my>y-30 AND my<y+15 THEN c=15 ELSE c=7
      PROCarrowdown(x,y,c)
      IF c=15 AND mb=4 THEN =1
      =0
      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
      DEFPROCarrowup(x,y,c)
      LOCAL ax,aw
      GCOL c
      FOR ax=1 TO 20
        PROCLR(x,y+ax,10)
      NEXT ax
      ax=0:aw=20
      FOR ax=1 TO 20
        PROCLR(x,y+20+ax,aw)
        aw=aw-1
      NEXT ax
      ENDPROC
      DEFPROCarrowdown(x,y,c)
      LOCAL ax,aw
      GCOL c
      FOR ax=1 TO 20
        PROCLR(x,y-ax,10)
      NEXT ax
      ax=0:aw=20
      FOR ax=1 TO 20
        PROCLR(x,y-20-ax,aw)
        aw=aw-1
      NEXT ax
      ENDPROC
      REM Left and Right from center x,y, and width w
      DEFPROCLR(x,y,w)
      LINE x-w,y,x+w,y
      ENDPROC
      REM  "INTERFACE" -library - for graphics text input and other tools
      REM X,Y,message,r,g,b
      DEF PROCpr(X,Y,msg$,c$)
      PRIVATE trackx,tracky,trackmsg$,trackc$
      LOCAL initialx%,fi%,reduction%,tx,ty
      IF trackx=X AND tracky=Y AND trackmsg$<>msg$ THEN PROCprsub(trackx,tracky,trackmsg$,"000,000,000")
      IF trackx<>X OR tracky<>Y OR trackmsg$<>msg$ OR trackc$<>c$ THEN
        initialx%=LEN(msg$)
        PROCcolor("f",c$)
        GCOL 0
        LET tx= X+initialx%+25
        LET ty= Y:reduction%=0
        reduction%=initialx%/2
        reduction%=reduction%*6
        IF initialx%<20 THEN reduction%=reduction%/2
        initialx%=initialx%*22-reduction%
        FOR fi%=12 TO 48
          LINE X-3,Y+20-fi%,X+initialx%+8,Y+20-fi%
        NEXT
        COLOUR 0,0,0,0
        GCOL 0
        MOVE tx,ty
        PRINT msg$
        MOVE 0,0
      ENDIF
      trackx=X:tracky=Y:trackmsg$=msg$:trackc$=c$
      ENDPROC
      REM used by PROCpr to enhance clean up from text overlays
      DEFPROCprsub(X,Y,msg$,c$)
      LOCAL initialx%,fi%,reduction%,tx,ty
      initialx%=LEN(msg$)
      PROCcolor("f",c$)
      GCOL 0
      LET tx= X+initialx%+25
      LET ty= Y:reduction%=0
      reduction%=initialx%/2
      reduction%=reduction%*6
      IF initialx%<20 THEN reduction%=reduction%/2
      initialx%=initialx%*22-reduction%
      FOR fi%=12 TO 48
        LINE X-3,Y+20-fi%,X+initialx%+8,Y+20-fi%
      NEXT
      COLOUR 0,0,0,0
      GCOL 0
      MOVE tx,ty
      PRINT msg$
      MOVE 0,0
      ENDPROC
      REM restore default color palettes
      DEFPROCresetrgb
      COLOUR 0,0,0,0 :COLOUR 1,200,0,0 :COLOUR 2,000,200,000
      COLOUR 3,200,200,000:COLOUR 4,000,000,200:COLOUR 5,200,000,200
      COLOUR 6,000,200,200:COLOUR 7,200,200,200:COLOUR 8,056,056,056
      COLOUR 9,248,056,056:COLOUR 10,056,248,056:COLOUR 11,248,248,056
      COLOUR 12,056,056,248:COLOUR 13,248,056,248:COLOUR 14,056,248,248
      COLOUR 15,248,248,248
      ENDPROC
      DEF PROCcolor(fb$,rgb$)
      PRIVATE assemble$,br%,bg%,bb%
      IF rgb$="0" OR rgb$="black" THEN rgb$="000,000,000"
      IF rgb$="1" OR rgb$="red" THEN rgb$="200,000,000"
      IF rgb$="2" OR rgb$="green" THEN rgb$="000,200,000"
      IF rgb$="3" OR rgb$="yellow" THEN rgb$="200,200,000"
      IF rgb$="4" OR rgb$="blue" THEN rgb$="000,000,200"
      IF rgb$="5" OR rgb$="magenta" THEN rgb$="200,000,200"
      IF rgb$="6" OR rgb$="cyan" THEN rgb$="000,200,200"
      IF rgb$="7" OR rgb$="white" THEN rgb$="200,200,200"
      IF rgb$="8" OR rgb$="grey" THEN rgb$="056,056,056"
      IF rgb$="9" OR rgb$="light red" THEN rgb$="248,056,056"
      IF rgb$="10" OR rgb$="light green" THEN rgb$="056,248,056"
      IF rgb$="11" OR rgb$="light yellow" THEN rgb$="248,248,056"
      IF rgb$="12" OR rgb$="light blue" THEN rgb$="056,056,248"
      IF rgb$="13" OR rgb$="light magenta" THEN rgb$="248,056,248"
      IF rgb$="14" OR rgb$="light cyan" THEN rgb$="056,248,248"
      IF rgb$="15" OR rgb$="light white" THEN rgb$="248,248,248"
      assemble$=rgb$
      br%=VAL(MID$(assemble$,1,3)):bg%=VAL(MID$(assemble$,5,3)):bb%=VAL(MID$(assemble$,9,3))
      IF fb$="f" OR fb$="F" THEN COLOUR 0,br%,bg%,bb% : GCOL 0
      IF fb$="b" OR fb$="B" THEN COLOUR 1,br%,bg%,bb% : GCOL 128+1
      ENDPROC

Focus is on code subject. Feel free to judge the quality of my work.