Tradingview widget - customize simple moving average and Exponential moving average lenght

Viewed 3129

I'm trying to add "Advanced Real Time chart" widget from tradinview. I'm able to add indicator Exponential moving average and Simple moving average. But it takes default 9 days length. I want to change that.

I tried as below but it does not work. Could somebody please help. Thanks a lot in advance.

widget = new TradingView.widget(
    {
        "width": 1200,
        "height": 700,
        "symbol": "NSE:DRREDDY",
        "interval": "D",
        "timezone": "Asia/Kolkata",
        "theme": "Dark",
        "style": "1",
        "locale": "in",
        "toolbar_bg": "#f1f3f6",
        "enable_publishing": false,
        "hide_side_toolbar": false,
        "allow_symbol_change": true,
        "details": true,
        "studies_overrides": {
            "moving average exponential.length": 20
        },
        "studies": [
            "MAExp@tv-basicstudies"
        ],

        "container_id": "tradingview_f6d89"
    }
2 Answers

Here's the way to do it :

"studies": [
   {
     "id": "MAExp@tv-basicstudies",
     "version": 60,
     "inputs": {
       "length": 20
     }
   },
   ...

The code above takes EMA 20 ticks back on the current time frame (TF), so if you want days, you need to set TF to days and change this value to 9 (or equivalently, set TF to hours and set EMA to 24*9).

Related