freqtrade_origin/en/2019.6/strategy-customization/index.html

1565 lines
66 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="prev" href="../configuration/">
<link rel="next" href="../stoploss/">
<link rel="icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.0, mkdocs-material-9.5.30">
<title>Strategy Customization - Freqtrade</title>
<link rel="stylesheet" href="../assets/stylesheets/main.3cba04c6.min.css">
<link rel="stylesheet" href="../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="blue-grey" data-md-color-accent="tear">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#optimization" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<div data-md-color-scheme="default" data-md-component="outdated" hidden>
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="Freqtrade" class="md-header__button md-logo" aria-label="Freqtrade" data-md-component="logo">
<img src="../images/logo.png" alt="logo">
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Freqtrade
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Strategy Customization
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="Freqtrade" class="md-nav__button md-logo" aria-label="Freqtrade" data-md-component="logo">
<img src="../images/logo.png" alt="logo">
</a>
Freqtrade
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href=".." class="md-nav__link">
<span class="md-ellipsis">
About
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../installation/" class="md-nav__link">
<span class="md-ellipsis">
Installation
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../docker/" class="md-nav__link">
<span class="md-ellipsis">
Installation Docker
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../configuration/" class="md-nav__link">
<span class="md-ellipsis">
Configuration
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Strategy Customization
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Strategy Customization
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#install-a-custom-strategy-file" class="md-nav__link">
<span class="md-ellipsis">
Install a custom strategy file
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#change-your-strategy" class="md-nav__link">
<span class="md-ellipsis">
Change your strategy
</span>
</a>
<nav class="md-nav" aria-label="Change your strategy">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#anatomy-of-a-strategy" class="md-nav__link">
<span class="md-ellipsis">
Anatomy of a strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#customize-indicators" class="md-nav__link">
<span class="md-ellipsis">
Customize Indicators
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#buy-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Buy signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#sell-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Sell signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#minimal-roi" class="md-nav__link">
<span class="md-ellipsis">
Minimal ROI
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss" class="md-nav__link">
<span class="md-ellipsis">
Stoploss
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#ticker-interval" class="md-nav__link">
<span class="md-ellipsis">
Ticker interval
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#metadata-dict" class="md-nav__link">
<span class="md-ellipsis">
Metadata dict
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#storing-information" class="md-nav__link">
<span class="md-ellipsis">
Storing information
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#additional-data-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Additional data (DataProvider)
</span>
</a>
<nav class="md-nav" aria-label="Additional data (DataProvider)">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Possible options for DataProvider
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#ohlcv-historic_ohlcv" class="md-nav__link">
<span class="md-ellipsis">
ohlcv / historic_ohlcv
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#orderbook" class="md-nav__link">
<span class="md-ellipsis">
Orderbook
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#available-pairs" class="md-nav__link">
<span class="md-ellipsis">
Available Pairs
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#get-data-for-non-tradeable-pairs" class="md-nav__link">
<span class="md-ellipsis">
Get data for non-tradeable pairs
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-wallets" class="md-nav__link">
<span class="md-ellipsis">
Additional data - Wallets
</span>
</a>
<nav class="md-nav" aria-label="Additional data - Wallets">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-wallets" class="md-nav__link">
<span class="md-ellipsis">
Possible options for Wallets
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#print-created-dataframe" class="md-nav__link">
<span class="md-ellipsis">
Print created dataframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#where-is-the-default-strategy" class="md-nav__link">
<span class="md-ellipsis">
Where is the default strategy?
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#specify-custom-strategy-location" class="md-nav__link">
<span class="md-ellipsis">
Specify custom strategy location
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#further-strategy-ideas" class="md-nav__link">
<span class="md-ellipsis">
Further strategy ideas
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#next-step" class="md-nav__link">
<span class="md-ellipsis">
Next step
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../stoploss/" class="md-nav__link">
<span class="md-ellipsis">
Stoploss
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../bot-usage/" class="md-nav__link">
<span class="md-ellipsis">
Start the bot
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_8" >
<label class="md-nav__link" for="__nav_8" id="__nav_8_label" tabindex="0">
<span class="md-ellipsis">
Control the bot
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_8_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_8">
<span class="md-nav__icon md-icon"></span>
Control the bot
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../telegram-usage/" class="md-nav__link">
<span class="md-ellipsis">
Telegram
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../webhook-config/" class="md-nav__link">
<span class="md-ellipsis">
Web Hook
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../rest-api/" class="md-nav__link">
<span class="md-ellipsis">
REST API
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../backtesting/" class="md-nav__link">
<span class="md-ellipsis">
Backtesting
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../hyperopt/" class="md-nav__link">
<span class="md-ellipsis">
Hyperopt
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../edge/" class="md-nav__link">
<span class="md-ellipsis">
Edge positioning
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../plotting/" class="md-nav__link">
<span class="md-ellipsis">
Plotting
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../deprecated/" class="md-nav__link">
<span class="md-ellipsis">
Deprecated features
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../faq/" class="md-nav__link">
<span class="md-ellipsis">
FAQ
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../data-analysis/" class="md-nav__link">
<span class="md-ellipsis">
Data Analysis
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../sql_cheatsheet/" class="md-nav__link">
<span class="md-ellipsis">
SQL Cheatsheet
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../sandbox-testing/" class="md-nav__link">
<span class="md-ellipsis">
Sandbox testing
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../developer/" class="md-nav__link">
<span class="md-ellipsis">
Contributors guide
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#install-a-custom-strategy-file" class="md-nav__link">
<span class="md-ellipsis">
Install a custom strategy file
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#change-your-strategy" class="md-nav__link">
<span class="md-ellipsis">
Change your strategy
</span>
</a>
<nav class="md-nav" aria-label="Change your strategy">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#anatomy-of-a-strategy" class="md-nav__link">
<span class="md-ellipsis">
Anatomy of a strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#customize-indicators" class="md-nav__link">
<span class="md-ellipsis">
Customize Indicators
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#buy-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Buy signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#sell-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Sell signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#minimal-roi" class="md-nav__link">
<span class="md-ellipsis">
Minimal ROI
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss" class="md-nav__link">
<span class="md-ellipsis">
Stoploss
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#ticker-interval" class="md-nav__link">
<span class="md-ellipsis">
Ticker interval
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#metadata-dict" class="md-nav__link">
<span class="md-ellipsis">
Metadata dict
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#storing-information" class="md-nav__link">
<span class="md-ellipsis">
Storing information
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#additional-data-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Additional data (DataProvider)
</span>
</a>
<nav class="md-nav" aria-label="Additional data (DataProvider)">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Possible options for DataProvider
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#ohlcv-historic_ohlcv" class="md-nav__link">
<span class="md-ellipsis">
ohlcv / historic_ohlcv
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#orderbook" class="md-nav__link">
<span class="md-ellipsis">
Orderbook
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#available-pairs" class="md-nav__link">
<span class="md-ellipsis">
Available Pairs
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#get-data-for-non-tradeable-pairs" class="md-nav__link">
<span class="md-ellipsis">
Get data for non-tradeable pairs
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-wallets" class="md-nav__link">
<span class="md-ellipsis">
Additional data - Wallets
</span>
</a>
<nav class="md-nav" aria-label="Additional data - Wallets">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-wallets" class="md-nav__link">
<span class="md-ellipsis">
Possible options for Wallets
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#print-created-dataframe" class="md-nav__link">
<span class="md-ellipsis">
Print created dataframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#where-is-the-default-strategy" class="md-nav__link">
<span class="md-ellipsis">
Where is the default strategy?
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#specify-custom-strategy-location" class="md-nav__link">
<span class="md-ellipsis">
Specify custom strategy location
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#further-strategy-ideas" class="md-nav__link">
<span class="md-ellipsis">
Further strategy ideas
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#next-step" class="md-nav__link">
<span class="md-ellipsis">
Next step
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="optimization">Optimization<a class="headerlink" href="#optimization" title="Permanent link">&para;</a></h1>
<p>This page explains where to customize your strategies, and add new
indicators.</p>
<h2 id="install-a-custom-strategy-file">Install a custom strategy file<a class="headerlink" href="#install-a-custom-strategy-file" title="Permanent link">&para;</a></h2>
<p>This is very simple. Copy paste your strategy file into the folder
<code>user_data/strategies</code>.</p>
<p>Let assume you have a class called <code>AwesomeStrategy</code> in the file <code>awesome-strategy.py</code>:</p>
<ol>
<li>Move your file into <code>user_data/strategies</code> (you should have <code>user_data/strategies/awesome-strategy.py</code></li>
<li>Start the bot with the param <code>--strategy AwesomeStrategy</code> (the parameter is the class name)</li>
</ol>
<div class="highlight"><pre><span></span><code>python3<span class="w"> </span>freqtrade<span class="w"> </span>--strategy<span class="w"> </span>AwesomeStrategy
</code></pre></div>
<h2 id="change-your-strategy">Change your strategy<a class="headerlink" href="#change-your-strategy" title="Permanent link">&para;</a></h2>
<p>The bot includes a default strategy file. However, we recommend you to
use your own file to not have to lose your parameters every time the default
strategy file will be updated on Github. Put your custom strategy file
into the folder <code>user_data/strategies</code>.</p>
<p>Best copy the test-strategy and modify this copy to avoid having bot-updates override your changes.
<code>cp user_data/strategies/test_strategy.py user_data/strategies/awesome-strategy.py</code></p>
<h3 id="anatomy-of-a-strategy">Anatomy of a strategy<a class="headerlink" href="#anatomy-of-a-strategy" title="Permanent link">&para;</a></h3>
<p>A strategy file contains all the information needed to build a good strategy:</p>
<ul>
<li>Indicators</li>
<li>Buy strategy rules</li>
<li>Sell strategy rules</li>
<li>Minimal ROI recommended</li>
<li>Stoploss strongly recommended</li>
</ul>
<p>The bot also include a sample strategy called <code>TestStrategy</code> you can update: <code>user_data/strategies/test_strategy.py</code>.
You can test it with the parameter: <code>--strategy TestStrategy</code></p>
<div class="highlight"><pre><span></span><code>python3<span class="w"> </span>freqtrade<span class="w"> </span>--strategy<span class="w"> </span>AwesomeStrategy
</code></pre></div>
<p><strong>For the following section we will use the <a href="https://github.com/freqtrade/freqtrade/blob/develop/user_data/strategies/test_strategy.py">user_data/strategies/test_strategy.py</a>
file as reference.</strong></p>
<div class="admonition note strategies and backtesting">
<p class="admonition-title">Note</p>
<p>To avoid problems and unexpected differences between Backtesting and dry/live modes, please be aware
that during backtesting the full time-interval is passed to the <code>populate_*()</code> methods at once.
It is therefore best to use vectorized operations (across the whole dataframe, not loops) and
avoid index referencing (<code>df.iloc[-1]</code>), but instead use <code>df.shift()</code> to get to the previous candle.</p>
</div>
<div class="admonition warning using future data">
<p class="admonition-title">Warning</p>
<p>Since backtesting passes the full time interval to the <code>populate_*()</code> methods, the strategy author
needs to take care to avoid having the strategy utilize data from the future.
Samples for usage of future data are <code>dataframe.shift(-1)</code>, <code>dataframe.resample("1h")</code> (this uses the left border of the interval, so moves data from an hour to the start of the hour).
They all use data which is not available during regular operations, so these strategies will perform well during backtesting, but will fail / perform badly in dry-runs.</p>
</div>
<h3 id="customize-indicators">Customize Indicators<a class="headerlink" href="#customize-indicators" title="Permanent link">&para;</a></h3>
<p>Buy and sell strategies need indicators. You can add more indicators by extending the list contained in the method <code>populate_indicators()</code> from your strategy file.</p>
<p>You should only add the indicators used in either <code>populate_buy_trend()</code>, <code>populate_sell_trend()</code>, or to populate another indicator, otherwise performance may suffer.</p>
<p>It's important to always return the dataframe without removing/modifying the columns <code>"open", "high", "low", "close", "volume"</code>, otherwise these fields would contain something unexpected.</p>
<p>Sample:</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_indicators</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataframe</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">metadata</span><span class="p">:</span> <span class="nb">dict</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DataFrame</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Adds several different TA indicators to the given DataFrame</span>
<span class="sd"> Performance Note: For the best performance be frugal on the number of indicators</span>
<span class="sd"> you are using. Let uncomment only the indicator you are using in your strategies</span>
<span class="sd"> or your hyperopt configuration, otherwise you will waste your memory and CPU usage.</span>
<span class="sd"> :param dataframe: Raw data from the exchange and parsed by parse_ticker_dataframe()</span>
<span class="sd"> :param metadata: Additional information, like the currently traded pair</span>
<span class="sd"> :return: a Dataframe with all mandatory indicators for the strategies</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;sar&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">SAR</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;adx&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">ADX</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">stoch</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">STOCHF</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;fastd&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">stoch</span><span class="p">[</span><span class="s1">&#39;fastd&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;fastk&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">stoch</span><span class="p">[</span><span class="s1">&#39;fastk&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;blower&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">BBANDS</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">nbdevup</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">nbdevdn</span><span class="o">=</span><span class="mi">2</span><span class="p">)[</span><span class="s1">&#39;lowerband&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;sma&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">SMA</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">timeperiod</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;tema&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">TEMA</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">timeperiod</span><span class="o">=</span><span class="mi">9</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;mfi&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">MFI</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;rsi&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">RSI</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;ema5&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">EMA</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">timeperiod</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;ema10&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">EMA</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">timeperiod</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;ema50&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">EMA</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">timeperiod</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;ema100&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">EMA</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">timeperiod</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;ao&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">awesome_oscillator</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">macd</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">MACD</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;macd&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">macd</span><span class="p">[</span><span class="s1">&#39;macd&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;macdsignal&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">macd</span><span class="p">[</span><span class="s1">&#39;macdsignal&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;macdhist&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">macd</span><span class="p">[</span><span class="s1">&#39;macdhist&#39;</span><span class="p">]</span>
<span class="n">hilbert</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">HT_SINE</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;htsine&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">hilbert</span><span class="p">[</span><span class="s1">&#39;sine&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;htleadsine&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">hilbert</span><span class="p">[</span><span class="s1">&#39;leadsine&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;plus_dm&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">PLUS_DM</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;plus_di&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">PLUS_DI</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;minus_dm&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">MINUS_DM</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;minus_di&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">MINUS_DI</span><span class="p">(</span><span class="n">dataframe</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
<div class="admonition note">
<p class="admonition-title">Want more indicator examples?</p>
<p>Look into the <a href="https://github.com/freqtrade/freqtrade/blob/develop/user_data/strategies/test_strategy.py">user_data/strategies/test_strategy.py</a>.<br/>
Then uncomment indicators you need.</p>
</div>
<h3 id="buy-signal-rules">Buy signal rules<a class="headerlink" href="#buy-signal-rules" title="Permanent link">&para;</a></h3>
<p>Edit the method <code>populate_buy_trend()</code> in your strategy file to update your buy strategy.</p>
<p>It's important to always return the dataframe without removing/modifying the columns <code>"open", "high", "low", "close", "volume"</code>, otherwise these fields would contain something unexpected.</p>
<p>This will method will also define a new column, <code>"buy"</code>, which needs to contain 1 for buys, and 0 for "no action".</p>
<p>Sample from <code>user_data/strategies/test_strategy.py</code>:</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_buy_trend</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataframe</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">metadata</span><span class="p">:</span> <span class="nb">dict</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DataFrame</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Based on TA indicators, populates the buy signal for the given dataframe</span>
<span class="sd"> :param dataframe: DataFrame populated with indicators</span>
<span class="sd"> :param metadata: Additional information, like the currently traded pair</span>
<span class="sd"> :return: DataFrame with buy column</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">dataframe</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span>
<span class="p">(</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;adx&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">30</span><span class="p">)</span> <span class="o">&amp;</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;tema&#39;</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;bb_middleband&#39;</span><span class="p">])</span> <span class="o">&amp;</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;tema&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;tema&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="p">),</span>
<span class="s1">&#39;buy&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
<h3 id="sell-signal-rules">Sell signal rules<a class="headerlink" href="#sell-signal-rules" title="Permanent link">&para;</a></h3>
<p>Edit the method <code>populate_sell_trend()</code> into your strategy file to update your sell strategy.
Please note that the sell-signal is only used if <code>use_sell_signal</code> is set to true in the configuration.</p>
<p>It's important to always return the dataframe without removing/modifying the columns <code>"open", "high", "low", "close", "volume"</code>, otherwise these fields would contain something unexpected.</p>
<p>This will method will also define a new column, <code>"sell"</code>, which needs to contain 1 for sells, and 0 for "no action".</p>
<p>Sample from <code>user_data/strategies/test_strategy.py</code>:</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_sell_trend</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataframe</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">metadata</span><span class="p">:</span> <span class="nb">dict</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DataFrame</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Based on TA indicators, populates the sell signal for the given dataframe</span>
<span class="sd"> :param dataframe: DataFrame populated with indicators</span>
<span class="sd"> :param metadata: Additional information, like the currently traded pair</span>
<span class="sd"> :return: DataFrame with buy column</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">dataframe</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span>
<span class="p">(</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;adx&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">70</span><span class="p">)</span> <span class="o">&amp;</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;tema&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;bb_middleband&#39;</span><span class="p">])</span> <span class="o">&amp;</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;tema&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;tema&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="p">),</span>
<span class="s1">&#39;sell&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
<h3 id="minimal-roi">Minimal ROI<a class="headerlink" href="#minimal-roi" title="Permanent link">&para;</a></h3>
<p>This dict defines the minimal Return On Investment (ROI) a trade should reach before selling, independent from the sell signal.</p>
<p>It is of the following format, with the dict key (left side of the colon) being the minutes passed since the trade opened, and the value (right side of the colon) being the percentage.</p>
<div class="highlight"><pre><span></span><code><span class="n">minimal_roi</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;40&quot;</span><span class="p">:</span> <span class="mf">0.0</span><span class="p">,</span>
<span class="s2">&quot;30&quot;</span><span class="p">:</span> <span class="mf">0.01</span><span class="p">,</span>
<span class="s2">&quot;20&quot;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
<span class="s2">&quot;0&quot;</span><span class="p">:</span> <span class="mf">0.04</span>
<span class="p">}</span>
</code></pre></div>
<p>The above configuration would therefore mean:</p>
<ul>
<li>Sell whenever 4% profit was reached</li>
<li>Sell when 2% profit was reached (in effect after 20 minutes)</li>
<li>Sell when 1% profit was reached (in effect after 30 minutes)</li>
<li>Sell when trade is non-loosing (in effect after 40 minutes)</li>
</ul>
<p>The calculation does include fees.</p>
<p>To disable ROI completely, set it to an insanely high number:</p>
<div class="highlight"><pre><span></span><code><span class="n">minimal_roi</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;0&quot;</span><span class="p">:</span> <span class="mi">100</span>
<span class="p">}</span>
</code></pre></div>
<p>While technically not completely disabled, this would sell once the trade reaches 10000% Profit.</p>
<h3 id="stoploss">Stoploss<a class="headerlink" href="#stoploss" title="Permanent link">&para;</a></h3>
<p>Setting a stoploss is highly recommended to protect your capital from strong moves against you.</p>
<p>Sample:</p>
<div class="highlight"><pre><span></span><code><span class="n">stoploss</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.10</span>
</code></pre></div>
<p>This would signify a stoploss of -10%.</p>
<p>For the full documentation on stoploss features, look at the dedicated <a href="../stoploss/">stoploss page</a>.</p>
<p>If your exchange supports it, it's recommended to also set <code>"stoploss_on_exchange"</code> in the order dict, so your stoploss is on the exchange and cannot be missed for network-problems (or other problems).</p>
<p>For more information on order_types please look <a href="../configuration/#understand-order_types">here</a>.</p>
<h3 id="ticker-interval">Ticker interval<a class="headerlink" href="#ticker-interval" title="Permanent link">&para;</a></h3>
<p>This is the set of candles the bot should download and use for the analysis.
Common values are <code>"1m"</code>, <code>"5m"</code>, <code>"15m"</code>, <code>"1h"</code>, however all values supported by your exchange should work.</p>
<p>Please note that the same buy/sell signals may work with one interval, but not the other.
This setting is accessible within the strategy by using <code>self.ticker_interval</code>.</p>
<h3 id="metadata-dict">Metadata dict<a class="headerlink" href="#metadata-dict" title="Permanent link">&para;</a></h3>
<p>The metadata-dict (available for <code>populate_buy_trend</code>, <code>populate_sell_trend</code>, <code>populate_indicators</code>) contains additional information.
Currently this is <code>pair</code>, which can be accessed using <code>metadata['pair']</code> - and will return a pair in the format <code>XRP/BTC</code>.</p>
<p>The Metadata-dict should not be modified and does not persist information across multiple calls.
Instead, have a look at the section <a href="#Storing-information">Storing information</a></p>
<h3 id="storing-information">Storing information<a class="headerlink" href="#storing-information" title="Permanent link">&para;</a></h3>
<p>Storing information can be accomplished by crating a new dictionary within the strategy class.</p>
<p>The name of the variable can be choosen at will, but should be prefixed with <code>cust_</code> to avoid naming collisions with predefined strategy variables.</p>
<div class="highlight"><pre><span></span><code><span class="k">class</span> <span class="nc">Awesomestrategy</span><span class="p">(</span><span class="n">IStrategy</span><span class="p">):</span>
<span class="c1"># Create custom dictionary</span>
<span class="n">cust_info</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">def</span> <span class="nf">populate_indicators</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataframe</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">metadata</span><span class="p">:</span> <span class="nb">dict</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DataFrame</span><span class="p">:</span>
<span class="c1"># Check if the entry already exists</span>
<span class="k">if</span> <span class="s2">&quot;crosstime&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cust_info</span><span class="p">[</span><span class="n">metadata</span><span class="p">[</span><span class="s2">&quot;pair&quot;</span><span class="p">]:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cust_info</span><span class="p">[</span><span class="n">metadata</span><span class="p">[</span><span class="s2">&quot;pair&quot;</span><span class="p">][</span><span class="s2">&quot;crosstime&quot;</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cust_info</span><span class="p">[</span><span class="n">metadata</span><span class="p">[</span><span class="s2">&quot;pair&quot;</span><span class="p">][</span><span class="s2">&quot;crosstime&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
</code></pre></div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
</div>
<p>The data is not persisted after a bot-restart (or config-reload). Also, the amount of data should be kept smallish (no DataFrames and such), otherwise the bot will start to consume a lot of memory and eventually run out of memory and crash.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
</div>
<p>If the data is pair-specific, make sure to use pair as one of the keys in the dictionary.</p>
<h3 id="additional-data-dataprovider">Additional data (DataProvider)<a class="headerlink" href="#additional-data-dataprovider" title="Permanent link">&para;</a></h3>
<p>The strategy provides access to the <code>DataProvider</code>. This allows you to get additional data to use in your strategy.</p>
<p>All methods return <code>None</code> in case of failure (do not raise an exception).</p>
<p>Please always check the mode of operation to select the correct method to get data (samples see below).</p>
<h4 id="possible-options-for-dataprovider">Possible options for DataProvider<a class="headerlink" href="#possible-options-for-dataprovider" title="Permanent link">&para;</a></h4>
<ul>
<li><code>available_pairs</code> - Property with tuples listing cached pairs with their intervals. (pair, interval)</li>
<li><code>ohlcv(pair, ticker_interval)</code> - Currently cached ticker data for all pairs in the whitelist, returns DataFrame or empty DataFrame</li>
<li><code>historic_ohlcv(pair, ticker_interval)</code> - Data stored on disk</li>
<li><code>runmode</code> - Property containing the current runmode.</li>
</ul>
<h4 id="ohlcv-historic_ohlcv">ohlcv / historic_ohlcv<a class="headerlink" href="#ohlcv-historic_ohlcv" title="Permanent link">&para;</a></h4>
<div class="highlight"><pre><span></span><code><span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">runmode</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;live&#39;</span><span class="p">,</span> <span class="s1">&#39;dry_run&#39;</span><span class="p">):</span>
<span class="k">if</span> <span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">stake_currency</span><span class="si">}</span><span class="s1">/BTC&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ticker_interval</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">available_pairs</span><span class="p">:</span>
<span class="n">data_eth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">ohlcv</span><span class="p">(</span><span class="n">pair</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">{self.stake_currency}</span><span class="s1">/BTC&#39;</span><span class="p">,</span>
<span class="n">ticker_interval</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ticker_interval</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Get historic ohlcv data (cached on disk).</span>
<span class="n">history_eth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">historic_ohlcv</span><span class="p">(</span><span class="n">pair</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">{self.stake_currency}</span><span class="s1">/BTC&#39;</span><span class="p">,</span>
<span class="n">ticker_interval</span><span class="o">=</span><span class="s1">&#39;1h&#39;</span><span class="p">)</span>
</code></pre></div>
<div class="admonition warning warning about backtesting">
<p class="admonition-title">Warning</p>
<p>Be carefull when using dataprovider in backtesting. <code>historic_ohlcv()</code> provides the full time-range in one go,
so please be aware of it and make sure to not "look into the future" to avoid surprises when running in dry/live mode).</p>
</div>
<div class="admonition warning warning in hyperopt">
<p class="admonition-title">Warning</p>
<p>This option cannot currently be used during hyperopt.</p>
</div>
<h4 id="orderbook">Orderbook<a class="headerlink" href="#orderbook" title="Permanent link">&para;</a></h4>
<p><div class="highlight"><pre><span></span><code><span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">runmode</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;live&#39;</span><span class="p">,</span> <span class="s1">&#39;dry_run&#39;</span><span class="p">):</span>
<span class="n">ob</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">orderbook</span><span class="p">(</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;pair&#39;</span><span class="p">],</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;best_bid&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ob</span><span class="p">[</span><span class="s1">&#39;bids&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;best_ask&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ob</span><span class="p">[</span><span class="s1">&#39;asks&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
</code></pre></div>
!Warning The order book is not part of the historic data which means backtesting and hyperopt will not work if this
method is used.</p>
<h4 id="available-pairs">Available Pairs<a class="headerlink" href="#available-pairs" title="Permanent link">&para;</a></h4>
<div class="highlight"><pre><span></span><code><span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="p">:</span>
<span class="k">for</span> <span class="n">pair</span><span class="p">,</span> <span class="n">ticker</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">available_pairs</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;available </span><span class="si">{</span><span class="n">pair</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">ticker</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</code></pre></div>
<h4 id="get-data-for-non-tradeable-pairs">Get data for non-tradeable pairs<a class="headerlink" href="#get-data-for-non-tradeable-pairs" title="Permanent link">&para;</a></h4>
<p>Data for additional, informative pairs (reference pairs) can be beneficial for some strategies.
Ohlcv data for these pairs will be downloaded as part of the regular whitelist refresh process and is available via <code>DataProvider</code> just as other pairs (see above).
These parts will <strong>not</strong> be traded unless they are also specified in the pair whitelist, or have been selected by Dynamic Whitelisting.</p>
<p>The pairs need to be specified as tuples in the format <code>("pair", "interval")</code>, with pair as the first and time interval as the second argument.</p>
<p>Sample:</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">informative_pairs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[(</span><span class="s2">&quot;ETH/USDT&quot;</span><span class="p">,</span> <span class="s2">&quot;5m&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;BTC/TUSD&quot;</span><span class="p">,</span> <span class="s2">&quot;15m&quot;</span><span class="p">),</span>
<span class="p">]</span>
</code></pre></div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>As these pairs will be refreshed as part of the regular whitelist refresh, it's best to keep this list short.
All intervals and all pairs can be specified as long as they are available (and active) on the used exchange.
It is however better to use resampling to longer time-intervals when possible
to avoid hammering the exchange with too many requests and risk beeing blocked.</p>
</div>
<h3 id="additional-data-wallets">Additional data - Wallets<a class="headerlink" href="#additional-data-wallets" title="Permanent link">&para;</a></h3>
<p>The strategy provides access to the <code>Wallets</code> object. This contains the current balances on the exchange.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Wallets is not available during backtesting / hyperopt.</p>
</div>
<p>Please always check if <code>Wallets</code> is available to avoid failures during backtesting.</p>
<div class="highlight"><pre><span></span><code><span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">wallets</span><span class="p">:</span>
<span class="n">free_eth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">wallets</span><span class="o">.</span><span class="n">get_free</span><span class="p">(</span><span class="s1">&#39;ETH&#39;</span><span class="p">)</span>
<span class="n">used_eth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">wallets</span><span class="o">.</span><span class="n">get_used</span><span class="p">(</span><span class="s1">&#39;ETH&#39;</span><span class="p">)</span>
<span class="n">total_eth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">wallets</span><span class="o">.</span><span class="n">get_total</span><span class="p">(</span><span class="s1">&#39;ETH&#39;</span><span class="p">)</span>
</code></pre></div>
<h4 id="possible-options-for-wallets">Possible options for Wallets<a class="headerlink" href="#possible-options-for-wallets" title="Permanent link">&para;</a></h4>
<ul>
<li><code>get_free(asset)</code> - currently available balance to trade</li>
<li><code>get_used(asset)</code> - currently tied up balance (open orders)</li>
<li><code>get_total(asset)</code> - total available balance - sum of the 2 above</li>
</ul>
<h3 id="print-created-dataframe">Print created dataframe<a class="headerlink" href="#print-created-dataframe" title="Permanent link">&para;</a></h3>
<p>To inspect the created dataframe, you can issue a print-statement in either <code>populate_buy_trend()</code> or <code>populate_sell_trend()</code>.
You may also want to print the pair so it's clear what data is currently shown.</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_buy_trend</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dataframe</span><span class="p">:</span> <span class="n">DataFrame</span><span class="p">,</span> <span class="n">metadata</span><span class="p">:</span> <span class="nb">dict</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DataFrame</span><span class="p">:</span>
<span class="n">dataframe</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span>
<span class="p">(</span>
<span class="c1">#&gt;&gt; whatever condition&lt;&lt;&lt;</span>
<span class="p">),</span>
<span class="s1">&#39;buy&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
<span class="c1"># Print the Analyzed pair</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;result for </span><span class="si">{</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;pair&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="c1"># Inspect the last 5 rows</span>
<span class="nb">print</span><span class="p">(</span><span class="n">dataframe</span><span class="o">.</span><span class="n">tail</span><span class="p">())</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
<p>Printing more than a few rows is also possible (simply use <code>print(dataframe)</code> instead of <code>print(dataframe.tail())</code>), however not recommended, as that will be very verbose (~500 lines per pair every 5 seconds).</p>
<h3 id="where-is-the-default-strategy">Where is the default strategy?<a class="headerlink" href="#where-is-the-default-strategy" title="Permanent link">&para;</a></h3>
<p>The default buy strategy is located in the file
<a href="https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/strategy/default_strategy.py">freqtrade/default_strategy.py</a>.</p>
<h3 id="specify-custom-strategy-location">Specify custom strategy location<a class="headerlink" href="#specify-custom-strategy-location" title="Permanent link">&para;</a></h3>
<p>If you want to use a strategy from a different folder you can pass <code>--strategy-path</code></p>
<div class="highlight"><pre><span></span><code>python3<span class="w"> </span>freqtrade<span class="w"> </span>--strategy<span class="w"> </span>AwesomeStrategy<span class="w"> </span>--strategy-path<span class="w"> </span>/some/folder
</code></pre></div>
<h3 id="further-strategy-ideas">Further strategy ideas<a class="headerlink" href="#further-strategy-ideas" title="Permanent link">&para;</a></h3>
<p>To get additional Ideas for strategies, head over to our <a href="https://github.com/freqtrade/freqtrade-strategies">strategy repository</a>. Feel free to use them as they are - but results will depend on the current market situation, pairs used etc. - therefore please backtest the strategy for your exchange/desired pairs first, evaluate carefully, use at your own risk.
Feel free to use any of them as inspiration for your own strategies.
We're happy to accept Pull Requests containing new Strategies to that repo.</p>
<p>We also got a <em>strategy-sharing</em> channel in our <a href="https://join.slack.com/t/highfrequencybot/shared_invite/enQtNjU5ODcwNjI1MDU3LWEyODBiNzkzNzcyNzU0MWYyYzE5NjIyOTQxMzBmMGUxOTIzM2YyN2Y4NWY1YTEwZDgwYTRmMzE2NmM5ZmY2MTg">Slack community</a> which is a great place to get and/or share ideas.</p>
<h2 id="next-step">Next step<a class="headerlink" href="#next-step" title="Permanent link">&para;</a></h2>
<p>Now you have a perfect strategy you probably want to backtest it.
Your next step is to learn <a href="../backtesting/">How to use the Backtesting</a>.</p>
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "..", "features": [], "search": "../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"provider": "mike"}}</script>
<script src="../assets/javascripts/bundle.fe8b6f2b.min.js"></script>
</body>
</html>