Cookie Clicker

Cookie Clicker

CookiStocker 2 | Automatic Stock Trading Mod
z  [developer] 29 Jul, 2023 @ 1:28am
The Trading Algorithm
In this thread, I will discuss the trading algorithm used by CookiStocker. I will start with the algorithm as it is currently implemented for CookiStocker 2.0, and I will gradually refine this post as the algorithm is refined for version 3.0. The algorithm as presented here will be divided into two parts: those parts that have been extensively tested and are not expected to change, and those parts which currently form the CookiStocker 2.0 algorithm but are expected to be substantially revised for the next version. Here they are:

Those parts of the algorithm that have been extensively tested and are not expected to change:
  1. Always buy stocks when the price drops below 2.
  2. Never sell stocks when the price is below 11. These first two rules override all others.
  3. Always buy stocks when the mode changes from 4 [rapidly falling] to 3 [rapidly rising].
  4. Always sell stocks when the mode changes from 3 to 4.
  5. Buy stocks if the trend changes so that the stock price rises four ticks in a row, unless the mode is 1 [slowly rising] or 3 [rapidly rising], in which case the threshold is three ticks in a row.
  6. Sell stocks it the trend changes so that the stock price falls four ticks in a row, unless the mode is 2 [slowly falling] or 4 [rapidly falling], in which case the threshold is three ticks in a row.. In both this case and the previous one, if the stock price does not change from one tick to another, such a tick counts toward the total buy or sell threshold.
  7. The counts used in the buy and sell rules mentioned directly above are always reset during mode changes that take the mode either in or out of a buy or sell mode.

    These parts of the algorithm will be changed, either completely or in part.

  8. Stocks are always bought when the mode changes to 1 [slowly rising] or 3 [rapidly rising] from any of the other four modes.
  9. Stocks are always sold when the mode changes to 2 [slowly falling] or 4 [rapidly falling] from any of the other four modes.
  10. None of the other mode transitions trigger a buy or sell.
This algorithm is what I am currently using in my tests, which are consistently generating an average of over $15 million per day, compared to less that $2 million for the currently released version of CookiStocker. This algorithm can be used manually to generate similar returns. However, using it manually requires almost constant attention to the market.
Last edited by z; 30 Jul, 2023 @ 12:56am
< >
Showing 1-1 of 1 comments
z  [developer] 29 Jul, 2023 @ 1:29am 
I thought that I would give an interim update on the trading algorithm, specifically on the part that deals with mode transitions. Here is what I have so far. The format is simply my own personal format; I will be using an easier-to-read format when I publish the full algorithm when it's done. It contains rules for all 30 mode transitions (6! / 4!); I have found 29 of them in use so far. Can anyone guess which one I haven't found?

Here's a guide to reading the algorithm:
  • The numbers in the first column show the starting mode and the ending mode; they are followed by the actual rules for the transition.
  • "Stay" means neither buy nor sell; i.e., do nothing.
  • "Hold" is true if any of the stock is owned.
    [*}"Not hold" is treated as a single word and is true if none of the stock is owned.
  • The "buy" test is always evaluated before the (options) "sell" test.
  • If the stock fulfills neither the buy nor sell rules of the test, nothing is done.
  • If the word "mode" is associated with an inequality, it is testing to see if the mode changed in the ticks directly preceding the current one. So "mode >= 3" is testing to see if the mode in the three ticks preceding the one containing the mode transition were all the same as the one at the start of the mode transition. A tick containing a mode transition is considered to have the mode at the end of the transition.
  • "Previous mode" refers to the mode that was in effect before the mode that is in effect at the start of the transition.
  • Buy and sell orders are always given for the maximum amount of stock.
  • Rising and falling refer to the price action of the stock in the specified number of ticks immediately preceding the transition tick. For example, "rising >= 3" means that starting with the fourth tick prior to the mode transition, the stock price either rose or stayed the same in each of the following three ticks. Similarly, "rising < 4" means that starting with the fifth tick before the transition, there is at least one pair of ticks where the stock price falls rather than rises.
  • If a rising or falling test is followed by the word "limited" in parentheses, it means that the full range of the test is used only if the mode remains unchanged for the ticks used in the test. If a mode change occurs close enough to the current mode change that the requisite number of ticks cannot be included in the test, the result of the test is deemed to be false.
  • "Resting" refers to the stock's resting value.
  • The bank ceiling is fully explained in the Ultimate Stock Market Guide under its own section. Briefly, it's equal to $100 when your banks are at level 1 (which is where the stock market first becomes visible) and increases by $3 for every level that your banks increase.
  • The word "ceiling" used when not preceded by the word "bank" refers to CookiStocker's custom ceiling, which is the maximum of the bank ceiling and the stock ceiling, times a fixed constant (currently 0.9). The stock ceiling is equal to the stock's resting price plus 50. It is no longer directly used by the stock market minigame, but I find it a useful number for the trading strategies.
  • The precedence of operations is standard. When a different precedence is required, parentheses are used.

    And here's the algorithm itself. Note that this is just a subset of the full trading algorithm; it replaces steps 8 through 10 in the post above. Steps 1 through 7 remain, and they take precedence if there are any conflicts.

    0 -> 1 Stay.
    0 -> 2 Stay if hold and mode >=3 and rising >=3 and previous mode != 1 and previous mode != 3; otherwise sell.
    0 -> 3 Always buy.
    0 -> 4 Always sell.
    0 -> 5 Buy if falling >= 4.
    1 -> 0 Buy if not hold and price < bank ceiling and sell price > bank ceiling.
    1 -> 2 Buy if not hold; stay if mode >= 4 and (rising >= 3 or price < resting + 20); otherwise sell.
    1 -> 3 Always buy.
    1 -> 4 Stay if hold < 6, otherwise sell.
    1 -> 5 Sell if mode < 6 or rise >= 3 or price > resting + 10.
    2 -> 0 Buy if mode >= 5 and falling >= 4 or mode < 5 and previous mode == 4; sell if hold >= 4 and rising < 4.
    2 -> 1 Buy or hold if mode >= 4 and (hold or not hold >= 4) and (price < resting – 20 or falling < 4) or if mode < 4 and (previous mode == 5 or falling >= 5); otherwise sell if hold.
    2 -> 3 Always buy.
    2 -> 4 Always sell.
    2 -> 5 Buy if (not hold >= 4 and rising < 4 or price < resting + 10) and price < ceiling; sell if hold >= 4 and price > resting + 10.
    3 -> 0 Stay if rising >=4; otherwise sell.
    3 -> 1 Sell if hold.
    3 -> 2 Sell if mode < 30.
    3 -> 4 Always sell.
    3 -> 5 Stay if mode < 20 and (rising < 4 or price < resting + 20), otherwise sell.
    4 -> 0 Buy if price < rising - 10.
    4 -> 1 Buy.
    4 -> 2 Sell if hold.
    4 -> 3 Always buy.
    4 -> 5 Buy if not hold >= 8 and (falling < 4 or price < resting) and (previous mode != 2 or mode < 14) and previous mode != 3.
    5 -> 0 Stay.
    5 -> 1 Buy if not hold and mode < 22 and (rising >= 4 (limited) or price < resting + 20 or previous mode == 4); sell if hold and mode >= 4 and rising < 4 and price > resting - 20.
    5 -> 2 Buy or stay if (not hold >= 3 or mode >= 3) and (falling >= 3 (limited) or rising >= 3 (limited) or price < resting – 10 or (previous mode == 4 or previous mode == 2) and price < ceiling); sell if (rising >= 4 (limited) or mode < 12 and previous mode == 3 or price > resting + 10.
    5 -> 3 Buy if not hold >= 3; stay if hold.
    5 -> 4 Always sell.

    Note that with the first two posts in this thread, you have a complete algorithm that you can trade on, and it's not even in any automated system yet.

    If people would like to see occasional updates of this algorithm, please let me know.
< >
Showing 1-1 of 1 comments
Per page: 1530 50