TradingView
Drun30
7 jan 2021 22:46

Momentum Strategy (BTC/USDT; 30m) - STOCH RSI (with source code) 

Bitcoin / TetherUSBinance

Beskrivning

Here's a strategy for low time frames (30min suggested) for BTC , based on momentum Analysis using Stochastic RSI
By default the strategy will use the 50% of the specified capital for each trade; if "Gamble Sizing" is enabled, it will add the specified amount of capital (25% by default, until reaching the 100% limit or lower) for the next trade after having detected a loss in the previous trade; if the next trade is successful, the size for the next trade comes back to 50%

• Trend Filter LONG: If the fast exponential moving average is UNDER the slow exponential moving average , it won't open LONG positions

• Trend Filter SHORT: If the fast exponential moving average is ABOVE the slow exponential moving average , it won't open SHORT positions

• Bars delay: the strategy will wait the specified amount of bars before closing the current position; the counter is triggered as soon as the closing trade condition is verified

BY MAKING USE OF THIS STRATEGY, YOU ACKNOWLEDGE AND AGREE THAT: (1) YOU ARE AWARE OF THE RISKS ASSOCIATED WITH TRANSACTIONS OF DIGITAL CURRENCIES AND THEIR DERIVATIVES; (2) YOU SHALL ASSUME ALL RISKS RELATED TO THE USE OF THIS STRATEGY AND TRANSACTIONS OF DIGITAL CURRENCIES AND THEIR DERIVATIVES; AND (3) I SHALL NOT BE LIABLE FOR ANY SUCH RISKS OR ADVERSE OUTCOMES.

SOURCE CODE BELOW

Versionsinformation

EDIT:
Now you can integrate easily this strategy with your tv-hub account by changing values from line 8 to 18; these variables will be submitted by string-interpolation in the JSON messages sent to the webhook.
Please notice that TV-HUB integration will need the possibility of sending webhook messages, so it is supposed that you have a PRO TradingView account at least.

WARNING: The strategy is suited for taking a PERCENTAGE of the AVAILABLE balance you set. So, if you put on line 8 "BTCUSDT" and on line 9 "50", if the condition for opening a long position is triggered, the bot would spend the 50% of the USDT PRESENT ON YOUR EXCHANGE WALLET for buying the equivalent of BTC at the given price, indipendently from the initial capital you've set inside the strategy. So, for example, if you have 5000 USDT available in your SPOT wallet on Binance (or Bitmex or Bybit), in the previous case the bot will open a long position using 2500 USDT. If you want the bot to run with the full amount of USDT you have, just put "100" at line 9

What you need to do is

(0) Change the values of the specified lines submitting the values associated with the matching keys you see on the JSON generated by Tv-hub

(1) Set the strategy on the desired timeframe you want it to run;

(2) Create a new alert by clicking on the clock symbol present in the "Strategy tester" panel;

(3) Click on the dropdown associated with "Condition" on the alert-panel that would have popped up and then select "Momentum Strategy";

(4) Enable the checkbox called "Webhook URL" and type "alerts.tv-hub.org" in the input field (without ")

(5) Type the "Alert name" you want (that's the name for saving the alert, you can also type "Vires in Numeris" or whatever

(6) Type on "Message" "{{strategy.order.alert_message}}" (without "). In this way the message sent to the webhook url you've set at the fourth point would be the JSON associated with the triggered condition (open long, open short or close position)

(7) Click on "Create" and cross your fingers

PLEASE, BE AWARE THAT THIS TRADING STRATEGY DOES NOT GUARANTEE ANY KIND OF SUCCESS IN ADVANCE. YOU ARE THE ONE AND ONLY RESPONSIBLE OF YOUR OWN DECISIONS, I DON'T TAKE ANY RESPONSIBILITY ASSOCIATED WITH THEM. IF YOU RUN THIS STRATEGY YOU ACCEPT THE POSSIBILITY OF LOOSING MONEY, ALL OF MY PUBBLICATIONS ARE SUPPOSED TO BE JUST FOR EDUCATIONAL PURPOSES.
IT IS AT YOUR OWN RISK WHETHER TO USE IT OR NOT

Buy me a beer! (ETH) → 0x2a2595D95a54330BeB848F7BFAab1B4f1569D635
Kommentarer
antoniodapc
Ciao Federico,
posso farti una domanda ?
Per caso è già pronto per dialogare con Tv-Hub ?

Saluti Antonio
Drun30
@antoniodapc, ciao Antonio! Per renderlo compatibile con TV-HUB è necessario inserire il JSON alle righe 83, 84 e 153 facendo però una corretta interpolazione di stringhe con le variabili. Ho voluto lasciare vuote queste righe in modo tale che l'utente possa inserire il messaggio di webhook che preferisce. Se però è una cosa richiesta anche da altri utenti magari valuto se fare questa integrazione! Buona Domenica
M-Carlo
@Drun30, Ciao, sarebbe fondamentale per chi come me vorrebbe impostare una size che cambia ad ogni trade... vorrei tanto poter gestire il rischio usando il fixed fractional method!! Non ho problemi a calcolare la variabile "quantita" ma propio non riesco a passarla allo script creato su tv-hub... Gentilmente un aiuto? grazie
uroDH
ciao anch'io ho una domanda che riguarda tv-hub... nello script ci sono dei valori nella riga 6,8,9,10, bisogna modificarli e farli coincidere con ciò che inserisco in tv-hub?o i valori ad esempio del capitale lo prende da ciò che imposto su tv-hub? probabilmente ci sono anche altre parti che forse mi predo perché non riesco a farlo funzionare collegandolo a tv-hub un'integrazione su questa funzione sarebbe super utile. grazie mille!
Drun30
@uroDH, ciao! Si, TV-HUB ti genera un JSON testuale contenente le informazioni di prezzo, quantità, stop loss e take profit che desideri. Il principio sarebbe inserire questa stringa all'interno del codice e, attraverso l'interpolazione testuale, inserire le variabili che desideri all'interno del programma. Le variabili da inserire sono però un po sparse all'interno del codice (ad esempio per stop loss e take profit sono alle righe 77 e 78), quindi al limite valuto se fare una versione del codice tv-hub compliant riorganizzando un po il tutto; a breve avrò un esame ma appena mi libero ci rimetto le mani!
uroDH
@Drun30, grazie mille!!!
sphawk_cork
@Drun30, in bocca al lupo x l'esame! XD
sphawk_cork
anche io volevo integrarlo con tv-hub.
ho inserito i 2 JSON alle righe indicate ma il json per il close?
Drun30
@sphawk_cork, ciao! Il JSON per la chiusura va inserito alla riga 84 associato alla variabile "JSON_chiusura" ma come scrivevo nell'altro commento è necessario fare una buona string interpolation con le variabili del codice per far sì che gli ordini si aprano e si chiudano nella maniera corretta. Se ricevo altri feedback in merito all'esigenza di questa funzione vedo di integrarla. Buona Serata!
Mer