Raj
Raj

Reputation: 31

Open a Market order with PineScript

I have the below script to send a market order and I am logged into my broker in tradingview but when I attach the script to the chart I do not see any positions opened in my broker. Any help is appreciated.

strategy(title="Positions", overlay=true)

// Calculate moving averages
fastSMA = sma(close, 50)
slowSMA = sma(close, 200)
price=input(title="price", defval=3205.25, minval=1)
strategy.entry(id="EL", long=true)

Thank you in advance.

Upvotes: 3

Views: 6730

Answers (2)

Ajayhere
Ajayhere

Reputation: 11

its so easy if you want to paper trading or real trade with automation and dynamic pine script with syntax then you can use NextLevelBOT platform. I share below dynamic script according to NextLevelBot Platform and now you can easily fully automation paper trading with below pine script.

if you want to know more about automation paper trading pls watch this video click here!

strategy("cci Strategy", overlay=true)
length = input( 14 )
overSold = input( 100 )
overBought = input( -100 )
_1 = input(true,"══════════ ADD Value ══════════")
// long_syntax = input("", "ADD LONG SYNTAX", input.string)
// Short_syntax = input("", "ADD SHORT SYNTAX", input.string)
ts = input("ADD SYMBOL INPUT", "TRADE SYMBOL", input.string)
exchange = input("NSE", "EXCHANGE", options=["NSE","NFO","MCX","OTHER"])
qty = input("25", "Quantity Value", input.string)

longEntry = '[{"E":"'+ exchange +'","TS":"'+ ts +'","PRICE":"' +tostring(close)+ '","CLOSE":"CLOSE","AT":"TRADINGVIEW"},{"E":"'+ exchange +'","TS":"'+ ts +'","PRICE":"' +tostring(close)+ '","Q":"'+ qty +'","TT":"BUY","AT":"TRADINGVIEW"}]'
shortEntry = '[{"E":"'+ exchange +'","TS":"'+ ts +'","PRICE":"' +tostring(close)+ '","CLOSE":"CLOSE","AT":"TRADINGVIEW"},{"E":"'+ exchange +'","TS":"'+ ts +'","PRICE":"' +tostring(close)+ '","Q":"'+ qty +'","TT":"SELL","AT":"TRADINGVIEW"}]'


price = close
vrsi = cci(price, length)
co = crossover(vrsi, overSold)
cu = crossunder(vrsi, overBought)
if (not na(vrsi))
    if (co)
        strategy.entry("RsiLE", strategy.long, alert_message=longEntry)
    if (cu)
        strategy.entry("RsiSE", strategy.short, alert_message=shortEntry)

//      plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
//      {{strategy.order.alert_message}}

makesure add this in alert message {{strategy.order.alert_message}}

Upvotes: 0

Bjorn Mistiaen
Bjorn Mistiaen

Reputation: 6905

This is currently not possible in TradingView.
The brokers with integration to TradingView can only be used for manual trading.
Exerpt from How to autotrade using Pine Script strategies:

Strategy trading is limited to the backtesting mode only. Automated strategy trading with a brokerage account is not available on TradingView yet. We are considering implementing this in the future.

There is a workaround though, but you'll need a 3rd party execution engine:

From PineCoders.com - Can my strategy generate orders through exchanges or brokers? :

No, because:

  1. The brokers with integration to TradingView can only be used for manual trading.
  2. The only possible connection between Pine scripts and brokers/exchanges is via alerts, through third-party execution engines, and only Pine studies can generate alerts.

If you have a Pine strategy and want to automate it to place orders on markets, you will have to:

  • Decide which third-party execution you will be using, as this will impact the design of your solution.
  • Create an indicator (a.k.a. study) from your strategy.
  • Insert alertcondition() calls in your indicator using your buy/sell conditions.
  • Create alerts from those alertcondition() calls in your study using TV’s alert creation feature from charts (ALT-A).
  • Link those alerts to a third-party app/bot which will in turn relay orders to exchanges or brokers.

Points to consider

  • If your strategy uses logic depending on Pine’s strategy.*() calls which is implemented by the broker emulator used in TV backtesting, that logic will need to be handled in the conversion process, either through custom Pine code in your study or through delegation of the logic to the execution engine, if it supports those features, in which case you will need to use the appropriate syntax in your alert messages so the particular execution engine you are using understands how to execute your orders.
  • Note that if you must convert your trade management logic into explicit Pine code in your study, this may require expertise you do not possess, and may also introduce behavioral deltas between your strategy and your study.
  • Unless you have forward-tested your strategy on the realtime bar, you will be running your strategy in a new, very different environment as a study. Because of the inevitable differences between the simulated world of backtests on historical data and realtime markets, your strategy’s behavior may turn out to be vastly different from what it was on historical bars.
  • The number of symbol/timeframe pairs you want your system to run on, multiplied by the number of alerts you need for each pair (one for buy order, one for sell orders, for example) will constitute the total number of alerts you will need. Your type of TV account must allow for that quantity of alerts.

The complexity of the conversion process between strategies and studies is the reason why we have developed our Backtesting and Trading Engine. Be sure to have a look at it.

Upvotes: 3

Related Questions