Custom Bots strategy ( insights ) beginner experience ( tutorial ) Custom Bot (

Custom Bots Strategy ( Insights ) Beginner Experience ( Tutorial ) Custom Bot (:

As a trader who has been deeply involved in the cryptocurrency space for a long time, rational trading should be placed in a position of utmost importance. Using Bots' judgment can help detach from more emotional manipulation and missteps.

Gate Custom Bots ) are suitable for traders who are sensitive to price fluctuations and have specific requirements for risk control, such as take profit and stop loss. They can make judgments and execute operations easily without the need for complicated mainstream Python quantitative trading code.

I think many people have a strong demand for running simple custom Bots, which can be very helpful in terms of take profit and loss, without needing to monitor the market all day long, being able to respond to extreme market conditions on their own, and even implementing full or semi-Bot operations by themselves. They can control the entry and exit based on the general trend using ( to start or stop ). For take profit and loss and re-establishing positions, they can rely on Bots. For example, the simple code below can easily achieve semi-Bot operations for take profit and loss and re-establishing positions by just deleting the first two lines in rule 2 regarding the 24-hour low.

Here, I summarize the basic insights and experiences I've gained while writing strategy code for a long time, aiming to provide everyone with a clear and straightforward introduction to Gate's custom Bots:

  1. Using line breaks after 'and' works just the same, making it convenient for daily coding and maintenance.

  2. The spaces before and after and or can be removed, generally leave a space after a number. ( save code space )

  3. Spaces within general function code can also be removed. When creating rule variables, you can take a closer look at the function usage instructions in the upper right corner of the webpage. ( save code space ) (Creating rules and variables)

  4. The “and” and “or” in code: each “and” condition will only execute the next “and” condition after the current one is satisfied. If the current “and” condition does not meet the criteria, it will jump to the next “or”. “And” means “as well as”, and “or” means “either”. #BTC仓位大于0张、# speed improvement (

  5. Code execution speed improvement, it is recommended to place time-consuming judgments like min/max at the end of the code. The values for functions like min and max should not exceed 10,000 minutes, which is about 7 days; for daily use, within 3 days is appropriate, otherwise it will run very slowly. Place the judgments at the end to reduce the likelihood of calls. ) speed improvement (

  6. If there is a prompt of false below the input box for creating rules, it proves that the code input is incorrect. (Creating rules and variables)

  7. Too much code can be encapsulated in variables for execution calls. The variable order is generally placed before the rules, and the variable call is get_value)“variable_name”(. ) saves code space( (rules and variable creation)

  8. The min and max functions generally use >= and <=, while pure price typically uses > and <.

  9. Custom Bots currently still need to be created and followed on the web, it is recommended to operate on a computer or tablet, but simple editing or viewing can be done on a mobile browser. ) rules and variable creation (

  10. The short code runs approximately every 10 seconds, and the running log makes it easy to see the running speed. ) speed improvement (

  11. In price function judgments, the spot price ending with 'spot' is commonly used, which feels more real-time and functionally differentiated than the futures price ending with 'usdt', and also avoids code fatigue.

  12. It is recommended to write the reason and date after # for each significant modification and addition of code, so that it is clear and understandable when reviewing this line of code in the future.

  13. Regarding the trading fees, they are currently deducted according to the normal VIP level contract on the Gate platform, along with the settlement fund rate. I hope that in the future, the Gate platform will have preferential policies to promote the progress of custom Bots.

#=======

#=======

The simplest example code: Bullish market, enter at BTC 2-hour high, exit at BTC 24-hour low ) with +20% take profit, -20% stop loss(

  1. Rule Name inbtc: Buy BTC Conditions: position_net)“BTC_USDT”,“usdt”(==0 and max_price)“BTC_USDT”,120,“spot”(<=max_price)“BTC_USDT”,1,“spot”(and price)“BTC_USDT”,0,“spot”(>100000

)Note on the code in this article: If there are Chinese " " double quotes in the code, it is a display issue of the webpage. Please replace them with English " " double quotes, otherwise the input box will prompt a false error. (

Description for each line: #BTC position equals 0 contracts, #BTC 2-hour high buy-in, spot highest price in 120 minutes <= 1 minute, #BTC price is greater than 100000

Rule execution logic: BTC/USDT Perpetual Contract: 10x Price: Market Price Quantity ) number (: 10 #The number of contracts can be set based on the amount of funds, generally recommended to be 20% to 30% ) 10 times 1 contract's principal = current BTC price * 0.00001U ( All or None: ) check ( Round: ) number of executions completed, generally checked for unlimited times, initially recommended 10 times to ensure normal operation, then gradually modify to relax to unlimited times, but it is very easy to forget, resulting in the Bots successfully buying 10 times and not opening positions again, need to remember (.

![])https://img-cdn.gateio.im/webp-social/moments-a9c7607b66-b6d18f544a-153d09-69ad2a.webp(

  1. Rule Name outbtc: Sell Holding BTC Conditions: position_net)“BTC_USDT”,“usdt”(>0 and min_price)“BTC_USDT”,1440,“spot”(\u003e=min_price)“BTC_USDT”,1,“spot”(or position_net)“BTC_USDT”,“usdt”(>0 and max_price)“BTC_USDT”,6,“spot”(>max_price)“BTC_USDT”,5,“spot”(and position_avg_open_price)“BTC_USDT”,“usdt”(*1.02 < index_price)“BTC_USDT”,0,“usdt”(or position_net)“BTC_USDT”,“usdt”(>0 and position_avg_open_price)“BTC_USDT”,“usdt”(*0.98>index_price)“BTC_USDT”,0,“usdt”(

)Notes on the code in this article: If there are Chinese " " double quotes in the code, it is a display issue of the webpage. Please replace them with English " " double quotes, otherwise the input box will prompt a false error. (

Each line description: #BTC position greater than 0 #24-hour low, latest spot price; or #BTC position greater than 0

Determine if the new high of 6 minutes is greater than that of 5 minutes, take the increase, avoid taking profits too early during minute-level rises ) strongly recommend to keep or only make slight adjustments (,

#+20% take profit, *1.02 is +20% profit; or #BTC position greater than 0 #-20% stop-loss, position_avg_open_price)“BTC_USDT”,“usdt”( is the average opening price of the contract, *0.98 is the -20% stop-loss, index_price)“BTC_USDT”,0,“usdt”( is the index price of the contract; #Note: Each part after 'or' is new, and it is necessary to check that the BTC position is greater than 0 to avoid empty brushing and excessive calls that may cause slow execution when there is no position. #Note: Leave a space when there is a number before and. #Note: The end of the last line does not need to add and or or

Note: Position and take profit/loss suggestions, a daily allocation of 20% to 30% is sufficient, and overall should not exceed 30%. For new coins and small coins with particularly large fluctuations, it is recommended to lower the allocation to 10% to 20%, and to increase the take profit/loss to 40% to 30% to increase the margin of error.

#Note: Regarding anxiety, there may occasionally be losses caused by drawing doors in a slow rising market, which is an inevitable loss of the unsolvable situation. Overall, it will be compensated through other bottom fishing, and there is no need to worry.

Rule execution logic: BTC/USDT perpetual contract: 10x Price: Market Price Quantity ) number (: position_net ) “BTC_USDT”, “usdt” ( #This sell quantity function is for the current BTC holding position, sell as much as you hold. All or Nothing: ) check ( Only reduce position: ) check ( Rounds: ) unlimited times (

![])https://img-cdn.gateio.im/webp-social/moments-a9c7607b66-e4d056a619-153d09-69ad2a.webp(

Execution order: inbtc, outbtc.

![])https://img-cdn.gateio.im/webp-social/moments-a9c7607b66-ada2a837c2-153d09-69ad2a.webp(

The above is the basic code; once added, it can be run. After running, wait for the coin price to reach a new high in 2 hours before buying in. Check the running status on the main interface.

The above uses the website:

Add Rule: https://www.gate.com/zh/strategybot/becomeStrategyMaker/newCustomize/rule Add execution order and run: https://www.gate.com/zh/strategybot/becomeStrategyMaker/newCustomize/strategyList Main interface, running Bots and data: https://www.gate.com/strategybot/underwayStrategy Function usage instructions: https://www.gate.com/zh/strategybot/becomeStrategyMaker/newCustomize/help

#=======

#=======

Advanced, a bit more complex or later, you can modify the corresponding code above to:

  1. Market price to limit price: The rule in btc, the buy market price can be set as limit price ) sell at 10 price (: ask_price ) “BTC_USDT”, 10, “usdt” ( Rule outbtc, the selling market price can be set as the limit price ) buy 10 price (: bid_price ) “BTC_USDT”, 10, “usdt” (

  2. The number of rules in btc ) number of shares ( change 3 to the position ) to be Bots spot funds + contract funds of 30% - current position, where floor ( is to take the integer down, for example, 1.2 is 1): floor()balance(“usdt”)+collateral(“usdt”() * 0.3/price)“BTC_USDT”,0,“spot”( * 100000(-position_net(“BTC_USDT”,“usdt”) Explanation of 30% position code breakdown: #Bots( spot funds + contract funds) 30% divided by the coin price multiplied by 100000 to get the number of contracts for 30%, the calculation method for each coin slightly differs but generally, filling 1 contract on the contract can determine it) ETH is * 1000, SOL is *10(,) balance) “usdt” ( + collateral) “usdt” ( 0192837465656574839201 * 0.3 / price) “BTC_USDT”, 0, “spot” ( * 100000

Among them, floor) ( is for rounding down to the nearest integer, such as 1.2 being 1, because the number of shares should be based on whole numbers, and for the sake of standardization, it is generally recommended to use the upper limit.

#Subtract the current positions to avoid over-leveraging, -position_net(“BTC_USDT”,“usdt”) #Note: The funds for Bots in spot and contract trading are universal. Initially, all funds are in spot; after opening a position, the funds allocated will automatically adjust to the contract funds. You can see the current position changes by clicking on the ongoing Bots on the webpage.

  1. You can add a dual variable to familiarize yourself with variable usage: judge if btc is greater than 100000 and put it into a variable for judgment. When get_value(“btc”)==get_value)“btc2”(, execute: Add variable ) to the URL (: https://www.gate.com/zh/strategybot/becomeStrategyMaker/newCustomize/ruleList

Variable name btc: Condition: get_value)“btc”(!=get_value)“btc2”(and price)“BTC_USDT”,0,“spot”(>100000 Variable value: get_value)“btc2”(

Description for each line: #When the variable btc!=btc2 )!=is not equal to ( #btc price greater than 100000

The variable value follows the variable value of btc2 (Note: All variable initial values are 0 when they start running, and only change after being written.)

![])https://img-cdn.gateio.im/webp-social/moments-a9c7607b66-1b02576e78-153d09-69ad2a.webp(

Variable name btc2: Conditions: get_value)“btc”(==get_value)“btc2”(and price)“BTC_USDT”,0,“spot”(<=100000 Variable value: get_value)“btc”(+1

Description for each line: #When the variable btc==btc2 )==equals ( #btc price is less than or equal to 100000 #The variable value is variable btc plus 1

![])https://img-cdn.gateio.im/webp-social/moments-a9c7607b66-5ec0a8c78a-153d09-69ad2a.webp(

The result is as follows: get_value)“btc”(==get_value)“btc2”( when the BTC price is greater than 100000; get_value)“btc”( != get_value)“btc2”( when the BTC price is less than 100000.

The way to add variables to the rules inbtc is: position_net)“BTC_USDT”,“usdt”(==0 and max_price)“BTC_USDT”,120,“spot”(<=max_price)“BTC_USDT”,1,“spot”(and get_value)“btc”(==get_value)“btc2”(

![])https://img-cdn.gateio.im/webp-social/moments-a9c7607b66-a6ea14f74b-153d09-69ad2a.webp(

Execution order: btc, btc2, inbtc, outbtc.

![])https://img-cdn.gateio.im/webp-social/moments-a9c7607b66-bee1d10d71-153d09-69ad2a.webp(

After running, the operating log will reflect the code execution status and the changes in variable values.

)Note on the code in this article: If there are Chinese " " double quotes in the code, they are display issues from the webpage. Please replace them back with English " " double quotes, otherwise the input box will prompt a false error. (

#=======

#=======

Disclaimer: All the above content is derived from experience summaries and is intended for communication and learning purposes. The accuracy and completeness of the content are not guaranteed. The content is for reference only and should not be considered as any operational or investment advice. Please analyze and learn independently!

PS: I'll stop writing here for now. If there are many viewers or the interaction is ideal, I can write more complex code examples.

BY: Violent Koala, please follow, like, and share! Reprint with source: Violent Koala's Gate updates https://www.gate.com/zh/profile/BRUXEwQc

BTC-2.18%
ETH-4.41%
SOL-2.9%
View Original
Last edited on 2025-10-24 14:52:47
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • 1
  • Repost
  • Share
Comment
0/400
ViolentKoala,VKoalavip
· 10-24 14:39
Bots assistance is the big trend in future trading.
View OriginalReply0
  • Pin
Trade Crypto Anywhere Anytime
qrCode
Scan to download Gate App
Community
  • 简体中文
  • English
  • Tiếng Việt
  • 繁體中文
  • Español
  • Русский
  • Français (Afrique)
  • Português (Portugal)
  • Bahasa Indonesia
  • 日本語
  • بالعربية
  • Українська
  • Português (Brasil)