kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
https://kieran-mackle.github.io/AutoTrader/
GNU General Public License v3.0
945 stars 217 forks source link

Translation of a indicator from trading view (python) #33

Closed EliskaPolakova1 closed 1 year ago

EliskaPolakova1 commented 2 years ago

Hello. I would like to request a translation of the Chandelier Exit indicator (tradingview), settings in ATR period 1, ATR Multiplier 1.9. Thank you very much!!!

kieran-mackle commented 1 year ago

Hi @EliskaPolakova1,

Apologies for the delayed response - I have added this in commit 69b8016d9212550a45b96a3f62f353e09d67a7d8 on the development branch. I will close this issue when it is merged into main.

Please see the code below for an example on plotting the indicator.

from datetime import datetime
from autotrader import AutoData, AutoPlot, indicators

# Instantiate GetData class
get_data = AutoData(data_source="yahoo")

# Get price data for EUR/USD
instrument = 'EURUSD=X'
data = get_data.fetch(
    instrument=instrument, 
    granularity='1h', 
    start_time=datetime(2021, 1, 1), 
    end_time=datetime(2021, 3, 1),
)

# Construct indicators dictionary
chandelier = indicators.chandelier_exit(data)

indicator_dict = {
    'Chandelier long stop': {
        'type': 'over',
        'data': chandelier["longstop"],
    },
    'Chandelier short stop': {
        'type': 'over',
        'data': chandelier["shortstop"],
    }
}

# Instantiate AutoPlot and plot
ap = AutoPlot(data)
ap.plot(indicators=indicator_dict, instrument=instrument)