Skip to content

Instantly share code, notes, and snippets.

@tranzium
Last active November 13, 2023 19:33
Show Gist options
  • Save tranzium/34727307c823dfa75e49 to your computer and use it in GitHub Desktop.
Save tranzium/34727307c823dfa75e49 to your computer and use it in GitHub Desktop.
TradingView can now become automated trading.
---------- Usage
The syntax created by these parameters is placed in an alert's description on TradingView
to be utilized by Autoview, a Chrome Extension.
Autoview: https://chrome.google.com/webstore/detail/autoview/okdhadoplaoehmeldlpakhpekjcpljmb
> Website: https://autoview.with.pink
> Help: https://use.autoview.with.pink
> Discord: https://discordapp.com/invite/BFz8VPn
TradingView: https://tradingview.go2cloud.org/aff_c?offer_id=2&aff_id=1187
---------- Syntax
<letter>=<value>
<letter>=<value> <letter>=<value>...
---------- Parameters
Alias ? type default values
account a string * Anything (excluding special characters)
book b string <all> buy, long, sell, short
cancel/close c string n/a order, position
> maximum cm decimal <all> #, min#-max#, %, min%-max%
> max. order cmo string oldest newest, oldest, lowest, highest, smallest, biggest, random
disabled d boolean 0 0, 1
leverage l integer <all> >= 0
price p decimal 0 #, min#-max#, %, min%-max%
quantity q decimal 100% #, min#-max#, %, min%-max%
shared boolean 0 0, 1
stoploss sl integer n/a #, min#-max#, %, min%-max%
order type t string limit limit, market, open, close, fok, ioc, post
take profit tp integer n/a #, min#-max#, %, min%-max%
yield y string balance balance, equity
-- Override
exchange e string <symbol> 1BROKER, OKCOIN
symbol s string <symbol> BTCCNY, GBPNZD, LTCUSD3M, ...
---------- Examples
-- Place a buy order of 5 quantity (market price)
b=buy q=5 t=market
-- Place a short at an undercut of $0.05
b=short p=-0.05 q=1
-- Place a long of 1-10 contracts, between the top price and an undercut of $1-2
b=long p=1-2 q=1-10
---------- Notes
PERCENTAGES: Will automatically be converted to a decimal (i.e. / 100).
e.g. 20% = 0.2
e.g. 115% = 1.15
PRICE: When using percentages, the calculation will be based directly off the top value.
e.g. $300 * 50% = $150
e.g. undercut @ p=95%: $300 * 0.95 = $285
e.g. overcut @ p=105%: $300 * 1.05 = $315
ORDER TYPE: [limit, market] apply to both opening orders and closing positions.
[close] applies to position closing orders.
[open] applies to canceling open orders.
[fok] Fill Or Kill orders will either completely fill or be aborted.
[ioc] Immediate Or Cancel orders can be partially or completely filled, but any remaining portion is cancelled.
[post] If any part of the order would have executed, it will be cancelled instead.
e.g. Cancel all open orders: c=order t=open
e.g. Cancel all position closing orders: c=order t=close
e.g. Cancel all orders: c=order
SYMBOL: Until more Forex exchanges are implemented, FX symbols will default to 1Broker.
YIELD: [balance] will use your available balance in calculations
[equity] will use your entire account balance in calculations
-- Using [equity] may cause orders to fail due to calculated contract quantity.
@CryptoRox
Copy link

Make sure to click on options under the extension on the chrome -> extensions page to connect your OKcoin account.
http://prntscr.com/86blq1

@CryptoRox
Copy link

Open 10% of available balance x20 long
*e=okcoin *s=btcusd3m b=long l=20 p=0 q=10%

Open 10 contracts x10 short
*e=okcoin *s=btcusd3m b=short l=10 p=0 q=10

Cancel all x20 long open orders
*e=okcoin *s=btcusd3m c=order b=long l=20

Cancel x20 short open orders
*e=okcoin *s=btcusd3m c=order b=short l=10

Close x20 long position at market
*e=okcoin *s=btcusd3m c=position b=long l=20 q=100% t=market

Close half x10 short position at market
*e=okcoin *s=btcusd3m c=position b=short l=20 q=50% t=market

In a single alert you can open longs, cancel all open orders ( shorts and longs), close shorts.

*e=okcoin *s=btcusd3m b=long l=20 p=0 q=10%
*e=okcoin *s=btcusd3m c=order l=20
*e=okcoin *s=btcusd3m c=position b=short l=20 q=100% t=market

*optional

@Johnster1
Copy link

Avoid using "market" on OkCoin. They don't get filled sometimes.
A "market" order via the API, doesn't actually sell/buy into the books, just the top bid/ask.
I think it's a flaw in their API implementation. How this always works:
Use the default (no need to use t=limit) together the p= for better results.

example:
Close half x10 short position at market
e=okcoin s=btcusd3m c=position b=short l=10 q=50% *p=5

*5 ($5) is the maximum you can use. I took the example from @fayoling comment.
(Did you notice there are typo's in there :-) )


Here is a set of working commands I used for TESTING/DeBugging:
Some stuff can be left out, as it is the default.
The examples generate "constructed/forced" market orders only.
You can use q=1% if you have more than 100 contracts available on 10x ;-)

SHORT, close all possible still open long orders, close all long positions, open a short position.

Weekly

?=SHORT
e=okcoin s=btcusd1w c=order b=long
e=okcoin s=btcusd1w c=position q=100% b=long p=-5
e=okcoin s=btcusd1w b=short l=10 q=2% p=5

Quarterly

?=SHORT
e=okcoin s=btcusd3m c=order b=long
e=okcoin s=btcusd3m c=position q=100% b=long p=-5
e=okcoin s=btcusd3m b=short l=10 q=2% p=5

LONG, close all possible still open short orders, close all short positions, open a long position.

Weekly

?=LONG
e=okcoin s=btcusd1w c=order b=short
e=okcoin s=btcusd1w c=position q=100% b=short p=5
e=okcoin s=btcusd1w b=long l=10 q=2% p=5

Quarterly

?=LONG
e=okcoin s=btcusd3m c=order b=short
e=okcoin s=btcusd3m c=position q=100% b=short p=5
e=okcoin s=btcusd3m b=long l=10 q=2% p=5

*Tuesday Sept 29th... the d=0/1 parameter doesn't seem to work, 0 or 1 both disable the command.
Same effect:
d=0 e=okcoin s=btcusd3m c=order b=short
d=1 e=okcoin s=btcusd3m c=order b=short

@Johnster1
Copy link

If you're worried if your alerts do fire or not, here is a tip:
Set an indicator with ultra low settings on a 1m chart. Make it so it fires every 1-3 minutes.
Leave the command box disabled (d=1) or default.
You will now see a log-entry/(pop-up, email, sound) (I use the log only) every few minutes confirming all is good.

@Johnster1
Copy link

Editing a TV Alert seems to have a problem. (It's still in Beta)

If you have your strategy mapped out 2x on a chart with different parameters, and you you want to switch your strategy by editing the alert, it doesn’t seem to pick up the new settings.
It still might fire with the old settings.
My advice, always create a new Alert.

@boxxa
Copy link

boxxa commented Nov 13, 2015

This is awesome but is there anyway to log the calls in the tab or is that just reliant on TV?

Also, does the limit/take profit only work on 1broker forex or can that be used on OKCoin too?

@edric1953
Copy link

Does your comp have to be on 24/7 I wonder ?

@speedracer1190
Copy link

Would you consider allowing access to the code for further contributions? Id like to add trailing stop loss for bittrex and also add BTC markets?
cheers,

@CBSInvest
Copy link

Hi Community,
i have a question if someone can help me here. I am using tradingview with the autoview api for my first testing periode on BITMEX TESTNET as a papertrading to test some strategies. So as i saw, if i wanna generate the alert for the Test, i am tesxting for example
ETCXBT LONG ENTRY BITMEX TESTNET
a=CBSTEST
e=bitmex s=ectxbt c=position t=market
b=buy q=1000000 t=market

ETCXBT SHORT ENTRY BITMEX TESTNET
a=CBSTEST
e=bitmex s=ectxbt c=position t=market
b=sell q=1000000 t=market

Means, i am trading long an short and the amount in USD is roughly 1000 USD !
What happens if i ma trading the same instrument with a different strategy, because of my c=position i would close an open trade of the instrument with an other strategy, how can i use different stratgies with the same instrument and not kicking out my position ?

Thank u for ur help !

@DOEResearch
Copy link

What is the syntax for an OANDA demo account long or short. I've tried:

a=* e=OANDA b=long q=10000

@agozzoo1
Copy link

Hello I'm trying to connect my own strategy to your extension on OANDA, but It doesn’t recognize the alerts issued by trading view, can you explain me how works the integration ? Do I need to have the pc on all time?

Thanks for your time!!

regrats

@agozzoo1
Copy link

What is the syntax for an OANDA demo account long or short. I've tried:

a=* e=OANDA b=long q=10000

It works?

@DavidLayneOfficial
Copy link

what if I am using coinbase pro sandbox?
Does the syntax change is the exchange name is more than one word?

@cjone003
Copy link

What is the syntax for an OANDA demo account long or short. I've tried:

a=* e=OANDA b=long q=10000

I found:

e=oandapractice for Oanda demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment