Screenshot of script python code

35% ROI in 15 Days – New ADX Driven 3Commas Bot Trigger Script

I recently completed testing this new automated script to trigger 3Commas bots and actual trading returned 35% in just 15 days! Even with a couple days turned off, the returns were better than I expected. Rather than wait any longer, I’m sharing the script now! Here’s the details….

Script Performance

The script ran for a span of fifteen days over the holidays (was off for about two days), and managed to peak at $60 on a $165 account during that time, so just over a 36% return in that period. There’s definitely some drawdowns happening, especially with higher volatility, but overall the net positive return seems to be very promising.

Script performance thirty five percent in fifteen days

How the Script Works

Similar to the first script I wrote, this one relies on 3Commas DCA trading bots and, however instead of looking for breakouts, it looks for trends using the Directional Movement Indicator (DMI) and the Average Directional Index (ADX), and instead of starting deals, it starts bots. The bot remains active until conditions are no longer met.

The script scans all perpetual futures on (except for black-listed ones) and will trigger the corresponding bot to start when the DMI lines cross – but only if the ADX line has a positive slope, and it’s value is above 15 (configurable). This goes for both longs and shorts.

The script will then rank all perps meeting the above conditions based on the absolute slope value of the EMA-20 line (configurable). The slope values are then smoothed using an EMA-3 calculation (also configurable). This is a very crude way to rank them, but seems to work well enough.

The stopping condition is configurable, and can be manual, when the ADX slope turns negative, when the ADX slopes tends to horizontal, or when the DMI lines again cross.

The base values in the script are the recommended values to start with, and I will cover the closing conditions in a bit more detail later on.


For this script you’ll need an account, the Pro plan on, and a way to run python scripts. I like the Python IDLE for local development and testing, but run my bots using a Google VM Instance so they continue to run while I’m offline. You’ll also need to connect your 3Commas account to your FTX sub-account you plan to use.

Installing the Script

Installation is similar to the previous script, but we need a few more dependencies with this one. I created a separate guide describing exactly how to setup and install the scripts on a Google VM so it can run 24/7. That guide includes all the dependencies you’ll need for using this particular script, as well as some details on how to install the script, and how to use Tmux to get the script to run continuously.

Next you’ll install the script. Details can be found in the section How to Install and Setup Python Automated Trading Scripts, except you’ll want to use the code at this link to get the zip file for this script.

Setting Up The File.

In the referenced guide in the previous section I covered how to do this, but make sure to rename the file to just, then open it to edit it and add your 3Commas and FTX details such as API and secret keys, sub-accounts, etc. Lines 1 to 4 are for 3Commas, and 6 to 8 are for FTX.

3commas and FTX API settings in config file

On the last script a lot of folks had issues finding the correct 3Commas Account ID. Unfortunately 3Commas doesn’t make this obvious or easy to find for the futures account (it’s different from the subaccount ID for spot). The easiest way to find it is described in this comment from the previous script. The next few lines configure the script:

Script settings in config file
  • PAIRS_BLACKLIST – Include any perps you don’t want to trade. The ones included already are there either because they don’t move much, not actually a perp, or there’s no matching pair in 3Commas, such as SHIB. Feel free to add any others as you wish.
  • MAX_OPEN_POSITIONS – This sets the maximum number of deals that can be open at the same time. It’s an upper limit though, and the script may calculate a lower number based on your bots’ usage of funds, and the funds available in your subaccount.
  • FUNDS_USAGE – You can limit how much of the funds in your subaccount will be used for trading. I tend to leave some headroom for drawdowns and as well for manual red bag recoveries. The value of 0.9 means the script will only use up to 90% of the funds in the subaccount.
  • TF – The time frame you want to trade – in minutes. 15 minutes, 60 minutes, 240 minutes, etc. The minimum needs to be greater than 1 minute, and the maximum needs to be less than 1 day. A good starting point is 15 minutes or 60 minutes. I wouldn’t recommend going over 4 hours (240 minutes).
  • ADX_LENGTH – The number of bars to use for calculating the ADX value. This is the same as the TradingView default.
  • EMA_LENGTH – Similar to the ADX_LENGTH, but the ema is used for helping rank pairs. Larger values will be more lagging, shorter values more false signals.
  • EMA_SMOOTHING – This smoothes the slope calculation of the EMA values for ranking the pairs.
  • DEAL_BOT_RATIO_WARNING – This defines a warning level of the number of open positions on the exchange to the number of enabled bots. In the shell window a message will be displayed letting you know you’ve reached this level and you may want to manually close some open positions or deals since many of those may now be red bags and you’re missing out on potential winning deals on other pairs. If the setting CLOSE_DEALS_WITH_BOT is True, then this warning should never be displayed since the pairs are closed when the bot is disabled.
  • CLOSE_DEALS_WITH_BOT – Bots are deactivated (so they won’t make more deals) when the ADX slope turns negative. When this is set to True, any open deals from that bot will also be closed at the current market price. If set to False, the bot is disabled, but any open deals for that bot remain open.
  • EARLY_CLOSE – This attempts to close deals when the last three consecutive ADX slopes are progressively lower than each other, indicating a slowing trend. The aim here is to reduce the drawdown even further by preempting the ADX slope going negative.
  • CLOSE_DEALS – When set to True, any open deals will be closed when the DM indicator lines cross in the opposite direction. When set to False, no deals will be closed when the indicator lines cross.

For the last three settings above, when CLOSE_DEALS_WITH_BOT is set to True, CLOSE_DEALS has no effect since the deals will be closed when the bot is deactivated. This also means deals can be closed too early, with two possible outcomes – 1) The deals are closed before a profit can be taken, or 2) The deals are closed before your bags become too red. So there’s a trade off here – let them run and hopefully close itself with your TP, or cut your loss early and move on.

When EARLY_CLOSE is true, the bots are deactivated even earlier, possibly giving the deal some time to close in profit before a potential trend reversal. When CLOSE_DEALS_WITH_BOT is also True, this further reduces the possibility of deeper drawdowns, but also possibly misses on more upside.

If the CLOSE_DEALS option is True while CLOSE_DEALS_WITH_BOT is False, in the scenario’s above you 1) Give your deal a chance to close in profit, if the price does pump back up, or 2) Take a deeper loss since when the DM indicator lines cross it will undoubtedly be further away from when the ADX turned negative. In back-testing, the ADX did produce some false signals and profits were higher in this scenario for some coins, and hence why this option was added.

If both options are False (CLOSE_DEALS and CLOSE_DEALS_WITH_BOT), the script will not close any deals on red bags, and you’ll have to close them manually. This is not a bad option if you’re not trading with leverage since you can still theoretically make a profit regardless of how far in the red the deal has gone – though it takes more patience and you could miss out on other gains in the meantime. It’s also a great way to conserve your capital. The biggest downside is you could miss out on market reversals and be really really red on all your bags if you’re not paying attention.

3Commas Bot Settings in

The section of settings below the above settings are specifically for creating and updating your 3Commas bots.

3Commas bot settings in config file

I’ve cleaned this up a bit from the last script, but should be fairly self-explanatory. The first section is used for creating and updating bots, and the second is used on updates only. These settings all coincide with 3Commas bot settings as if you were setting up a bot manually in 3Commas, so they should be familiar.

Creating Your 3Commas Bots

Compared to the previous script, creating the 3Commas bots is very similar, with one difference – we don’t need to enable the bots after they’re created. Hence that option is now deactivated in the script as it’s not needed.

Assuming you’ve completed setting up the file, in the terminal window run the bot creator script using:


As the script runs the shell window will show as each bot is created. Long bots will be created, followed by short bots. You can ignore the error{} texts that appear, this just means there was no error creating the bot. Let the script continue until the shell prompt is back again.

Updating Your 3Commas Bots

This is very similar to the above operation if you need to make changes to your bots. First make your changes to the bot settings in the file, then run:


Choose the first option (all the rest are inactive). The shell will display the progress and run through each bot, very similar to how the create bot script does, and updates each bot.

Start The Automated Trading Script

Assuming all your bots are setup without any issues and all dependencies are installed, you should be able to now start your script. If you’re testing locally on the Python IDLE interface, open the script and hit the F5 key to start the bot. If you’re running from a shell window, make sure you’re in the same folder as the script and type:


Experiment With Different Script and 3Commas Bot Settings

While the file has some default settings (most used in my initial testing), keep in mind I didn’t do extensive testing. The settings used may not work in all market conditions and could affect actual returns. Using a shorter timeframe would reduce drawdowns on reversals while waiting for the script to check for updates, but could also mean increased false triggers. You could also test different bot settings. More SO’s with higher martingale or step percentage. The bot settings are based on this guide for trending markets since the intent of this script is to activate bots that are in a trend.

Possible Future Updates to the Script

No automated script is perfect, and there is always room for improvement. Two possible implementations come to mind that might be helpful. The first is looking at a higher time frame trend to validate the entry. In other words, don’t start a long bot if the general trend is bearish on a higher time frame, and vice versa. There’s usually no shortage of bots to enable and I’m always hitting the max positions, so adding this filter might help thin out the list for better pairs to trade.

The second is to ignore signals resulting from breakouts. Breakouts generally wreak havoc on indicators since the data being used in the calculation is sort of an outlier. If you consider the price action will regress or normalize, then any signals from that breakout will be false signals. The hard part is deciphering between a breakout that will regress and the start of a strong trend or move we don’t want to miss. As a result, implementing something like this is tricky and may be better handled through stop management. It’s worth an explore at some point though.

That’s it! Make sure to sign up below so you don’t miss any updates or future scripts, and as usual, drop some comments below if you have any issues with the script, setting up, or suggestions on how it can be improved.

Stay up to date on all the posts and how-to’s, Subscribe!

259 thoughts on “35% ROI in 15 Days – New ADX Driven 3Commas Bot Trigger Script

  1. Hey Nick! Need some help!

    I’ve been testing a great multitude of set ups based of your script, but I’ve ultimately come out in the negative. I tried the basic script, the one with the new config settings, 15 and 1h timeframes, applied the triple RSI validators, tried 25 ADX settings, and a mix of each. I’ even trying to substitute the triple RSI for a triple Trading View Buy/Sell signals, but i don’t know how to code that (don’t know the terms).

    What I’d like to ask you is what of the currently tested settings would you recommend right now? I’m getting kind of burned hopping between this setting or the other and would like some stability. What do you recommend as of now?



  2. Hey Nick,

    Nice work! I tried to launch this on pythonanywhere but had some error messages, so I launched a google VM as per your blog post and I’m getting the exact same error messages. I don’t know how to fix this, would you be able to help at all?

    I manage to create all the bots but I get this when I run “python3”

    Balance: 200.01
    Max bot usage: 36.43306666666666
    Max positions: 4
    Getting perps OHLCV data…
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    Traceback (most recent call last):
    File “/home/USERNAME/adx-bot/”, line 359, in
    open_positions = get_positions()
    File “/home/USERNAME/adx-bot/”, line 116, in get_positions
    if ‘info’ in all_positions[0]:
    IndexError: list index out of range

    Any ideas?


    • It sounds like your subaccount on FTX has never held a position. Go to FTX and try to buy and then sell a perp in that sub-account – it can be anything, any amount – the sub-account just needs to have a history. Even one buy then sell will do.


  3. Thanks Nick, that solved the problem! I think a really nice addition would be a higher timeframe trend filter and also the ability to configure to do ‘short only’ and ‘long only’. Most of my losses today was on long positions 🙂 This way one could analyse the market and decide if it makes sense to go short only or long only. I don’t know python but your blog has inspired me to learn it.


    • This branch has the HTF filter:
      I haven’t merged it into the main branch yet. I need to refactor the code to make it run faster and ping FTX less, but it works.
      I’ll see what I can do on selecting longs and shorts only. The point of the script was to catch whatever trend was happening, but I can see how it might be useful. It might take me some time, but I’ll have a look at it.


      • That’s very interesting. I tried to launch it but get the following error message, any ideas what I can do to fix it?

        Balance: 200.00061519
        Max bot usage: 36.43306666666666
        Max positions: 4
        Getting perps OHLCV data…
        . . . . . . . . . . . . . . . . . . . . . . . . . . Traceback (most recent call last):
        File “/home/USERNAME/.local/lib/python3.9/site-packages/pandas/core/indexes/”, line 3621, in get_loc
        return self.engine.get_loc(casted_key)
        File “pandas/_libs/index.pyx”, line 136, in pandas._libs.index.IndexEngine.get_loc
        File “pandas/_libs/index.pyx”, line 163, in pandas._libs.index.IndexEngine.get_loc
        File “pandas/_libs/hashtable_class_helper.pxi”, line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
        File “pandas/_libs/hashtable_class_helper.pxi”, line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
        KeyError: ‘EMA_20’
        The above exception was the direct cause of the following exception:
        Traceback (most recent call last):
        File “/home/USERNAME/adx-bot-add-htf-validation/”, line 358, in
        unfiltered_stats, trend_dir = perp_stats(perp)
        File “/home/USERNAME/adx-bot-add-htf-validation/”, line 273, in perp_stats
        ema_fast = df2.loc[(df.shape[0]-2), ‘EMA
        File “/home/USERNAME/.local/lib/python3.9/site-packages/pandas/core/”, line 960, in getitem
        return self.obj._get_value(*key, takeable=self._takeable)
        File “/home/USERNAME/.local/lib/python3.9/site-packages/pandas/core/”, line 3615, in _get_value
        series = self._get_item_cache(col)
        File “/home/USERNAME/.local/lib/python3.9/site-packages/pandas/core/”, line 3931, in _get_item_cache
        loc = self.columns.get_loc(item)
        File “/home/USERNAME/.local/lib/python3.9/site-packages/pandas/core/indexes/”, line 3623, in get_loc
        raise KeyError(key) from err
        KeyError: ‘EMA_20’


      • Hmm, difficult to say for sure. Does the regular branch work ok? Did you update the for this one as well? It’s slightly different to the one without the HTF filter. And lastly, what time frame are you using?


      • Yes, the regular branch worked fine for me (some losses but script behaved correctly). I cloned the HTF version in a separate folder and configured the file correctly. I’m using the pre-set 15min timeframe and didn’t do any other modifications to the settings. The only thing I did differently was that I edited all strategies (manually) to set trailing stop ON, after I had run the script. Do you think that could have caused this issue somehow? I would assume the original bot ID would stay the same, so it shouldn’t matter in terms of running the script? I will try again from afresh and see if it works, wihtout manually adjusting the bots.


      • I think I’ve found a solution to this and wanted to share. I ran the following: pip3 install ccxt==1.63.1 (as per Nick’s comment on the other blog post) and it seem to have solved the problem. Script now runs.


  4. Hey Nick, just wanted to ask if you got any interesting results or updates you wanna share on the bots performance, be it on this script or the multipair bots you said you made.



    • Nothing to report back yet. It’s been a bit crazy at work, so I’ve had very little time to do any more testing. The multipair bot has been doing fairly well, I only check in on it every few days. It’s pretty hands-off at this point, and maybe 50 or 60% return in the last month. I’m hoping to get a post on that setup in the next week or so. Basically, it’s the three RSI triggers the other Pedro mentioned, running on a multipair bot in 3Commas. There’s no python script to worry about. Anyways, keep an eye out for the post, hopefully this coming week.


      • Impressive. I went up and set a long and short bot like that to check it out. I just opened multy pair bots, set the minimum base order, and gave only the 3 RSI checks from pedro for it to work with. Also, I cleaned the bot pairs from everything that wasn’t a PERP (the 0305 numbers). Did you do that as well?

        Also, completely unrelated, I’ve been getting this bug when trying to run the basic script since yesterday. I’ve tried everything, including a clean install, and it doesn’t go away. Any thoughts?

        Thanks for everything.


      • Did you do that as well?

        Yes, definitely. I also removed any stable coins. You’ll also find as you go you’ll remove a few that are very low volume, or ones that don’t move much. Typically the deal will be stuck at some percentage very close to zero and the past price action would look like it’s not going to hit any SO’s anytime soon. So I close the deal and remove it from the list as well. FYI, I also used 3x leverage, the long bot does much better than the short bot – and be careful in strong trends (like today), where a buy/sell signal could be triggered but there’s little chance of a bounce. This bot takes profit on bounces, so it’s trading against the trend – as long as you’re aware, you can watch and react accordingly.

        I’ve tried everything, including a clean install, and it doesn’t go away. Any thoughts?

        Looks like either FTX’s API is being weird, or ccxt has gone and changed their code again. Neither are unusual, but hoping it’s just FTX. I’ll have a look later today and see if I can replicate it. Let me know if it rights itself.


      • Will do. If it rights itself I’ll post about it ASAP. Hopefully it will, but it’d be great if you could quickly check to see if this issue isn’t exclusive to me, cause then it could be happening to more people and could imply more serious problems.



      • You were right Nick! The issue was likely FTX’s, I managed to get it working after trying a few more times.


  5. Hi Nick, great scrip and thanks for all the posts, interesting reading. I got everything setup and connected, but when I run the script I get the following:

    no existing bot ID files found, proceeding….
    The following long pairs were ignored, order volume too low: []
    The following short pairs were ignored, order volume too low: []
    0 long bots created.
    0 pairs ignored, order amount to low
    0 short bots created.
    0 pairs ignored, order amount to low
    Ignored pairs can be found in ignored_longs.txt and ignored_shorts.txt
    All done, have a nice day!

    3C is talking to the FTX sub-account and am using the same API details in the config file as in 3c, also used the trick you mentioned to find the correct ID for 3c. As per a previous comment, I did also make a manual trade in FTX and can setup a bot manually just fine.

    Any ideas? Bound to be me being simple, thanks!


    • Hi James,

      It looks like you’ve got everything covered, and there’s no error message, so I’m not sure why it’s happening. This is indicating no “PERPS” are being found, so no bots are being created. Are you able to create a bot with a perp 3c?


      • Hi Nick, thanks for the reply. You are bang on the money, I can only see one Perp token in 3Commas when manually creating a Bot against FTX (I can see them all on FTX itself). So guessing that’s the root cause, I’ll open a Ticket with 3C and see what they say.

        On a side note, I have been running a bot against 3X Long Ethereum Token (ETHBULL) with fairly decent looking returns, too early to really say but so far so good.

        LongUSD Long Bot, TP 2.5%, BO 2.0 USD, SO 6.0 USD, OS 3.0, SS 1.9, SOS 1.27, MSTC 3, Nonstop

        At the moment running a couple of different bots to test settings on a small scale, but that one so far seem to be doing quite well.

        Will look forward to your Multipair post when you get the chance to write. Cheers!


      • Hmmm so quick update, I actually can see the PERP pairs under FTC Futures rather than FTC but I think my issue is more local, as putting the wrong API keys in still gives the same message as per before. Will shelve that VM and build a new one.


  6. Firstly, thanks so much for tremendous effort and your willingness to share. Made good profit first day trying it out. however, on the second day, my position was not closed even when I am losing about 35$ out of 100$ trade value (-35%). I manually closed the position later. I am sure i might be missing something out here. here are my settings. can you please help me out?

    EARLY_CLOSE = True
    CLOSE_DEALS = True


    STOP_LOSS_TYPE = ‘stop_loss_and_disable_bot’
    START_ORDER_TYPE = ‘market’


    • Hi Sachin,

      It’s difficult to say for sure without knowing all of your settings, but there are a few things to look at. First, keep in mind you’re using leverage, so a 10% drop on $100 is $10 X 3 = $30. Some alts have been dropping fast the last few days, so this is very possible.
      Second, the CLOSE_DEALS = True means the deal will be closed when the two directional lines (DM+ and DM-) cross in the opposite direction. These do lag a bit, so again, this is possible when prices drop very fast. You can pull up the “Directional Movement Index” indicator on a TradingView chart for that coin, set the same time frame, and look for when the cross happens. Keep in mind, we don’t know a cross happens until the candle is complete. In other words, the signal to close the deal comes at the start of the candle immediately following the cross over, ie the opening price (or very close to it) of the following candle.
      And lastly, the script had to be still running to be able to close the deal. If the script stopped for some reason, then it wouldn’t have been able to close the deal.

      I hope that helps explain why it might have happened. To date I’ve never seen the script miss a close like that, but let me know so I can take a closer look.


  7. Hi Nick, just to confirm I had the same issue as another poster, same fix by using “pip3 install ccxt==1.63.1” and the bots where then crated. Cheers!


      • He nick can you help me with the script as it is not working at the moment? Can we have a teams meet where I can share my screen please?


      • Why not just create a requirements.txt file to manage all dependencies?
        /project_folder $ python3 -m pip install requirements.txt should do the trick, right?


  8. Hey Nick, sorry to bother with this question, but on your experience so far, which of this script’s configuration has the best performance? The original settings:

    EARLY_CLOSE = True
    CLOSE_DEALS = False

    or the “new” one you’ve updated for a while?

    EARLY_CLOSE = True
    CLOSE_DEALS = True

    I’m very curious to compare your results with what I’ve got.



    • Hi Pedro,

      As far as limiting overall losses, False, True, False seems to be working the best. Unfortunately, this means manually saving the red bags which ties up your funds for some time while you wait for the right opportunity to do so.
      The original settings seem to suffer from too many small losses when the price is ranging and limits profits when the indicator fakes a move in the opposite direction.
      The “new” settings you mention let the bot run with more profit, so the upside is better, but also the downside is worse since in most cases most/all of the SO’s have been completed and then the script closes the deals.
      There’s no best setting unfortunately, and like most DCA bots the deals suffer from reversals. The settings I’m testing now would not require the use of 3Commas at all. Instead, the script will place orders on the same trigger, then also place take profits and stop losses at the appropriate risk to reward ratio, and on a slightly higher time frame. You could still use 3Commas for this by setting the SO count to zero and your BO will be the amount of the trade you want to go with. Having said that, I’m still testing this setup to make sure it will work.


      • Oh that’s neat, I eager to hear more from it!
        As a side note, I tend to have noticed that the bots major losses seem to be concentrated on weekends. Have you noticed that as well? It might be due to the low volume that leads to higher manipulation and fake moves. Hard to say though.


  9. Hi, is someone getting nice positive returns with this script as it is?
    I’ve been running it for the last 4 days… with 10 positions of 10 USD on a 2K USD balance. I’m now at 1950USD… it went up to 2200 USD but then just sunk and sunk… I’ve switched to the htf branch since last night… don’t know if it will be better.
    using the default settings on all…

    any suggestion?



    • Hi Florentin,
      I replied to your email as well, I hope it helps.
      In terms of the HTF validation, it will help on some deals, but not all since even the HTF can be fooled by reversals. I think with the right settings, ie no closing of deals (manually only), plus the HTF, it could work well, though not fully automated. For that, we would need to have stop losses in place, limit or have no safety orders at all, and a risk to reward ratio high enough to counter any triggered stop losses. As mentioned in the email, hopefully I’ll have some test results from that soon.


    • I haven’t been doing much in the last couple of weeks. Work’s been too busy, and the market’s been to crazy. Mostly just manual trading when I see an opportunity.


  10. Great Work – documentation just as impressive as the script – Got a question though…

    Running it i am getting

    No bot ID lists were found. Create bots and ID list before continuing.

    Do i need to set something up on 3commas?



    • Do i need to set something up on 3commas?

      You shouldn’t have to, no. Did you run the create bot script first? ie python3, and confirmed the bots were created in your 3Commas account?


      • ah on that script you said ignore errors… i got account ID invalid –

        “Other error occurred: record_invalid Invalid parameters {‘account_id’: [‘is invalid’]}.”, ‘status_code’: 400}

        I assume i cant really ignore that error … how i know my FTC acct ID ? I put in the subaccount name is that not correct?


      • Ok – reread again – its the 3commas ID – put that in… now running the create getting this error..

        no existing bot ID files found, proceeding….
        Error: {‘error’: True, ‘msg’: ‘Other error occurred: not_found Not Found None.’, ‘status_code’: 404}
        Traceback (most recent call last):
        File “”, line 193, in
        File “”, line 168, in build_bots
        longbot_list, no_long_bots = generate_long_bots(pairs_list, min_price)
        File “”, line 99, in generate_long_bots
        bot_list[key] = data[“id”]
        KeyError: ‘id’


      • ok resolved the account id invalid one – and go to this one ..

        Error: {‘error’: True, ‘msg’: “Other error occurred: record_invalid Invalid parameters {‘pair’: [‘No market data for this pair’]}.”, ‘status_code’: 400}


      • Is this happening when you’re running the script, or the main one?

        If it’s the main one, and you’ve properly identified the correct futures account ID (details in this comment), then it’s possible the sub-account has never had any trades. To solve that, go to FTX, buy and then sell a perpetual futures pair. It can be any pair, doesn’t matter. The response back from the API is empty, and causes this error. So making a small trade fixes that (until I can get to fixing the code).


  11. Hello Nick,

    First of all, thank you for this cool project.

    I wondered if you could share your current list of disabled trading pairs.

    Thanks a lot!


  12. Moreover, when I try to run ‘python3’ in the Terminal (adx-bot-master directory), I get the following error:

    no existing bot ID files found, proceeding….
    Error: {‘error’: True, ‘msg’: “Other error occurred: record_invalid Invalid parameters {‘pair’: [‘No market data for this pair’]}.”, ‘status_code’: 400}
    Traceback (most recent call last):
    File “////”, line 193, in
    File “/
    ///”, line 168, in build_bots
    longbot_list, no_long_bots = generate_long_bots(pairs_list, min_price)
    File “///***/”, line 99, in generate_long_bots
    bot_list[key] = data[“id”]
    KeyError: ‘id’

    Do you know any solution for this?

    Thank you in advance.


  13. Hello, the script worked fine for a couple days and then I get this error:
    Getting perps OHLCV data…
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Traceback (most recent call last):
    File “C:\Users\Janne\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\core\indexes\”, line 3621, in get_loc
    return self._engine.get_loc(casted_key)
    File “pandas_libs\index.pyx”, line 136, in pandas._libs.index.IndexEngine.get_loc
    File “pandas_libs\index.pyx”, line 163, in pandas._libs.index.IndexEngine.get_loc
    File “pandas_libs\hashtable_class_helper.pxi”, line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
    File “pandas_libs\hashtable_class_helper.pxi”, line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
    KeyError: ‘EMA_20’

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File “C:\Users\Janne\”, line 330, in
    unfiltered_stats = perp_stats(perp)
    File “C:\Users\Janne\”, line 247, in perp_stats
    df[‘EMA_SLOPE’] = df[‘EMA_’+str(ema_length)].diff().abs() / df[‘EMA_’+str(ema_length)]
    File “C:\Users\Janne\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\core\”, line 3506, in getitem
    indexer = self.columns.get_loc(key)
    File “C:\Users\Janne\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\core\indexes\”, line 3623, in get_loc
    raise KeyError(key) from err
    KeyError: ‘EMA_20’

    I tried older versions of packages but nothing worked, any idea what the issue could be?


    • I managed to fix this error by setting the timeframe back to 15 from 60. When the bot worked the performance was better with 60 minutes, would rather use the 60, it did work when I started the bot the first time.


  14. I am curious what the deal history was since you started it. I am looking in to start soemthing like you build it really looks nice. I just started with 3commas and see a lot of bots but which one is the perfect one is always the big question. I rather have 1 % per day then 35 and then -60 😉


    • which one is the perfect one is always the big question

      Absolutely! So far there haven’t been any perfect ones, yet. I think the trick is to find a few that work in various conditions and alternate them as required. I am looking at coding some future scripts that take fewer orders, but the consistency is considerably better.

      As far as long term testing, I haven’t kept the bot running consistently enough to know for sure as I’m always testing.


  15. Hello Nick, Im very grateful for this script, with some tweaking its starting to look very promising. The only way it works for me is if I dont have any of the stops on and only do manual safety trades on red deals, no big deal I guess but its not completely hands off.

    (for that previous comment, the HTF branch doesnt work with 60min timeframe, the main one does)

    Anyway my question is: I would like to understand the script properly to be able to make changes or maybe eventually build my own script. Where would you suggest I begin, I understand whats going on in the script but all the dependencies (pandas ccxt py3cw etc.) are a mystery to me as to what their functions are. Do you have any suggestions where I should start looking for information for learning all this?


    • The only way it works for me is if I dont have any of the stops on and only do manual safety trades on red deals, no big deal I guess but its not completely hands off.

      Yes, this is the best approach, and unfortunately not hands-off. If the market is trending then it is ok, but with these ranges we are seeing the last while the stops keep getting taken out and eventually erode our profits.

      (for that previous comment, the HTF branch doesnt work with 60min timeframe, the main one does)

      I will have to look into why this is happening, but my plan was to refactor this code anyways since it’s too slow and makes too many requests to the exchange. Hence why I have not merged with the original code yet.

      I would like to understand the script properly to be able to make changes or maybe eventually build my own script. Where would you suggest I begin, I understand whats going on in the script but all the dependencies (pandas ccxt py3cw etc.) are a mystery to me as to what their functions are. Do you have any suggestions where I should start looking for information for learning all this?

      So pandas, ccxt, py3cw, etc are external libraries I’m using so I don’t have to recode everything from scratch. For example, ccxt library handles the interface with the exchanges, in this case ftx. I don’t have to worry too much about how to code the initial authorization/connection, and the requests for market data. The ccxt library handles the complicated parts, and then with only one or two lines of code, make and receive my requests to ftx. py3cw is similar, but this is the interface to 3Commas, again to make the connection and “talking” with the 3Commas API much easier, since all the necessary code is built into py3cw. You can search for these to find them on Github, and they typically include instructions on how to use the libraries within your code.
      pandas is a tool for handling and manipulating large amounts of data. For example, in the code I request OHCL data for a coin to calculate the ema. If we need say the ema-40 value, we need to go back about 3 or 4 times the ema period to get an accurate value. In other words, I need 40 x 4 = 240 bars of data. I then need to calculate the ema using 40 bars at a time, from the beginning to the end, ie make the ema calculation 240 times – all just to get the ema for the latest bar. This is very slow and requires a lot of code to do. However pandas (and the ta library) makes it possible in only one line of code. Plus pandas is coded differently than traditional python, so it’s extremely fast.
      I think the best option if you want to learn is to look up each of the libraries, then compare to my code to see what is happening in the code.


  16. Thanks for this script, looks great and I am very curious how this will run.
    But as I don’t want to test with huge amounts, I use a rather low safety_order_volume and this makes that the Create script will generate errors. And in addition, in the error it’s not shown for what pair the error comes from.
    Therefore I made a small adjustment:

                print(f'{key} Error: {error}')
                if len(error) > 0:
                bot_list[key] = data["id"]

    At line 98 and line 148


  17. Hey Nick,
    I made a fork today (mvantloo) and did a few updates on your code because of some errors that I got… maybe they are also welcome for you.
    In addition, I am thinking to add some more error-handling (try/except) and a bit more output to the log-files.
    Let me know if it is welcome for you to work together, otherwise, just steal from me as how I steal from you 😉
    Thanks again for all the effort !! Great script and fantastic documents !!


    • Forgot to say: I also added a delete function in the update-script… that’s easy if you want to start over, so you don’t need to delete page-by-page all the bots from 3Comma’s.


  18. Hi Nick,

    Thank you so much for this script. I´ve been having some great results these last few days.

    Anyhow i want to make some changes to the bots and was wondering, how do i stop this script from running?
    I´m using your google cloud VM setup aswell. I´ve killed the tmux session but it continues to open deals. So how do i completely stop the script from running?


    • Sorry for the late reply! Hopefully you got the bots stopped. If you kill the tmux session then the script should stop running, though I always ctrl+c to stop the python script, then kill the tmux session. Also, make sure the bots on 3Commas are also deactivated. The script activates and deactivates them depending on market conditions. If you stop the script, then it will no longer control the bots on 3Commas and some may be left activated, and those need to be deactivated manually in 3Commas.


  19. Hey Nick, I recently started with your script as well, also via google cloud VM. It show good results, but I am not confident yet. But anyway, thanks for the nice work already!
    Last friday I did some changes in mijn script, among others the setting “CLOSE_DEALS” = TRUE. This morning I checked the results of the weekend. I saw a very nice “ride” on “CEL-PERP” short. But for some reason this morning around 4:30 AM the last deal was ended, and thereafter only “SELL’s” were done, but they were in big lose when I looked (at around 8:45 am). So the “BUY” order was not reached and my bot was still active according to my 3Commas dashboard. But when I got to my VM and wanted to “attach” to my tmux session, it told me there was no tmux session at all => Somehow my tmux session with my pybot seems to be ended after 4:30 am. The currently running bot executed all the safety orders, but the deal was not closed. Maybe the trigger to close the deal was not triggered yet, but the bot within my tmux session (the whole tmux session) seems to be stopped.
    My position was in nice red…. while the plan was that the red bag doesn’t become too big…
    Well, that my position is red, is one thing (that can happen), but the fact that my tmux session stopped working is concerning me more.
    Question 1: Did you have any experience that such an tmux session just ends?
    Question 2: Is there some logging somewhere to have a look at? to be able to see what maybe happened?
    Question 3: What can be a reason that such a tmux session ends?


    • Hi there,
      Sorry to hear this happened. I’ve never seen a tmux session stop, ever. I have some running for several weeks at a time. The python script may error out from time to time, mostly when FTX or 3Commas API’s go down or times out. I’ve added retries to the script so it keeps trying to make a connection, but it will eventually time out at some point. When that happens, the script stops running and can no longer control the bot, or close deals. It’s generally a good idea to keep a stop loss on the bot if you’re concerned about these situations. I personally prefer not to use SL’s with DCA bots and try to manually recover the deal.
      In terms of logging, there is some logging in the 3ctrigger_log.txt file in the same folder as the script, however it generally only records signals sent to 3Commas, and balance updates etc.


  20. Hey Nick,

    I run your script now for a while, without any automated close deals…. and end up with MANY red bags all the time because the long-bots buy in the top of a wick and the short-bots buy in the bottom of a wick.

    To avoid this, I added RSI settings in de bots and see that bots are all the time enable/disable in the times that the RSI is actually very bad; Most like 70+ on long and 30- on short bots, so therefore no deal is ever started….

    So my question is if this is expected, or is something going wrong in the ADX decisions?

    Thanks for your support !!


    • Hi Maurice,

      The red bags are typically a result of the market conditions, and especially what we are seeing now in crypto. The ADX is a lagging indicator, but it also reacts a bit (not nicely) to sudden moves. In the market now we are seeing the sideways action, and lots of sudden up and down moves within the range. The movement is enough to get the ADX above the minimum threshold, but the price then reverses, hence the entries at or near the top of a candle or wick.
      This script does do amazingly well in strong trends, but unfortunately it will give it all back in sideways markets like we are in now. My advice would be to hold off until things pick up again.


  21. Hi Nick,

    It looks like an awesome script you have made! Many thanks for sharing! Unfortunately, I get a strange error message when using it. The bots seem to be created according to the script, but I cannot find them in 3C. The following error message is displayed, and a bunch of messages about pandas…

    ImportError: cannot import name set_locale

    Can you help me out, please?


  22. Hi,

    I’ve encountered an error on multiple occasions that i can’t seem to figure out.
    Have anyone encountered this error message before?

    File “/home/…/adx/”, line 330, in
    unfiltered_stats = perp_stats(perp)
    File “/home/…/adx/”, line 239, in perp_stats
    df = pd.DataFrame(np.array(candles), columns=[‘Time’, ‘Open’, ‘High’, ‘Low’, ‘Close’, ‘Volume’])
    File “/home/…/.local/lib/python3.9/site-packages/pandas/core/”, line 694, in init
    mgr = ndarray_to_mgr(
    File “/home/…/.local/lib/python3.9/site-packages/pandas/core/internals/”, line 351, in ndarray_to_mgr
    _check_values_indices_shape_match(values, index, columns)
    File “/home/…/.local/lib/python3.9/site-packages/pandas/core/internals/”, line 418, in _check_values_indices_shape_match


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s