简体   繁体   中英

Tradingview and Pine Script: code question

I have zero experience with coding. I am using a publicly available strategy (Pine Script v2) on TradingView and I want to connect it to my 3Commas bot using TradingView's custom signals.

What I need to do is to add a comment to the line of code that calls for long or short positions so that when the alert is triggered, it communicates with my bot.

I followed an online tutorial and the docs from 3Commas. The comment arguments below is where I get stuck: I keep receiving the " no viable alternative at character '{' " error. They would be on lines 7 and 11 below:

//============ signal Generator ==================================//
period = input('720')
ch1 = security(tickerid, period, open)
ch2 = security(tickerid, period, close)
longCondition = crossover(security(tickerid, period, close),security(tickerid, period, open))
if (longCondition)
    strategy.entry("BUY", strategy.long, comment="{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0\n}")
    
shortCondition = crossunder(security(tickerid, period, close),security(tickerid, period, open))
if (shortCondition)
    strategy.entry("SELL", strategy.short, comment="{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0,\n\"action\": \"close_at_market_price\"\n}")

I would appreciate any help in fixing the code. Thank you in advance.

Use Pine v4 and alert_message parameter instead of comment .

//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)

period = input('720')
ch1 = security(syminfo.tickerid, period, open)
ch2 = security(syminfo.tickerid, period, close)

longCondition = crossover(security(syminfo.tickerid, period, close),security(syminfo.tickerid, period, open))
shortCondition = crossunder(security(syminfo.tickerid, period, close),security(syminfo.tickerid, period, open))

if (longCondition)
    strategy.entry("BUY", strategy.long, alert_message = "{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0\n}")
if (shortCondition)
    strategy.entry("SELL", strategy.short, alert_message = "{\n\"message_type\": \"bot\",\n\"bot_id\": xxxxxxx,\n\"email_token\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",\n\"delay_seconds\": 0,\n\"action\": \"close_at_market_price\"\n}")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM