Guest User

Untitled

a guest
Dec 22nd, 2021
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. /** @param {NS} ns **/
  2. export async function main(ns) {
  3. //*********PARAMS FOR SCRIPT ************//
  4. var maxSharePer = 0.45 // maximum percent of a symbol's total stock to buy
  5. var stockBuyPer = 0.6 // percent probablity to buy symbol
  6. var stockVolPer = .03 // percent stock will move to buy
  7. var moneyKeep = 1000000000 // min money to keep on hand
  8. var minSharePer = 5 // min shares to buy
  9. var orderMax = 1000000000000 // max money to spend on a single order
  10. var profPer = 0.05 // min profit percentage to sell
  11. var panicPer = 0.15 // percentage loss to panic sell at
  12. //******************************//
  13. while (true) {
  14. ns.disableLog('disableLog');
  15. ns.disableLog('sleep');
  16. ns.disableLog('getServerMoneyAvailable')
  17. var stocks = ns.stock.getSymbols();
  18. for (const stock of stocks) {
  19. var position = ns.stock.getPosition(stock)
  20. var forecast = ns.stock.getForecast(stock);
  21. if (position[0]) {
  22. ns.print('Position: ' + stock + ", " + position[0] + " Profit: " + ns.nFormat(Math.round(ns.stock.getSaleGain(stock, position[0], "Long") - (position[0] * position[1])), '0,0', "Long") + ' % ' + ns.nFormat(ns.stock.getSaleGain(stock, position[0], "Long") / (position[0] * position[1]), "0%"));
  23. sellPositions(stock);
  24. }
  25. buyPositions(stock);
  26.  
  27. }
  28. await ns.sleep(6000);
  29. }
  30. function sellPositions(stock) {
  31. //sell if only 40% chance increase
  32. if (ns.stock.getForecast(stock) < 0.4) {
  33. //sell stock
  34. ns.toast("SOLD STOCK " + stock + " for " + ns.nFormat(Math.round(ns.stock.getSaleGain(stock, position[0], "Long") - (position[0] * position[1])), '0,0') + " profit!");
  35. ns.stock.sell(stock, position[0]);
  36. }
  37. }
  38.  
  39. function buyPositions(stock) {
  40. var maxShares = (ns.stock.getMaxShares(stock) * maxSharePer) - position[0];
  41. var askPrice = ns.stock.getAskPrice(stock);
  42. var forecast = ns.stock.getForecast(stock);
  43. var volPer = ns.stock.getVolatility(stock);
  44. var minBuy = 10000000;
  45. var playerMoney = ns.getServerMoneyAvailable('home');
  46. //if the stock will move positive by stockbuyper or more and it will grow stockvolper or more
  47. if (forecast >= stockBuyPer && volPer <= stockVolPer) {
  48. //check money for one share
  49. if (playerMoney - moneyKeep > ns.stock.getPurchaseCost(stock, minSharePer, "Long")) {
  50. var shares = Math.min((playerMoney - moneyKeep - 100000) / askPrice, orderMax / askPrice);
  51. if (shares * askPrice > minBuy) {
  52. ns.stock.buy(stock, Math.min(shares, maxShares));
  53. }
  54. }
  55. }
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment