使用一种交易策略来连接到机器人的多个硬币

发布于 2025-01-31 08:43:41 字数 474 浏览 4 评论 0 原文

我是TradingView的新手,并且已经学习了很多东西。我正在使用Pine-Script语言进行回测的策略,但是让我感到困惑的是如何将相同的策略用于多个硬币。

该策略主要是为了赚钱期货交易而制定的,如果可能的话,是否可以将其应用于其他交易所。

因此,我想设置多个硬币的警报系统要连接到3comma bot或Finandy,以根据设置参数执行交易。

我的问题是。

  1. 如果我想使用某些蜡烛类型(例如Hiken Ashi),应该包含在代码中或仅在图表中选择它,并且该策略将自动读取?

  2. 我应该在脚本中包括硬币还是在图表中选择一个,然后设置每枚硬币的警报?

  3. 我应该每张一枚硬币创建一个警报,还是每张硬币都有多个图表来设置警报?

  4. 应该在代码中定义时间表,否则图表可以完成工作?

对不起,有很多问题,我试图很好地理解这一过程。

I'm a newbie for TradingView and have been learning a lot. I'm developing a strategy with backtesting using pine-script language however what confusing me, is how to use the same strategy for multiple coins.

The strategy is mainly developed for Binance Futures trading not sure if possible to apply it to other Exchangers.

So I wanna setup alerting system for multiple coins to be connected to 3comma Bot or Finandy to execute a trade based on the setup parameter.

My questions are.

  1. If I wanna use certain candle types like Hiken Ashi should that be included in the code or just select it in the chart and it will be read by the strategy automatically?

  2. Should I include the coins in the script or I should select them one by one in the chart and then setup an alert per coin?

  3. Should I create one alert per one coin per chart or I should have multiple charts per each coin to setup an alert?

  4. Should the timeframe also be defined in the code or the chart can do the job?

Sorry for many questions, I'm trying to understand the process well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不即不离 2025-02-07 08:43:41

对于多个硬币,最简单的方法是将您的策略​​附加到您要与之交易的交易中的每一个硬币上。这样,您可以在各自的图表上进行测试。

如果您为Binance:BTCUSDT创建一种策略,并考虑在不同的交流中使用此策略,您可以做到,但是首先,我建议对Binance进行测试:BTCPERP,并亲自查看相同的策略如何显示出截然不同的结果(即使BTCUSDT和BTCPERP也应该移动相同)。

对于一个复杂的解决方案,您可以创建一个使用多个证券的单个脚本,但是您将无法通过简单的方法进行回报,您将不得不编写自己的收益/损失计算器,而您还没有。

我沿着同一条道路,我的建议是:

  • 为要交易的硬币创建输入(将进入输入变量)
  • 摘要 strategy.entry.entry()>命令,也就是说,以某种方式构造警报消息,您可以用其中的变量替换值(如上所选择的硬币)
  • 3个commas需要一个bot ID来启动/停止一个bot,也要抽象地删除,并且您将拥有一个良好的样板代码您可以多次重复用作
  • 好的练习(从Kubernetes偷来),除了人类可读名称外,我给我的每个机器人提供了5个字母的标识符,以便简单地识别

一些示例。以下将为硬币和用于交易硬币的机器人ID创建一个选择器。诸如“ bin:gmtperp -osakr”之类的名称完全是我的制作,它们是钥匙(对于键/值对):

symbol_choser = input.string(title='Ticker symbol', defval='BTC-PERP - aktqw', options=[FTX_Multi, 'FTX:MOVE Single - pdikr', 'BIN:GMTPERP - osakr', 'BIN:GMTPERP - rkwif', 'BTC-PERP - aktqw', 'BTC-PERP - ikrtl', 'BTC-PERP - cbdwe', 'BTC-PERP', 'BAL-PERP', 'RUNE-PERP', 'Paper Multi - fjeur', 'Paper Single - ruafh'], group = 'Bot settings')

exchange_symbol = switch symbol_choser // if you use Single Pair bots on 3Commas, the Value should be an empty string
    'BIN:GMTPERP - osakr' => 'USDT_GMTUSDT'
    'BTC-PERP - cbdwe' => 'USD_BTC-PERP'
    'Paper Multi - fjeur' => 'USDT_ADADOWN'

bot_id = switch symbol_choser
    'BIN:GMTPERP - osakr' => '8941983'
    'BTC-PERP - cbdwe' => '8669136'
    'Paper Multi - fjeur' => '8246237'

现在您可以将上述部分组合到两个警报中,以启动/停止bot:

alertMessage_Enter = '{"message_type": "bot",  "bot_id": ' + bot_id + ',  "email_token": "12345678-4321-abcd-xyzq-132435465768",  "delay_seconds": 0,  "pair": "' + exchange_symbol + '"}'
alertMessage_Exit = '{"action": "close_at_market_price", "message_type": "bot",  "bot_id": ' + bot_id + ',  "email_token": "12345678-4321-abcd-xyzq-132435465768",  "delay_seconds": 0,  "pair": "' + exchange_symbol + '"}'

Exchange_Symbol 是您需要提供给机器人的适当的Exchange符号,您可以在3Commas的Bot页面上获得帮助(它们已预先制作了您需要用于某些操作的HTTP请求)。

bot_id 是您的机器人的ID,这很简单。

上述解决方案无法处理单个硬币机器人,其触发消息具有不同的结构。

只要您可以使用多硬币机器人,因为它们可以充当一个机器人,但要有两个例外:

  • 如果您有较长的跨度策略,并且当您启动一个机器人时,您应该已经进行交易,可以手动启动一个机器人, 无法启动多硬币机器人(因为无法提供可以启动交易的硬币信息)
  • 但是,如果您要交易诸如FTX的Move Contracts之类的衍生产品,并且您的脚本附加到基础BTC期货,则 。移动合同每天更改名称(日期是其名称,例如:BTC-MOVE-0523),因此您需要删除警报,更新和重新应用警报,等等。相反,如果您的脚本在BTC--然后,您可以使用单个硬币机器人,该机器人不会期望在警报消息中使用硬币名称,以便它可以启动/停止与其连接到的任何硬币上的机器人,然后您只需要每天更改bot中的硬币名称设置,永远不要触摸警报。

要总结您的问题:

  1. 不包括代码中的图表类型(甚至不是可嵌入的数据),只需将代码应用于您想要使用的任何图表即可。提示:切勿使用Heikin-Ashi进行交易。您可以,但您会为此付出深厚的付出(每个人都在尝试,即使是针对警告,不用担心)

  2. 一一设置它们,因此您可以回头测试

  3. 否,请在图表上设置时间表。稍后,当您经验丰富时,您将能够抽象当前的时间范围(无论它是什么),并编写时间范围的代码。但这很难使您的代码不那么可读。

For multiple coins, the easiest way is to attach your strategy to each and every coin on Tradingview you want to trade with. This way you can backtest each on their respective chart.

If you create a strategy for say BINANCE:BTCUSDT and think of using this strategy on different exchange, you can do it, but first I suggest test it on BINANCE:BTCPERP and see for yourself how the same strategy can show a wildly different result (even though BTCUSDT and BTCPERP should be moving the same).

For a complex solution you can create a single script that uses multiple securities, but you won't be able to backtest that with simple approach, you would have to write your own gain/loss calculator, and you are not there yet.

I was going down the same road, my suggestions are:

  • create an input for the coin you want to trade (that will go into an input variable)
  • abstract the alert message off of the strategy.entry() command, that is, construct the alert message in a way you can replace values with variables in it (like the above selected coin)
  • 3Commas needs a Bot ID to start/stop a bot, abstract that off as well, and you will have a good boilerplate code you can reuse many times
  • as a good practice (stolen from Kubernetes) besides the human readable name, I give a 5 letter identifier to every one of my bots, for easy recognition

A few examples. The below will create a selector for a coin and the Bot ID that is used to trade that coin. The names like 'BIN:GMTPERP - osakr' are entirely my making, they act as a Key (for a key/value pair):

symbol_choser = input.string(title='Ticker symbol', defval='BTC-PERP - aktqw', options=[FTX_Multi, 'FTX:MOVE Single - pdikr', 'BIN:GMTPERP - osakr', 'BIN:GMTPERP - rkwif', 'BTC-PERP - aktqw', 'BTC-PERP - ikrtl', 'BTC-PERP - cbdwe', 'BTC-PERP', 'BAL-PERP', 'RUNE-PERP', 'Paper Multi - fjeur', 'Paper Single - ruafh'], group = 'Bot settings')

exchange_symbol = switch symbol_choser // if you use Single Pair bots on 3Commas, the Value should be an empty string
    'BIN:GMTPERP - osakr' => 'USDT_GMTUSDT'
    'BTC-PERP - cbdwe' => 'USD_BTC-PERP'
    'Paper Multi - fjeur' => 'USDT_ADADOWN'

bot_id = switch symbol_choser
    'BIN:GMTPERP - osakr' => '8941983'
    'BTC-PERP - cbdwe' => '8669136'
    'Paper Multi - fjeur' => '8246237'

And now you can combine the above parts into two Alerts, for starting/stopping the bot:

alertMessage_Enter = '{"message_type": "bot",  "bot_id": ' + bot_id + ',  "email_token": "12345678-4321-abcd-xyzq-132435465768",  "delay_seconds": 0,  "pair": "' + exchange_symbol + '"}'
alertMessage_Exit = '{"action": "close_at_market_price", "message_type": "bot",  "bot_id": ' + bot_id + ',  "email_token": "12345678-4321-abcd-xyzq-132435465768",  "delay_seconds": 0,  "pair": "' + exchange_symbol + '"}'

exchange_symbol is the proper exchange symbol you need to provide to your bot, you can get help on the 3Commas' bot page (they have pre-crafted the HTTP requests you need to use for certain actions).

bot_id is the ID of your Bot, that is straightforward.

The above solution does not handle Single coin bots, their trigger message has a different structure.

Whenever you can, use Multi coin bots as they can act as a Single bot with two exception:

  • if you have a long spanning strategy and when you start a bot, you should be already in a trade, you can manually start a Single bot, but you cannot start a Multi coin bot (as there is no way to provide the coin info on which to start the trade)
  • if you are trading a derivative like FTX's MOVE contracts and your script is attached to the underlying BTC Futures. MOVE contracts changes name every day (the date is in their name, like: BTC-MOVE-0523) so you would need delete an alert, update and reapply the alert every day, etc. Instead, if your script is on the BTC-PERP then you can use a Single coin bot which does not expect a coin name in the alert message so it will start/stop the Bot on whatever coin it is connected to, then you need to change the coin name every day only in the Bot settings and never touch the Alert.

To summarize on your questions:

  1. Do not include chart type in code (that is not even an embeddable data), just apply your code to whatever chart you want to use. Hint: never use Heikin-Ashi for trading. You can, but you will pay for it dearly (everyone tries, even against warnings, no worries)

  2. Set up them one-by-one, so you can backtest them

  3. No, set the timeframe on the chart. Later, when you will be more experienced you will be able to abstract the current timeframe (whatever it is) away and write code that is timeframe-agnostic. But that's hard and make your code less readable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文