-1

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.

David Buik
  • 522
  • 1
  • 8
  • 31

1 Answers1

0

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.

karatedog
  • 2,508
  • 19
  • 29
  • Thanks a lot for the informative answer I've learned new things from you. I'll apply that for sure as stated. I'm wondering what's wrong with HA candles while it gives you a very high-Profit Factor and Percentage compared to Normal Ones. For example the Profit Factor on HA is 4 while on Candles is less than 2 high Profitable Precentage and low Markdown. Any article you recommend to explain the process of HA candles. – David Buik May 24 '22 at 10:51
  • Excuse me also I'm looking for the right structure of Leverage. I saw many codes however they are using Volume and SMA or other Indicators not sure why. I'm wanna understand how leverage exactly works to implement it in the backtesting – David Buik May 24 '22 at 10:53
  • @DavidBuik HA candles are not what really is happening with the price, it is not the reality. Take this test: On BTCUSD change to HA, find a 'good looking' price increase where price has moved up from the bottom, draw an Info Line in from the bottom to the top, and it will show you how much percentage the price has moved (this is a lie, but let's continue). Now switch back to normal candles, and finetune the endpoints of the above Info Line, to match the Open price on that candle you put them on. You usually end up with 0 percent. Now there are times when this can work, but that is very rare. – karatedog May 25 '22 at 08:25
  • @DavidBuik I don't want to sound blunt but if you are thinking on working with HA candles, you are not experienced yet to even think about leverage. Leverage is a larger topic in itself, please take time to read about it/watch videos. Leverage is a good tool, but it can quickly drain all of your money. You will realize with time that successful traders don't really go for per-deal profit but they go for consistency as it is better to have 3-5% per every month with minimal losses than 20% one month, and -15% next month) – karatedog May 25 '22 at 08:31