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

2714 lines
164 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="canonical" href="https://www.freqtrade.io/2022.5/strategy-customization/">
<link rel="icon" href="../images/logo.png">
<meta name="generator" content="mkdocs-1.3.0, mkdocs-material-8.2.15">
<title>Strategy Customization - Freqtrade</title>
<link rel="stylesheet" href="../assets/stylesheets/main.c382b1dc.min.css">
<link rel="stylesheet" href="../assets/stylesheets/palette.cc9b2e1e.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>
<link rel="stylesheet" href="../stylesheets/ft.extra.css">
<script>__md_scope=new URL("..",location),__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">
<script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
<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="#strategy-customization" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<div data-md-component="outdated" hidden>
<aside class="md-banner md-banner--warning">
</aside>
</div>
<header class="md-header" 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>
<form class="md-header__option" data-md-component="palette">
<input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="blue-grey" data-md-color-accent="tear" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_1">
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 6H7c-3.31 0-6 2.69-6 6s2.69 6 6 6h10c3.31 0 6-2.69 6-6s-2.69-6-6-6zm0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4zM7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/></svg>
</label>
<input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="blue-grey" data-md-color-accent="tear" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_2">
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 7H7a5 5 0 0 0-5 5 5 5 0 0 0 5 5h10a5 5 0 0 0 5-5 5 5 0 0 0-5-5m0 8a3 3 0 0 1-3-3 3 3 0 0 1 3-3 3 3 0 0 1 3 3 3 3 0 0 1-3 3Z"/></svg>
</label>
</form>
<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" 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" 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"></ol>
</div>
</div>
</div>
</div>
</div>
<div class="md-header__source">
<a href="https://github.com/freqtrade/freqtrade" title="Go to repository" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</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">
<!-- Main navigation -->
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div id="widget-wrapper">
</div>
<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>
<div class="md-nav__source">
<a href="https://github.com/freqtrade/freqtrade" title="Go to repository" class="md-source" data-md-component="source">
<div class="md-source__icon md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
</div>
<div class="md-source__repository">
GitHub
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href=".." class="md-nav__link">
Home
</a>
</li>
<li class="md-nav__item">
<a href="../docker_quickstart/" class="md-nav__link">
Quickstart with Docker
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="__nav_3" type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3">
Installation
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Installation" data-md-level="1">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
Installation
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../installation/" class="md-nav__link">
Linux/MacOS/Raspberry
</a>
</li>
<li class="md-nav__item">
<a href="../windows_installation/" class="md-nav__link">
Windows
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../bot-basics/" class="md-nav__link">
Freqtrade Basics
</a>
</li>
<li class="md-nav__item">
<a href="../configuration/" class="md-nav__link">
Configuration
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" data-md-toggle="toc" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
Strategy Customization
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
Strategy Customization
</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="#develop-your-own-strategy" class="md-nav__link">
Develop your own strategy
</a>
<nav class="md-nav" aria-label="Develop your own strategy">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#anatomy-of-a-strategy" class="md-nav__link">
Anatomy of a strategy
</a>
</li>
<li class="md-nav__item">
<a href="#dataframe" class="md-nav__link">
Dataframe
</a>
</li>
<li class="md-nav__item">
<a href="#customize-indicators" class="md-nav__link">
Customize Indicators
</a>
<nav class="md-nav" aria-label="Customize Indicators">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#indicator-libraries" class="md-nav__link">
Indicator libraries
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#strategy-startup-period" class="md-nav__link">
Strategy startup period
</a>
<nav class="md-nav" aria-label="Strategy startup period">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#example" class="md-nav__link">
Example
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#entry-signal-rules" class="md-nav__link">
Entry signal rules
</a>
</li>
<li class="md-nav__item">
<a href="#exit-signal-rules" class="md-nav__link">
Exit signal rules
</a>
</li>
<li class="md-nav__item">
<a href="#minimal-roi" class="md-nav__link">
Minimal ROI
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss" class="md-nav__link">
Stoploss
</a>
</li>
<li class="md-nav__item">
<a href="#timeframe" class="md-nav__link">
Timeframe
</a>
</li>
<li class="md-nav__item">
<a href="#can-short" class="md-nav__link">
Can short
</a>
</li>
<li class="md-nav__item">
<a href="#metadata-dict" class="md-nav__link">
Metadata dict
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#strategy-file-loading" class="md-nav__link">
Strategy file loading
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs" class="md-nav__link">
Informative Pairs
</a>
<nav class="md-nav" aria-label="Informative Pairs">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#get-data-for-non-tradeable-pairs" class="md-nav__link">
Get data for non-tradeable pairs
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs-decorator-informative" class="md-nav__link">
Informative pairs decorator (@informative())
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-dataprovider" class="md-nav__link">
Additional data (DataProvider)
</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">
Possible options for DataProvider
</a>
</li>
<li class="md-nav__item">
<a href="#example-usages" class="md-nav__link">
Example Usages
</a>
</li>
<li class="md-nav__item">
<a href="#available_pairs" class="md-nav__link">
available_pairs
</a>
</li>
<li class="md-nav__item">
<a href="#current_whitelist" class="md-nav__link">
current_whitelist()
</a>
</li>
<li class="md-nav__item">
<a href="#get_pair_dataframepair-timeframe" class="md-nav__link">
get_pair_dataframe(pair, timeframe)
</a>
</li>
<li class="md-nav__item">
<a href="#get_analyzed_dataframepair-timeframe" class="md-nav__link">
get_analyzed_dataframe(pair, timeframe)
</a>
</li>
<li class="md-nav__item">
<a href="#orderbookpair-maximum" class="md-nav__link">
orderbook(pair, maximum)
</a>
</li>
<li class="md-nav__item">
<a href="#tickerpair" class="md-nav__link">
ticker(pair)
</a>
</li>
<li class="md-nav__item">
<a href="#complete-data-provider-sample" class="md-nav__link">
Complete Data-provider sample
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#helper-functions" class="md-nav__link">
Helper functions
</a>
<nav class="md-nav" aria-label="Helper functions">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#merge_informative_pair" class="md-nav__link">
merge_informative_pair()
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss_from_open" class="md-nav__link">
stoploss_from_open()
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss_from_absolute" class="md-nav__link">
stoploss_from_absolute()
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-wallets" class="md-nav__link">
Additional data (Wallets)
</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">
Possible options for Wallets
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-trades" class="md-nav__link">
Additional data (Trades)
</a>
</li>
<li class="md-nav__item">
<a href="#prevent-trades-from-happening-for-a-specific-pair" class="md-nav__link">
Prevent trades from happening for a specific pair
</a>
<nav class="md-nav" aria-label="Prevent trades from happening for a specific pair">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#locking-pairs-from-within-the-strategy" class="md-nav__link">
Locking pairs from within the strategy
</a>
<nav class="md-nav" aria-label="Locking pairs from within the strategy">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#pair-locking-example" class="md-nav__link">
Pair locking example
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#print-created-dataframe" class="md-nav__link">
Print created dataframe
</a>
</li>
<li class="md-nav__item">
<a href="#common-mistakes-when-developing-strategies" class="md-nav__link">
Common mistakes when developing strategies
</a>
<nav class="md-nav" aria-label="Common mistakes when developing strategies">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#peeking-into-the-future-while-backtesting" class="md-nav__link">
Peeking into the future while backtesting
</a>
</li>
<li class="md-nav__item">
<a href="#colliding-signals" class="md-nav__link">
Colliding signals
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#further-strategy-ideas" class="md-nav__link">
Further strategy ideas
</a>
</li>
<li class="md-nav__item">
<a href="#next-step" class="md-nav__link">
Next step
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../strategy-callbacks/" class="md-nav__link">
Strategy Callbacks
</a>
</li>
<li class="md-nav__item">
<a href="../stoploss/" class="md-nav__link">
Stoploss
</a>
</li>
<li class="md-nav__item">
<a href="../plugins/" class="md-nav__link">
Plugins
</a>
</li>
<li class="md-nav__item">
<a href="../bot-usage/" class="md-nav__link">
Start the bot
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="__nav_11" type="checkbox" id="__nav_11" >
<label class="md-nav__link" for="__nav_11">
Control the bot
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Control the bot" data-md-level="1">
<label class="md-nav__title" for="__nav_11">
<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">
Telegram
</a>
</li>
<li class="md-nav__item">
<a href="../rest-api/" class="md-nav__link">
REST API & FreqUI
</a>
</li>
<li class="md-nav__item">
<a href="../webhook-config/" class="md-nav__link">
Web Hook
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../data-download/" class="md-nav__link">
Data Downloading
</a>
</li>
<li class="md-nav__item">
<a href="../backtesting/" class="md-nav__link">
Backtesting
</a>
</li>
<li class="md-nav__item">
<a href="../hyperopt/" class="md-nav__link">
Hyperopt
</a>
</li>
<li class="md-nav__item">
<a href="../leverage/" class="md-nav__link">
Short / Leverage
</a>
</li>
<li class="md-nav__item">
<a href="../utils/" class="md-nav__link">
Utility Sub-commands
</a>
</li>
<li class="md-nav__item">
<a href="../plotting/" class="md-nav__link">
Plotting
</a>
</li>
<li class="md-nav__item">
<a href="../exchanges/" class="md-nav__link">
Exchange-specific Notes
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="__nav_19" type="checkbox" id="__nav_19" >
<label class="md-nav__link" for="__nav_19">
Data Analysis
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Data Analysis" data-md-level="1">
<label class="md-nav__title" for="__nav_19">
<span class="md-nav__icon md-icon"></span>
Data Analysis
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../data-analysis/" class="md-nav__link">
Jupyter Notebooks
</a>
</li>
<li class="md-nav__item">
<a href="../strategy_analysis_example/" class="md-nav__link">
Strategy analysis
</a>
</li>
<li class="md-nav__item">
<a href="../advanced-backtesting/" class="md-nav__link">
Backtest analysis
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle" data-md-toggle="__nav_20" type="checkbox" id="__nav_20" >
<label class="md-nav__link" for="__nav_20">
Advanced Topics
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" aria-label="Advanced Topics" data-md-level="1">
<label class="md-nav__title" for="__nav_20">
<span class="md-nav__icon md-icon"></span>
Advanced Topics
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../advanced-setup/" class="md-nav__link">
Advanced Post-installation Tasks
</a>
</li>
<li class="md-nav__item">
<a href="../edge/" class="md-nav__link">
Edge Positioning
</a>
</li>
<li class="md-nav__item">
<a href="../strategy-advanced/" class="md-nav__link">
Advanced Strategy
</a>
</li>
<li class="md-nav__item">
<a href="../advanced-hyperopt/" class="md-nav__link">
Advanced Hyperopt
</a>
</li>
<li class="md-nav__item">
<a href="../sandbox-testing/" class="md-nav__link">
Sandbox Testing
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../faq/" class="md-nav__link">
FAQ
</a>
</li>
<li class="md-nav__item">
<a href="../sql_cheatsheet/" class="md-nav__link">
SQL Cheat-sheet
</a>
</li>
<li class="md-nav__item">
<a href="../strategy_migration/" class="md-nav__link">
Strategy migration
</a>
</li>
<li class="md-nav__item">
<a href="../updating/" class="md-nav__link">
Updating Freqtrade
</a>
</li>
<li class="md-nav__item">
<a href="../deprecated/" class="md-nav__link">
Deprecated Features
</a>
</li>
<li class="md-nav__item">
<a href="../developer/" class="md-nav__link">
Contributors Guide
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<!-- Table of contents -->
<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="#develop-your-own-strategy" class="md-nav__link">
Develop your own strategy
</a>
<nav class="md-nav" aria-label="Develop your own strategy">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#anatomy-of-a-strategy" class="md-nav__link">
Anatomy of a strategy
</a>
</li>
<li class="md-nav__item">
<a href="#dataframe" class="md-nav__link">
Dataframe
</a>
</li>
<li class="md-nav__item">
<a href="#customize-indicators" class="md-nav__link">
Customize Indicators
</a>
<nav class="md-nav" aria-label="Customize Indicators">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#indicator-libraries" class="md-nav__link">
Indicator libraries
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#strategy-startup-period" class="md-nav__link">
Strategy startup period
</a>
<nav class="md-nav" aria-label="Strategy startup period">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#example" class="md-nav__link">
Example
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#entry-signal-rules" class="md-nav__link">
Entry signal rules
</a>
</li>
<li class="md-nav__item">
<a href="#exit-signal-rules" class="md-nav__link">
Exit signal rules
</a>
</li>
<li class="md-nav__item">
<a href="#minimal-roi" class="md-nav__link">
Minimal ROI
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss" class="md-nav__link">
Stoploss
</a>
</li>
<li class="md-nav__item">
<a href="#timeframe" class="md-nav__link">
Timeframe
</a>
</li>
<li class="md-nav__item">
<a href="#can-short" class="md-nav__link">
Can short
</a>
</li>
<li class="md-nav__item">
<a href="#metadata-dict" class="md-nav__link">
Metadata dict
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#strategy-file-loading" class="md-nav__link">
Strategy file loading
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs" class="md-nav__link">
Informative Pairs
</a>
<nav class="md-nav" aria-label="Informative Pairs">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#get-data-for-non-tradeable-pairs" class="md-nav__link">
Get data for non-tradeable pairs
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs-decorator-informative" class="md-nav__link">
Informative pairs decorator (@informative())
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-dataprovider" class="md-nav__link">
Additional data (DataProvider)
</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">
Possible options for DataProvider
</a>
</li>
<li class="md-nav__item">
<a href="#example-usages" class="md-nav__link">
Example Usages
</a>
</li>
<li class="md-nav__item">
<a href="#available_pairs" class="md-nav__link">
available_pairs
</a>
</li>
<li class="md-nav__item">
<a href="#current_whitelist" class="md-nav__link">
current_whitelist()
</a>
</li>
<li class="md-nav__item">
<a href="#get_pair_dataframepair-timeframe" class="md-nav__link">
get_pair_dataframe(pair, timeframe)
</a>
</li>
<li class="md-nav__item">
<a href="#get_analyzed_dataframepair-timeframe" class="md-nav__link">
get_analyzed_dataframe(pair, timeframe)
</a>
</li>
<li class="md-nav__item">
<a href="#orderbookpair-maximum" class="md-nav__link">
orderbook(pair, maximum)
</a>
</li>
<li class="md-nav__item">
<a href="#tickerpair" class="md-nav__link">
ticker(pair)
</a>
</li>
<li class="md-nav__item">
<a href="#complete-data-provider-sample" class="md-nav__link">
Complete Data-provider sample
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#helper-functions" class="md-nav__link">
Helper functions
</a>
<nav class="md-nav" aria-label="Helper functions">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#merge_informative_pair" class="md-nav__link">
merge_informative_pair()
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss_from_open" class="md-nav__link">
stoploss_from_open()
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss_from_absolute" class="md-nav__link">
stoploss_from_absolute()
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-wallets" class="md-nav__link">
Additional data (Wallets)
</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">
Possible options for Wallets
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-trades" class="md-nav__link">
Additional data (Trades)
</a>
</li>
<li class="md-nav__item">
<a href="#prevent-trades-from-happening-for-a-specific-pair" class="md-nav__link">
Prevent trades from happening for a specific pair
</a>
<nav class="md-nav" aria-label="Prevent trades from happening for a specific pair">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#locking-pairs-from-within-the-strategy" class="md-nav__link">
Locking pairs from within the strategy
</a>
<nav class="md-nav" aria-label="Locking pairs from within the strategy">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#pair-locking-example" class="md-nav__link">
Pair locking example
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#print-created-dataframe" class="md-nav__link">
Print created dataframe
</a>
</li>
<li class="md-nav__item">
<a href="#common-mistakes-when-developing-strategies" class="md-nav__link">
Common mistakes when developing strategies
</a>
<nav class="md-nav" aria-label="Common mistakes when developing strategies">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#peeking-into-the-future-while-backtesting" class="md-nav__link">
Peeking into the future while backtesting
</a>
</li>
<li class="md-nav__item">
<a href="#colliding-signals" class="md-nav__link">
Colliding signals
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#further-strategy-ideas" class="md-nav__link">
Further strategy ideas
</a>
</li>
<li class="md-nav__item">
<a href="#next-step" class="md-nav__link">
Next step
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<a href="https://github.com/freqtrade/freqtrade/edit/master/docs/strategy-customization.md" title="Edit this page" class="md-content__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25Z"/></svg>
</a>
<h1 id="strategy-customization">Strategy Customization<a class="headerlink" href="#strategy-customization" title="Permanent link">&para;</a></h1>
<p>This page explains how to customize your strategies, add new indicators and set up trading rules.</p>
<p>Please familiarize yourself with <a href="../bot-basics/">Freqtrade basics</a> first, which provides overall info on how the bot operates.</p>
<h2 id="develop-your-own-strategy">Develop your own strategy<a class="headerlink" href="#develop-your-own-strategy" title="Permanent link">&para;</a></h2>
<p>The bot includes a default strategy file.
Also, several other strategies are available in the <a href="https://github.com/freqtrade/freqtrade-strategies">strategy repository</a>.</p>
<p>You will however most likely have your own idea for a strategy.
This document intends to help you convert your strategy idea into your own strategy.</p>
<p>To get started, use <code>freqtrade new-strategy --strategy AwesomeStrategy</code> (you can obviously use your own naming for your strategy).
This will create a new strategy file from a template, which will be located under <code>user_data/strategies/AwesomeStrategy.py</code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This is just a template file, which will most likely not be profitable out of the box.</p>
</div>
<details class="hint">
<summary>Different template levels</summary>
<p><code>freqtrade new-strategy</code> has an additional parameter, <code>--template</code>, which controls the amount of pre-build information you get in the created strategy. Use <code>--template minimal</code> to get an empty strategy without any indicator examples, or <code>--template advanced</code> to get a template with most callbacks defined.</p>
</details>
<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>Entry strategy rules</li>
<li>Exit strategy rules</li>
<li>Minimal ROI recommended</li>
<li>Stoploss strongly recommended</li>
</ul>
<p>The bot also include a sample strategy called <code>SampleStrategy</code> you can update: <code>user_data/strategies/sample_strategy.py</code>.
You can test it with the parameter: <code>--strategy SampleStrategy</code></p>
<p>Additionally, there is an attribute called <code>INTERFACE_VERSION</code>, which defines the version of the strategy interface the bot should use.
The current version is 3 - which is also the default when it's not set explicitly in the strategy.</p>
<p>Future versions will require this to be set.</p>
<div class="highlight"><pre><span></span><code>freqtrade<span class="w"> </span>trade<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/freqtrade/templates/sample_strategy.py">user_data/strategies/sample_strategy.py</a>
file as reference.</strong></p>
<div class="admonition note">
<p class="admonition-title">Strategies and Backtesting</p>
<p>To avoid problems and unexpected differences between Backtesting and dry/live modes, please be aware
that during backtesting the full time range 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">
<p class="admonition-title">Warning: Using future data</p>
<p>Since backtesting passes the full time range to the <code>populate_*()</code> methods, the strategy author
needs to take care to avoid having the strategy utilize data from the future.
Some common patterns for this are listed in the <a href="#common-mistakes-when-developing-strategies">Common Mistakes</a> section of this document.</p>
</div>
<h3 id="dataframe">Dataframe<a class="headerlink" href="#dataframe" title="Permanent link">&para;</a></h3>
<p>Freqtrade uses <a href="https://pandas.pydata.org/">pandas</a> to store/provide the candlestick (OHLCV) data.
Pandas is a great library developed for processing large amounts of data.</p>
<p>Each row in a dataframe corresponds to one candle on a chart, with the latest candle always being the last in the dataframe (sorted by date).</p>
<div class="highlight"><pre><span></span><code><span class="go">&gt; dataframe.head()</span>
<span class="go"> date open high low close volume</span>
<span class="go">0 2021-11-09 23:25:00+00:00 67279.67 67321.84 67255.01 67300.97 44.62253</span>
<span class="go">1 2021-11-09 23:30:00+00:00 67300.97 67301.34 67183.03 67187.01 61.38076</span>
<span class="go">2 2021-11-09 23:35:00+00:00 67187.02 67187.02 67031.93 67123.81 113.42728</span>
<span class="go">3 2021-11-09 23:40:00+00:00 67123.80 67222.40 67080.33 67160.48 78.96008</span>
<span class="go">4 2021-11-09 23:45:00+00:00 67160.48 67160.48 66901.26 66943.37 111.39292</span>
</code></pre></div>
<p>Pandas provides fast ways to calculate metrics. To benefit from this speed, it's advised to not use loops, but use vectorized methods instead.</p>
<p>Vectorized operations perform calculations across the whole range of data and are therefore, compared to looping through each row, a lot faster when calculating indicators.</p>
<p>As a dataframe is a table, simple python comparisons like the following will not work</p>
<div class="highlight"><pre><span></span><code> <span class="k">if</span> <span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;rsi&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">30</span><span class="p">:</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;enter_long&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
</code></pre></div>
<p>The above section will fail with <code>The truth value of a Series is ambiguous. [...]</code>.</p>
<p>This must instead be written in a pandas-compatible way, so the operation is performed across the whole dataframe.</p>
<div class="highlight"><pre><span></span><code> <span class="n">dataframe</span><span class="o">.</span><span class="n">loc</span><span class="p">[</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">&gt;</span> <span class="mi">30</span><span class="p">)</span>
<span class="p">,</span> <span class="s1">&#39;enter_long&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
</code></pre></div>
<p>With this section, you have a new column in your dataframe, which has <code>1</code> assigned whenever RSI is above 30.</p>
<h3 id="customize-indicators">Customize Indicators<a class="headerlink" href="#customize-indicators" title="Permanent link">&para;</a></h3>
<p>Buy and sell signals 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_entry_trend()</code>, <code>populate_exit_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: Dataframe with data from the exchange</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/freqtrade/templates/sample_strategy.py">user_data/strategies/sample_strategy.py</a>.
Then uncomment indicators you need.</p>
</div>
<h4 id="indicator-libraries">Indicator libraries<a class="headerlink" href="#indicator-libraries" title="Permanent link">&para;</a></h4>
<p>Out of the box, freqtrade installs the following technical libraries:</p>
<ul>
<li><a href="http://mrjbq7.github.io/ta-lib/">ta-lib</a></li>
<li><a href="https://twopirllc.github.io/pandas-ta/">pandas-ta</a></li>
<li><a href="https://github.com/freqtrade/technical/">technical</a></li>
</ul>
<p>Additional technical libraries can be installed as necessary, or custom indicators may be written / invented by the strategy author.</p>
<h3 id="strategy-startup-period">Strategy startup period<a class="headerlink" href="#strategy-startup-period" title="Permanent link">&para;</a></h3>
<p>Most indicators have an instable startup period, in which they are either not available (NaN), or the calculation is incorrect. This can lead to inconsistencies, since Freqtrade does not know how long this instable period should be.
To account for this, the strategy can be assigned the <code>startup_candle_count</code> attribute.
This should be set to the maximum number of candles that the strategy requires to calculate stable indicators.</p>
<p>In this example strategy, this should be set to 100 (<code>startup_candle_count = 100</code>), since the longest needed history is 100 candles.</p>
<div class="highlight"><pre><span></span><code> <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>
</code></pre></div>
<p>By letting the bot know how much history is needed, backtest trades can start at the specified timerange during backtesting and hyperopt.</p>
<div class="admonition warning">
<p class="admonition-title">Using x calls to get OHLCV</p>
<p>If you receive a warning like <code>WARNING - Using 3 calls to get OHLCV. This can result in slower operations for the bot. Please check if you really need 1500 candles for your strategy</code> - you should consider if you really need this much historic data for your signals.
Having this will cause Freqtrade to make multiple calls for the same pair, which will obviously be slower than one network request.
As a consequence, Freqtrade will take longer to refresh candles - and should therefore be avoided if possible.
This is capped to 5 total calls to avoid overloading the exchange, or make freqtrade too slow.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p><code>startup_candle_count</code> should be below <code>ohlcv_candle_limit * 5</code> (which is 500 * 5 for most exchanges) - since only this amount of candles will be available during Dry-Run/Live Trade operations.</p>
</div>
<h4 id="example">Example<a class="headerlink" href="#example" title="Permanent link">&para;</a></h4>
<p>Let's try to backtest 1 month (January 2019) of 5m candles using an example strategy with EMA100, as above.</p>
<div class="highlight"><pre><span></span><code>freqtrade<span class="w"> </span>backtesting<span class="w"> </span>--timerange<span class="w"> </span><span class="m">20190101</span>-20190201<span class="w"> </span>--timeframe<span class="w"> </span>5m
</code></pre></div>
<p>Assuming <code>startup_candle_count</code> is set to 100, backtesting knows it needs 100 candles to generate valid buy signals. It will load data from <code>20190101 - (100 * 5m)</code> - which is ~2018-12-31 15:30:00.
If this data is available, indicators will be calculated with this extended timerange. The instable startup period (up to 2019-01-01 00:00:00) will then be removed before starting backtesting.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If data for the startup period is not available, then the timerange will be adjusted to account for this startup period - so Backtesting would start at 2019-01-01 08:30:00.</p>
</div>
<h3 id="entry-signal-rules">Entry signal rules<a class="headerlink" href="#entry-signal-rules" title="Permanent link">&para;</a></h3>
<p>Edit the method <code>populate_entry_trend()</code> in your strategy file to update your entry 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 method will also define a new column, <code>"enter_long"</code> (<code>"enter_short"</code> for shorts), which needs to contain 1 for entries, and 0 for "no action". <code>enter_long</code> is a mandatory column that must be set even if the strategy is shorting only.</p>
<p>Sample from <code>user_data/strategies/sample_strategy.py</code>:</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_entry_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">qtpylib</span><span class="o">.</span><span class="n">crossed_above</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="mi">30</span><span class="p">))</span> <span class="o">&amp;</span> <span class="c1"># Signal: RSI crosses above 30</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="c1"># Guard</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="o">&amp;</span> <span class="c1"># Guard</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># Make sure Volume is not 0</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;enter_long&#39;</span><span class="p">,</span> <span class="s1">&#39;enter_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;rsi_cross&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
<details class="note">
<summary>Enter short trades</summary>
<p>Short-entries can be created by setting <code>enter_short</code> (corresponds to <code>enter_long</code> for long trades).
The <code>enter_tag</code> column remains identical.
Short-trades need to be supported by your exchange and market configuration!
Please make sure to set <a href=""><code>can_short</code></a> appropriately on your strategy if you intend to short.</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_entry_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="p">(</span><span class="n">qtpylib</span><span class="o">.</span><span class="n">crossed_above</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="mi">30</span><span class="p">))</span> <span class="o">&amp;</span> <span class="c1"># Signal: RSI crosses above 30</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="c1"># Guard</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="o">&amp;</span> <span class="c1"># Guard</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># Make sure Volume is not 0</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;enter_long&#39;</span><span class="p">,</span> <span class="s1">&#39;enter_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;rsi_cross&#39;</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="p">(</span><span class="n">qtpylib</span><span class="o">.</span><span class="n">crossed_below</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="mi">70</span><span class="p">))</span> <span class="o">&amp;</span> <span class="c1"># Signal: RSI crosses below 70</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="c1"># Guard</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="o">&amp;</span> <span class="c1"># Guard</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># Make sure Volume is not 0</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;enter_short&#39;</span><span class="p">,</span> <span class="s1">&#39;enter_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;rsi_cross&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
</details>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Buying requires sellers to buy from - therefore volume needs to be &gt; 0 (<code>dataframe['volume'] &gt; 0</code>) to make sure that the bot does not buy/sell in no-activity periods.</p>
</div>
<h3 id="exit-signal-rules">Exit signal rules<a class="headerlink" href="#exit-signal-rules" title="Permanent link">&para;</a></h3>
<p>Edit the method <code>populate_exit_trend()</code> into your strategy file to update your exit strategy.
Please note that the exit-signal is only used if <code>use_exit_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 method will also define a new column, <code>"exit_long"</code> (<code>"exit_short"</code> for shorts), which needs to contain 1 for exits, and 0 for "no action".</p>
<p>Sample from <code>user_data/strategies/sample_strategy.py</code>:</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_exit_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 exit 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">qtpylib</span><span class="o">.</span><span class="n">crossed_above</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="mi">70</span><span class="p">))</span> <span class="o">&amp;</span> <span class="c1"># Signal: RSI crosses above 70</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="c1"># Guard</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="o">&amp;</span> <span class="c1"># Guard</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># Make sure Volume is not 0</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;exit_long&#39;</span><span class="p">,</span> <span class="s1">&#39;exit_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;rsi_too_high&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
<details class="note">
<summary>Exit short trades</summary>
<p>Short-exits can be created by setting <code>exit_short</code> (corresponds to <code>exit_long</code>).
The <code>exit_tag</code> column remains identical.
Short-trades need to be supported by your exchange and market configuration!</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_exit_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="p">(</span><span class="n">qtpylib</span><span class="o">.</span><span class="n">crossed_above</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="mi">70</span><span class="p">))</span> <span class="o">&amp;</span> <span class="c1"># Signal: RSI crosses above 70</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="c1"># Guard</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="o">&amp;</span> <span class="c1"># Guard</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># Make sure Volume is not 0</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;exit_long&#39;</span><span class="p">,</span> <span class="s1">&#39;exit_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;rsi_too_high&#39;</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="p">(</span><span class="n">qtpylib</span><span class="o">.</span><span class="n">crossed_below</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="mi">30</span><span class="p">))</span> <span class="o">&amp;</span> <span class="c1"># Signal: RSI crosses below 30</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="c1"># Guard</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="o">&amp;</span> <span class="c1"># Guard</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># Make sure Volume is not 0</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;exit_short&#39;</span><span class="p">,</span> <span class="s1">&#39;exit_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;rsi_too_low&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
</details>
<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 exiting, independent from the exit 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>Exit whenever 4% profit was reached</li>
<li>Exit when 2% profit was reached (in effect after 20 minutes)</li>
<li>Exit when 1% profit was reached (in effect after 30 minutes)</li>
<li>Exit 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 exit once the trade reaches 10000% Profit.</p>
<p>To use times based on candle duration (timeframe), the following snippet can be handy.
This will allow you to change the timeframe for the strategy, and ROI times will still be set as candles (e.g. after 3 candles ...)</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">freqtrade.exchange</span> <span class="kn">import</span> <span class="n">timeframe_to_minutes</span>
<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="n">timeframe</span> <span class="o">=</span> <span class="s2">&quot;1d&quot;</span>
<span class="n">timeframe_mins</span> <span class="o">=</span> <span class="n">timeframe_to_minutes</span><span class="p">(</span><span class="n">timeframe</span><span class="p">)</span>
<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="mf">0.05</span><span class="p">,</span> <span class="c1"># 5% for the first 3 candles</span>
<span class="nb">str</span><span class="p">(</span><span class="n">timeframe_mins</span> <span class="o">*</span> <span class="mi">3</span><span class="p">)):</span> <span class="mf">0.02</span><span class="p">,</span> <span class="c1"># 2% after 3 candles</span>
<span class="nb">str</span><span class="p">(</span><span class="n">timeframe_mins</span> <span class="o">*</span> <span class="mi">6</span><span class="p">)):</span> <span class="mf">0.01</span><span class="p">,</span> <span class="c1"># 1% After 6 candles</span>
<span class="p">}</span>
</code></pre></div>
<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 of setting a 10% stoploss:</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>For the full documentation on stoploss features, look at the dedicated <a href="../stoploss/">stoploss page</a>.</p>
<h3 id="timeframe">Timeframe<a class="headerlink" href="#timeframe" 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 entry/exit signals may work well with one timeframe, but not with the others.</p>
<p>This setting is accessible within the strategy methods as the <code>self.timeframe</code> attribute.</p>
<h3 id="can-short">Can short<a class="headerlink" href="#can-short" title="Permanent link">&para;</a></h3>
<p>To use short signals in futures markets, you will have to let us know to do so by setting <code>can_short=True</code>.
Strategies which enable this will fail to load on spot markets.
Disabling of this will have short signals ignored (also in futures markets).</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_entry_trend</code>, <code>populate_exit_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 <a href="../strategy-advanced/#Storing-information">Storing information</a> section.</p>
<h2 id="strategy-file-loading">Strategy file loading<a class="headerlink" href="#strategy-file-loading" title="Permanent link">&para;</a></h2>
<p>By default, freqtrade will attempt to load strategies from all <code>.py</code> files within <code>user_data/strategies</code>.</p>
<p>Assuming your strategy is called <code>AwesomeStrategy</code>, stored in the file <code>user_data/strategies/AwesomeStrategy.py</code>, then you can start freqtrade with <code>freqtrade trade --strategy AwesomeStrategy</code>.
Note that we're using the class-name, not the file name.</p>
<p>You can use <code>freqtrade list-strategies</code> to see a list of all strategies Freqtrade is able to load (all strategies in the correct folder).
It will also include a "status" field, highlighting potential problems.</p>
<details class="hint">
<summary>Customize strategy directory</summary>
<p>You can use a different directory by using <code>--strategy-path user_data/otherPath</code>. This parameter is available to all commands that require a strategy.</p>
</details>
<h2 id="informative-pairs">Informative Pairs<a class="headerlink" href="#informative-pairs" title="Permanent link">&para;</a></h2>
<h3 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></h3>
<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 below).
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", "timeframe")</code>, with pair as the first and timeframe 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>
<p>A full sample can be found <a href="#complete-data-provider-sample">in the DataProvider section</a>.</p>
<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 timeframes 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 timeframes whenever possible
to avoid hammering the exchange with too many requests and risk being blocked.</p>
</div>
<details class="note">
<summary>Alternative candle types</summary>
<p>Informative_pairs can also provide a 3<sup>rd</sup> tuple element defining the candle type explicitly.
Availability of alternative candle-types will depend on the trading-mode and the exchange. Details about this can be found in the exchange documentation.</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="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="s2">&quot;&quot;</span><span class="p">),</span> <span class="c1"># Uses default candletype, depends on trading_mode </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="s2">&quot;spot&quot;</span><span class="p">),</span> <span class="c1"># Forces usage of spot candles</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="s2">&quot;futures&quot;</span><span class="p">),</span> <span class="c1"># Uses futures candles</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="s2">&quot;mark&quot;</span><span class="p">),</span> <span class="c1"># Uses mark candles</span>
<span class="p">]</span>
</code></pre></div>
</details>
<hr />
<h3 id="informative-pairs-decorator-informative">Informative pairs decorator (<code>@informative()</code>)<a class="headerlink" href="#informative-pairs-decorator-informative" title="Permanent link">&para;</a></h3>
<p>In most common case it is possible to easily define informative pairs by using a decorator. All decorated <code>populate_indicators_*</code> methods run in isolation,
not having access to data from other informative pairs, in the end all informative dataframes are merged and passed to main <code>populate_indicators()</code> method.
When hyperopting, use of hyperoptable parameter <code>.value</code> attribute is not supported. Please use <code>.range</code> attribute. See <a href="../hyperopt/#optimizing-an-indicator-parameter">optimizing an indicator parameter</a>
for more information.</p>
<details class="info">
<summary>Full documentation</summary>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">informative</span><span class="p">(</span><span class="n">timeframe</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">asset</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
<span class="n">fmt</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Callable</span><span class="p">[[</span><span class="n">KwArg</span><span class="p">(</span><span class="nb">str</span><span class="p">)],</span> <span class="nb">str</span><span class="p">]]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="o">*</span><span class="p">,</span>
<span class="n">candle_type</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">CandleType</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">ffill</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Callable</span><span class="p">[[</span><span class="n">PopulateIndicators</span><span class="p">],</span> <span class="n">PopulateIndicators</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A decorator for populate_indicators_Nn(self, dataframe, metadata), allowing these functions to</span>
<span class="sd"> define informative indicators.</span>
<span class="sd"> Example usage:</span>
<span class="sd"> @informative(&#39;1h&#39;)</span>
<span class="sd"> def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -&gt; DataFrame:</span>
<span class="sd"> dataframe[&#39;rsi&#39;] = ta.RSI(dataframe, timeperiod=14)</span>
<span class="sd"> return dataframe</span>
<span class="sd"> :param timeframe: Informative timeframe. Must always be equal or higher than strategy timeframe.</span>
<span class="sd"> :param asset: Informative asset, for example BTC, BTC/USDT, ETH/BTC. Do not specify to use</span>
<span class="sd"> current pair.</span>
<span class="sd"> :param fmt: Column format (str) or column formatter (callable(name, asset, timeframe)). When not</span>
<span class="sd"> specified, defaults to:</span>
<span class="sd"> * {base}_{quote}_{column}_{timeframe} if asset is specified. </span>
<span class="sd"> * {column}_{timeframe} if asset is not specified.</span>
<span class="sd"> Format string supports these format variables:</span>
<span class="sd"> * {asset} - full name of the asset, for example &#39;BTC/USDT&#39;.</span>
<span class="sd"> * {base} - base currency in lower case, for example &#39;eth&#39;.</span>
<span class="sd"> * {BASE} - same as {base}, except in upper case.</span>
<span class="sd"> * {quote} - quote currency in lower case, for example &#39;usdt&#39;.</span>
<span class="sd"> * {QUOTE} - same as {quote}, except in upper case.</span>
<span class="sd"> * {column} - name of dataframe column.</span>
<span class="sd"> * {timeframe} - timeframe of informative dataframe.</span>
<span class="sd"> :param ffill: ffill dataframe after merging informative pair.</span>
<span class="sd"> :param candle_type: &#39;&#39;, mark, index, premiumIndex, or funding_rate</span>
<span class="sd"> &quot;&quot;&quot;</span>
</code></pre></div>
</details>
<details class="example">
<summary>Fast and easy way to define informative pairs</summary>
<p>Most of the time we do not need power and flexibility offered by <code>merge_informative_pair()</code>, therefore we can use a decorator to quickly define informative pairs.</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">from</span> <span class="nn">freqtrade.persistence</span> <span class="kn">import</span> <span class="n">Trade</span>
<span class="kn">from</span> <span class="nn">freqtrade.strategy</span> <span class="kn">import</span> <span class="n">IStrategy</span><span class="p">,</span> <span class="n">informative</span>
<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"># This method is not required. </span>
<span class="c1"># def informative_pairs(self): ...</span>
<span class="c1"># Define informative upper timeframe for each pair. Decorators can be stacked on same </span>
<span class="c1"># method. Available in populate_indicators as &#39;rsi_30m&#39; and &#39;rsi_1h&#39;.</span>
<span class="nd">@informative</span><span class="p">(</span><span class="s1">&#39;30m&#39;</span><span class="p">)</span>
<span class="nd">@informative</span><span class="p">(</span><span class="s1">&#39;1h&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">populate_indicators_1h</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="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">timeperiod</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
<span class="c1"># Define BTC/STAKE informative pair. Available in populate_indicators and other methods as</span>
<span class="c1"># &#39;btc_rsi_1h&#39;. Current stake currency should be specified as {stake} format variable </span>
<span class="c1"># instead of hard-coding actual stake currency. Available in populate_indicators and other </span>
<span class="c1"># methods as &#39;btc_usdt_rsi_1h&#39; (when stake currency is USDT).</span>
<span class="nd">@informative</span><span class="p">(</span><span class="s1">&#39;1h&#39;</span><span class="p">,</span> <span class="s1">&#39;BTC/</span><span class="si">{stake}</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">populate_indicators_btc_1h</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="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">timeperiod</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
<span class="c1"># Define BTC/ETH informative pair. You must specify quote currency if it is different from</span>
<span class="c1"># stake currency. Available in populate_indicators and other methods as &#39;eth_btc_rsi_1h&#39;.</span>
<span class="nd">@informative</span><span class="p">(</span><span class="s1">&#39;1h&#39;</span><span class="p">,</span> <span class="s1">&#39;ETH/BTC&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">populate_indicators_eth_btc_1h</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="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">timeperiod</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
<span class="c1"># Define BTC/STAKE informative pair. A custom formatter may be specified for formatting</span>
<span class="c1"># column names. A callable `fmt(**kwargs) -&gt; str` may be specified, to implement custom</span>
<span class="c1"># formatting. Available in populate_indicators and other methods as &#39;rsi_upper&#39;.</span>
<span class="nd">@informative</span><span class="p">(</span><span class="s1">&#39;1h&#39;</span><span class="p">,</span> <span class="s1">&#39;BTC/</span><span class="si">{stake}</span><span class="s1">&#39;</span><span class="p">,</span> <span class="s1">&#39;</span><span class="si">{column}</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">populate_indicators_btc_1h_2</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="p">[</span><span class="s1">&#39;rsi_upper&#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">timeperiod</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</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"># Strategy timeframe indicators for current pair.</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">timeperiod</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="c1"># Informative pairs are available in this method.</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;rsi_less&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;rsi&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;rsi_1h&#39;</span><span class="p">]</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
</details>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Do not use <code>@informative</code> decorator if you need to use data of one informative pair when generating another informative pair. Instead, define informative pairs
manually as described <a href="#complete-data-provider-sample">in the DataProvider section</a>.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Use string formatting when accessing informative dataframes of other pairs. This will allow easily changing stake currency in config without having to adjust strategy code.</p>
<div class="highlight"><pre><span></span><code><span class="k">def</span> <span class="nf">populate_entry_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">stake</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;stake_currency&#39;</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="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="sa">f</span><span class="s1">&#39;btc_</span><span class="si">{</span><span class="n">stake</span><span class="si">}</span><span class="s1">_rsi_1h&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">35</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;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;enter_long&#39;</span><span class="p">,</span> <span class="s1">&#39;enter_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;buy_signal_rsi&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
</code></pre></div>
<p>Alternatively column renaming may be used to remove stake currency from column names: <code>@informative('1h', 'BTC/{stake}', fmt='{base}_{column}_{timeframe}')</code>.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Duplicate method names</p>
<p>Methods tagged with <code>@informative()</code> decorator must always have unique names! Re-using same name (for example when copy-pasting already defined informative method)
will overwrite previously defined method and not produce any errors due to limitations of Python programming language. In such cases you will find that indicators
created in earlier-defined methods are not available in the dataframe. Carefully review method names and make sure they are unique!</p>
</div>
<h2 id="additional-data-dataprovider">Additional data (DataProvider)<a class="headerlink" href="#additional-data-dataprovider" title="Permanent link">&para;</a></h2>
<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>
<div class="admonition warning">
<p class="admonition-title">Hyperopt</p>
<p>Dataprovider is available during hyperopt, however it can only be used in <code>populate_indicators()</code> within a strategy.
It is not available in <code>populate_buy()</code> and <code>populate_sell()</code> methods, nor in <code>populate_indicators()</code>, if this method located in the hyperopt file.</p>
</div>
<h3 id="possible-options-for-dataprovider">Possible options for DataProvider<a class="headerlink" href="#possible-options-for-dataprovider" title="Permanent link">&para;</a></h3>
<ul>
<li><a href="#available_pairs"><code>available_pairs</code></a> - Property with tuples listing cached pairs with their timeframe (pair, timeframe).</li>
<li><a href="#current_whitelist"><code>current_whitelist()</code></a> - Returns a current list of whitelisted pairs. Useful for accessing dynamic whitelists (i.e. VolumePairlist)</li>
<li><a href="#get_pair_dataframepair-timeframe"><code>get_pair_dataframe(pair, timeframe)</code></a> - This is a universal method, which returns either historical data (for backtesting) or cached live data (for the Dry-Run and Live-Run modes).</li>
<li><a href="#get_analyzed_dataframepair-timeframe"><code>get_analyzed_dataframe(pair, timeframe)</code></a> - Returns the analyzed dataframe (after calling <code>populate_indicators()</code>, <code>populate_buy()</code>, <code>populate_sell()</code>) and the time of the latest analysis.</li>
<li><code>historic_ohlcv(pair, timeframe)</code> - Returns historical data stored on disk.</li>
<li><code>market(pair)</code> - Returns market data for the pair: fees, limits, precisions, activity flag, etc. See <a href="https://github.com/ccxt/ccxt/wiki/Manual#markets">ccxt documentation</a> for more details on the Market data structure.</li>
<li><code>ohlcv(pair, timeframe)</code> - Currently cached candle (OHLCV) data for the pair, returns DataFrame or empty DataFrame.</li>
<li><a href="#orderbookpair-maximum"><code>orderbook(pair, maximum)</code></a> - Returns latest orderbook data for the pair, a dict with bids/asks with a total of <code>maximum</code> entries.</li>
<li><a href="#tickerpair"><code>ticker(pair)</code></a> - Returns current ticker data for the pair. See <a href="https://github.com/ccxt/ccxt/wiki/Manual#price-tickers">ccxt documentation</a> for more details on the Ticker data structure.</li>
<li><code>runmode</code> - Property containing the current runmode.</li>
</ul>
<h3 id="example-usages">Example Usages<a class="headerlink" href="#example-usages" title="Permanent link">&para;</a></h3>
<h3 id="available_pairs"><em>available_pairs</em><a class="headerlink" href="#available_pairs" title="Permanent link">&para;</a></h3>
<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">timeframe</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">timeframe</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</code></pre></div>
<h3 id="current_whitelist"><em>current_whitelist()</em><a class="headerlink" href="#current_whitelist" title="Permanent link">&para;</a></h3>
<p>Imagine you've developed a strategy that trades the <code>5m</code> timeframe using signals generated from a <code>1d</code> timeframe on the top 10 volume pairs by volume.</p>
<p>The strategy might look something like this:</p>
<p><em>Scan through the top 10 pairs by volume using the <code>VolumePairList</code> every 5 minutes and use a 14 day RSI to buy and sell.</em></p>
<p>Due to the limited available data, it's very difficult to resample <code>5m</code> candles into daily candles for use in a 14 day RSI. Most exchanges limit us to just 500 candles which effectively gives us around 1.74 daily candles. We need 14 days at least!</p>
<p>Since we can't resample the data we will have to use an informative pair; and since the whitelist will be dynamic we don't know which pair(s) to use.</p>
<p>This is where calling <code>self.dp.current_whitelist()</code> comes in handy.</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="c1"># get access to all pairs available in whitelist.</span>
<span class="n">pairs</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">current_whitelist</span><span class="p">()</span>
<span class="c1"># Assign tf to each pair so they can be downloaded and cached for strategy.</span>
<span class="n">informative_pairs</span> <span class="o">=</span> <span class="p">[(</span><span class="n">pair</span><span class="p">,</span> <span class="s1">&#39;1d&#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">pair</span> <span class="ow">in</span> <span class="n">pairs</span><span class="p">]</span>
<span class="k">return</span> <span class="n">informative_pairs</span>
</code></pre></div>
<h3 id="get_pair_dataframepair-timeframe"><em>get_pair_dataframe(pair, timeframe)</em><a class="headerlink" href="#get_pair_dataframepair-timeframe" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><span class="c1"># fetch live / historical candle (OHLCV) data for the first informative pair</span>
<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="n">inf_pair</span><span class="p">,</span> <span class="n">inf_timeframe</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">informative_pairs</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">informative</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">get_pair_dataframe</span><span class="p">(</span><span class="n">pair</span><span class="o">=</span><span class="n">inf_pair</span><span class="p">,</span>
<span class="n">timeframe</span><span class="o">=</span><span class="n">inf_timeframe</span><span class="p">)</span>
</code></pre></div>
<div class="admonition warning">
<p class="admonition-title">Warning about backtesting</p>
<p>Be careful when using dataprovider in backtesting. <code>historic_ohlcv()</code> (and <code>get_pair_dataframe()</code>
for the backtesting runmode) 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>
<h3 id="get_analyzed_dataframepair-timeframe"><em>get_analyzed_dataframe(pair, timeframe)</em><a class="headerlink" href="#get_analyzed_dataframepair-timeframe" title="Permanent link">&para;</a></h3>
<p>This method is used by freqtrade internally to determine the last signal.
It can also be used in specific callbacks to get the signal that caused the action (see <a href="../strategy-advanced/">Advanced Strategy Documentation</a> for more details on available callbacks).</p>
<div class="highlight"><pre><span></span><code><span class="c1"># fetch current dataframe</span>
<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="o">.</span><span class="n">value</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">dataframe</span><span class="p">,</span> <span class="n">last_updated</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">get_analyzed_dataframe</span><span class="p">(</span><span class="n">pair</span><span class="o">=</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;pair&#39;</span><span class="p">],</span>
<span class="n">timeframe</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">timeframe</span><span class="p">)</span>
</code></pre></div>
<div class="admonition note">
<p class="admonition-title">No data available</p>
<p>Returns an empty dataframe if the requested pair was not cached.
This should not happen when using whitelisted pairs.</p>
</div>
<h3 id="orderbookpair-maximum"><em>orderbook(pair, maximum)</em><a class="headerlink" href="#orderbookpair-maximum" title="Permanent link">&para;</a></h3>
<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="o">.</span><span class="n">value</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>
<p>The orderbook structure is aligned with the order structure from <a href="https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure">ccxt</a>, so the result will look as follows:</p>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="w"> </span><span class="s1">&#39;bids&#39;</span><span class="o">:</span><span class="w"> </span><span class="p">[</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="nx">price</span><span class="p">,</span><span class="w"> </span><span class="nx">amount</span><span class="w"> </span><span class="p">],</span><span class="w"> </span><span class="c1">// [ float, float ]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="nx">price</span><span class="p">,</span><span class="w"> </span><span class="nx">amount</span><span class="w"> </span><span class="p">],</span>
<span class="w"> </span><span class="p">...</span>
<span class="w"> </span><span class="p">],</span>
<span class="w"> </span><span class="s1">&#39;asks&#39;</span><span class="o">:</span><span class="w"> </span><span class="p">[</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="nx">price</span><span class="p">,</span><span class="w"> </span><span class="nx">amount</span><span class="w"> </span><span class="p">],</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="nx">price</span><span class="p">,</span><span class="w"> </span><span class="nx">amount</span><span class="w"> </span><span class="p">],</span>
<span class="w"> </span><span class="c1">//...</span>
<span class="w"> </span><span class="p">],</span>
<span class="w"> </span><span class="c1">//...</span>
<span class="p">}</span>
</code></pre></div>
<p>Therefore, using <code>ob['bids'][0][0]</code> as demonstrated above will result in using the best bid price. <code>ob['bids'][0][1]</code> would look at the amount at this orderbook position.</p>
<div class="admonition warning">
<p class="admonition-title">Warning about backtesting</p>
<p>The order book is not part of the historic data which means backtesting and hyperopt will not work correctly if this method is used, as the method will return uptodate values.</p>
</div>
<h3 id="tickerpair"><em>ticker(pair)</em><a class="headerlink" href="#tickerpair" title="Permanent link">&para;</a></h3>
<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="o">.</span><span class="n">value</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">ticker</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">ticker</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="n">dataframe</span><span class="p">[</span><span class="s1">&#39;last_price&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ticker</span><span class="p">[</span><span class="s1">&#39;last&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume24h&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ticker</span><span class="p">[</span><span class="s1">&#39;quoteVolume&#39;</span><span class="p">]</span>
<span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;vwap&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ticker</span><span class="p">[</span><span class="s1">&#39;vwap&#39;</span><span class="p">]</span>
</code></pre></div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Although the ticker data structure is a part of the ccxt Unified Interface, the values returned by this method can
vary for different exchanges. For instance, many exchanges do not return <code>vwap</code> values, the FTX exchange
does not always fills in the <code>last</code> field (so it can be None), etc. So you need to carefully verify the ticker
data returned from the exchange and add appropriate error handling / defaults.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning about backtesting</p>
<p>This method will always return up-to-date values - so usage during backtesting / hyperopt will lead to wrong results.</p>
</div>
<h3 id="complete-data-provider-sample">Complete Data-provider sample<a class="headerlink" href="#complete-data-provider-sample" title="Permanent link">&para;</a></h3>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">freqtrade.strategy</span> <span class="kn">import</span> <span class="n">IStrategy</span><span class="p">,</span> <span class="n">merge_informative_pair</span>
<span class="kn">from</span> <span class="nn">pandas</span> <span class="kn">import</span> <span class="n">DataFrame</span>
<span class="k">class</span> <span class="nc">SampleStrategy</span><span class="p">(</span><span class="n">IStrategy</span><span class="p">):</span>
<span class="c1"># strategy init stuff...</span>
<span class="n">timeframe</span> <span class="o">=</span> <span class="s1">&#39;5m&#39;</span>
<span class="c1"># more strategy init stuff..</span>
<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="c1"># get access to all pairs available in whitelist.</span>
<span class="n">pairs</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">current_whitelist</span><span class="p">()</span>
<span class="c1"># Assign tf to each pair so they can be downloaded and cached for strategy.</span>
<span class="n">informative_pairs</span> <span class="o">=</span> <span class="p">[(</span><span class="n">pair</span><span class="p">,</span> <span class="s1">&#39;1d&#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">pair</span> <span class="ow">in</span> <span class="n">pairs</span><span class="p">]</span>
<span class="c1"># Optionally Add additional &quot;static&quot; pairs</span>
<span class="n">informative_pairs</span> <span class="o">+=</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>
<span class="k">return</span> <span class="n">informative_pairs</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="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="p">:</span>
<span class="c1"># Don&#39;t do anything if DataProvider is not available.</span>
<span class="k">return</span> <span class="n">dataframe</span>
<span class="n">inf_tf</span> <span class="o">=</span> <span class="s1">&#39;1d&#39;</span>
<span class="c1"># Get the informative pair</span>
<span class="n">informative</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">get_pair_dataframe</span><span class="p">(</span><span class="n">pair</span><span class="o">=</span><span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;pair&#39;</span><span class="p">],</span> <span class="n">timeframe</span><span class="o">=</span><span class="n">inf_tf</span><span class="p">)</span>
<span class="c1"># Get the 14 day rsi</span>
<span class="n">informative</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">informative</span><span class="p">,</span> <span class="n">timeperiod</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="c1"># Use the helper function merge_informative_pair to safely merge the pair</span>
<span class="c1"># Automatically renames the columns and merges a shorter timeframe dataframe and a longer timeframe informative pair</span>
<span class="c1"># use ffill to have the 1d value available in every row throughout the day.</span>
<span class="c1"># Without this, comparisons between columns of the original and the informative pair would only work once per day.</span>
<span class="c1"># Full documentation of this method, see below</span>
<span class="n">dataframe</span> <span class="o">=</span> <span class="n">merge_informative_pair</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">informative</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">timeframe</span><span class="p">,</span> <span class="n">inf_tf</span><span class="p">,</span> <span class="n">ffill</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="c1"># Calculate rsi of the original dataframe (5m timeframe)</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">timeperiod</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="c1"># Do other stuff</span>
<span class="c1"># ...</span>
<span class="k">return</span> <span class="n">dataframe</span>
<span class="k">def</span> <span class="nf">populate_entry_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="p">(</span><span class="n">qtpylib</span><span class="o">.</span><span class="n">crossed_above</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="mi">30</span><span class="p">))</span> <span class="o">&amp;</span> <span class="c1"># Signal: RSI crosses above 30</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;rsi_1d&#39;</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">30</span><span class="p">)</span> <span class="o">&amp;</span> <span class="c1"># Ensure daily RSI is &lt; 30</span>
<span class="p">(</span><span class="n">dataframe</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># Ensure this candle had volume (important for backtesting)</span>
<span class="p">),</span>
<span class="p">[</span><span class="s1">&#39;enter_long&#39;</span><span class="p">,</span> <span class="s1">&#39;enter_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;rsi_cross&#39;</span><span class="p">)</span>
</code></pre></div>
<hr />
<h2 id="helper-functions">Helper functions<a class="headerlink" href="#helper-functions" title="Permanent link">&para;</a></h2>
<h3 id="merge_informative_pair"><em>merge_informative_pair()</em><a class="headerlink" href="#merge_informative_pair" title="Permanent link">&para;</a></h3>
<p>This method helps you merge an informative pair to a regular dataframe without lookahead bias.
It's there to help you merge the dataframe in a safe and consistent way.</p>
<p>Options:</p>
<ul>
<li>Rename the columns for you to create unique columns</li>
<li>Merge the dataframe without lookahead bias</li>
<li>Forward-fill (optional)</li>
</ul>
<p>All columns of the informative dataframe will be available on the returning dataframe in a renamed fashion:</p>
<div class="admonition example">
<p class="admonition-title">Column renaming</p>
<p>Assuming <code>inf_tf = '1d'</code> the resulting columns will be:</p>
<div class="highlight"><pre><span></span><code><span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="s1">&#39;rsi&#39;</span> <span class="c1"># from the original dataframe</span>
<span class="s1">&#39;date_1d&#39;</span><span class="p">,</span> <span class="s1">&#39;open_1d&#39;</span><span class="p">,</span> <span class="s1">&#39;high_1d&#39;</span><span class="p">,</span> <span class="s1">&#39;low_1d&#39;</span><span class="p">,</span> <span class="s1">&#39;close_1d&#39;</span><span class="p">,</span> <span class="s1">&#39;rsi_1d&#39;</span> <span class="c1"># from the informative dataframe</span>
</code></pre></div>
</div>
<details class="example">
<summary>Column renaming - 1h</summary>
<p>Assuming <code>inf_tf = '1h'</code> the resulting columns will be:</p>
<div class="highlight"><pre><span></span><code><span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="s1">&#39;open&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">,</span> <span class="s1">&#39;low&#39;</span><span class="p">,</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="s1">&#39;rsi&#39;</span> <span class="c1"># from the original dataframe</span>
<span class="s1">&#39;date_1h&#39;</span><span class="p">,</span> <span class="s1">&#39;open_1h&#39;</span><span class="p">,</span> <span class="s1">&#39;high_1h&#39;</span><span class="p">,</span> <span class="s1">&#39;low_1h&#39;</span><span class="p">,</span> <span class="s1">&#39;close_1h&#39;</span><span class="p">,</span> <span class="s1">&#39;rsi_1h&#39;</span> <span class="c1"># from the informative dataframe</span>
</code></pre></div>
</details>
<details class="example">
<summary>Custom implementation</summary>
<p>A custom implementation for this is possible, and can be done as follows:</p>
<div class="highlight"><pre><span></span><code><span class="c1"># Shift date by 1 candle</span>
<span class="c1"># This is necessary since the data is always the &quot;open date&quot;</span>
<span class="c1"># and a 15m candle starting at 12:15 should not know the close of the 1h candle from 12:00 to 13:00</span>
<span class="n">minutes</span> <span class="o">=</span> <span class="n">timeframe_to_minutes</span><span class="p">(</span><span class="n">inf_tf</span><span class="p">)</span>
<span class="c1"># Only do this if the timeframes are different:</span>
<span class="n">informative</span><span class="p">[</span><span class="s1">&#39;date_merge&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">informative</span><span class="p">[</span><span class="s2">&quot;date&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_timedelta</span><span class="p">(</span><span class="n">minutes</span><span class="p">,</span> <span class="s1">&#39;m&#39;</span><span class="p">)</span>
<span class="c1"># Rename columns to be unique</span>
<span class="n">informative</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">col</span><span class="si">}</span><span class="s2">_</span><span class="si">{</span><span class="n">inf_tf</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">informative</span><span class="o">.</span><span class="n">columns</span><span class="p">]</span>
<span class="c1"># Assuming inf_tf = &#39;1d&#39; - then the columns will now be:</span>
<span class="c1"># date_1d, open_1d, high_1d, low_1d, close_1d, rsi_1d</span>
<span class="c1"># Combine the 2 dataframes</span>
<span class="c1"># all indicators on the informative sample MUST be calculated before this point</span>
<span class="n">dataframe</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">dataframe</span><span class="p">,</span> <span class="n">informative</span><span class="p">,</span> <span class="n">left_on</span><span class="o">=</span><span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="n">right_on</span><span class="o">=</span><span class="sa">f</span><span class="s1">&#39;date_merge_</span><span class="si">{</span><span class="n">inf_tf</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">how</span><span class="o">=</span><span class="s1">&#39;left&#39;</span><span class="p">)</span>
<span class="c1"># FFill to have the 1d value available in every row throughout the day.</span>
<span class="c1"># Without this, comparisons would only work once per day.</span>
<span class="n">dataframe</span> <span class="o">=</span> <span class="n">dataframe</span><span class="o">.</span><span class="n">ffill</span><span class="p">()</span>
</code></pre></div>
</details>
<div class="admonition warning">
<p class="admonition-title">Informative timeframe &lt; timeframe</p>
<p>Using informative timeframes smaller than the dataframe timeframe is not recommended with this method, as it will not use any of the additional information this would provide.
To use the more detailed information properly, more advanced methods should be applied (which are out of scope for freqtrade documentation, as it'll depend on the respective need).</p>
</div>
<hr />
<h3 id="stoploss_from_open"><em>stoploss_from_open()</em><a class="headerlink" href="#stoploss_from_open" title="Permanent link">&para;</a></h3>
<p>Stoploss values returned from <code>custom_stoploss</code> must specify a percentage relative to <code>current_rate</code>, but sometimes you may want to specify a stoploss relative to the open price instead. <code>stoploss_from_open()</code> is a helper function to calculate a stoploss value that can be returned from <code>custom_stoploss</code> which will be equivalent to the desired percentage above the open price.</p>
<details class="example">
<summary>Returning a stoploss relative to the open price from the custom stoploss function</summary>
<p>Say the open price was $100, and <code>current_price</code> is $121 (<code>current_profit</code> will be <code>0.21</code>). </p>
<p>If we want a stop price at 7% above the open price we can call <code>stoploss_from_open(0.07, current_profit, False)</code> which will return <code>0.1157024793</code>. 11.57% below $121 is $107, which is the same as 7% above $100.</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">from</span> <span class="nn">freqtrade.persistence</span> <span class="kn">import</span> <span class="n">Trade</span>
<span class="kn">from</span> <span class="nn">freqtrade.strategy</span> <span class="kn">import</span> <span class="n">IStrategy</span><span class="p">,</span> <span class="n">stoploss_from_open</span>
<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"># ... populate_* methods</span>
<span class="n">use_custom_stoploss</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">def</span> <span class="nf">custom_stoploss</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pair</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">trade</span><span class="p">:</span> <span class="s1">&#39;Trade&#39;</span><span class="p">,</span> <span class="n">current_time</span><span class="p">:</span> <span class="n">datetime</span><span class="p">,</span>
<span class="n">current_rate</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">current_profit</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">float</span><span class="p">:</span>
<span class="c1"># once the profit has risen above 10%, keep the stoploss at 7% above the open price</span>
<span class="k">if</span> <span class="n">current_profit</span> <span class="o">&gt;</span> <span class="mf">0.10</span><span class="p">:</span>
<span class="k">return</span> <span class="n">stoploss_from_open</span><span class="p">(</span><span class="mf">0.07</span><span class="p">,</span> <span class="n">current_profit</span><span class="p">,</span> <span class="n">is_short</span><span class="o">=</span><span class="n">trade</span><span class="o">.</span><span class="n">is_short</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
</code></pre></div>
<p>Full examples can be found in the <a href="../strategy-advanced/#custom-stoploss">Custom stoploss</a> section of the Documentation.</p>
</details>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Providing invalid input to <code>stoploss_from_open()</code> may produce "CustomStoploss function did not return valid stoploss" warnings.
This may happen if <code>current_profit</code> parameter is below specified <code>open_relative_stop</code>. Such situations may arise when closing trade
is blocked by <code>confirm_trade_exit()</code> method. Warnings can be solved by never blocking stop loss sells by checking <code>exit_reason</code> in
<code>confirm_trade_exit()</code>, or by using <code>return stoploss_from_open(...) or 1</code> idiom, which will request to not change stop loss when
<code>current_profit &lt; open_relative_stop</code>.</p>
</div>
<h3 id="stoploss_from_absolute"><em>stoploss_from_absolute()</em><a class="headerlink" href="#stoploss_from_absolute" title="Permanent link">&para;</a></h3>
<p>In some situations it may be confusing to deal with stops relative to current rate. Instead, you may define a stoploss level using an absolute price.</p>
<details class="example">
<summary>Returning a stoploss using absolute price from the custom stoploss function</summary>
<p>If we want to trail a stop price at 2xATR below current price we can call <code>stoploss_from_absolute(current_rate - (candle['atr'] * 2), current_rate, is_short=trade.is_short)</code>.</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">from</span> <span class="nn">freqtrade.persistence</span> <span class="kn">import</span> <span class="n">Trade</span>
<span class="kn">from</span> <span class="nn">freqtrade.strategy</span> <span class="kn">import</span> <span class="n">IStrategy</span><span class="p">,</span> <span class="n">stoploss_from_absolute</span>
<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="n">use_custom_stoploss</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">def</span> <span class="nf">populate_indicators_1h</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="p">[</span><span class="s1">&#39;atr&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ta</span><span class="o">.</span><span class="n">ATR</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">14</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dataframe</span>
<span class="k">def</span> <span class="nf">custom_stoploss</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pair</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">trade</span><span class="p">:</span> <span class="s1">&#39;Trade&#39;</span><span class="p">,</span> <span class="n">current_time</span><span class="p">:</span> <span class="n">datetime</span><span class="p">,</span>
<span class="n">current_rate</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">current_profit</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">float</span><span class="p">:</span>
<span class="n">dataframe</span><span class="p">,</span> <span class="n">_</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">get_analyzed_dataframe</span><span class="p">(</span><span class="n">pair</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">timeframe</span><span class="p">)</span>
<span class="n">candle</span> <span class="o">=</span> <span class="n">dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span>
<span class="k">return</span> <span class="n">stoploss_from_absolute</span><span class="p">(</span><span class="n">current_rate</span> <span class="o">-</span> <span class="p">(</span><span class="n">candle</span><span class="p">[</span><span class="s1">&#39;atr&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span><span class="p">),</span> <span class="n">current_rate</span><span class="p">,</span> <span class="n">is_short</span><span class="o">=</span><span class="n">trade</span><span class="o">.</span><span class="n">is_short</span><span class="p">)</span>
</code></pre></div>
</details>
<h2 id="additional-data-wallets">Additional data (Wallets)<a class="headerlink" href="#additional-data-wallets" title="Permanent link">&para;</a></h2>
<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>
<h3 id="possible-options-for-wallets">Possible options for Wallets<a class="headerlink" href="#possible-options-for-wallets" title="Permanent link">&para;</a></h3>
<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>
<hr />
<h2 id="additional-data-trades">Additional data (Trades)<a class="headerlink" href="#additional-data-trades" title="Permanent link">&para;</a></h2>
<p>A history of Trades can be retrieved in the strategy by querying the database.</p>
<p>At the top of the file, import Trade.</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">freqtrade.persistence</span> <span class="kn">import</span> <span class="n">Trade</span>
</code></pre></div>
<p>The following example queries for the current pair and trades from today, however other filters can easily be added.</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">config</span><span class="p">[</span><span class="s1">&#39;runmode&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</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">trades</span> <span class="o">=</span> <span class="n">Trade</span><span class="o">.</span><span class="n">get_trades</span><span class="p">([</span><span class="n">Trade</span><span class="o">.</span><span class="n">pair</span> <span class="o">==</span> <span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;pair&#39;</span><span class="p">],</span>
<span class="n">Trade</span><span class="o">.</span><span class="n">open_date</span> <span class="o">&gt;</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span> <span class="o">-</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span>
<span class="n">Trade</span><span class="o">.</span><span class="n">is_open</span><span class="o">.</span><span class="n">is_</span><span class="p">(</span><span class="kc">False</span><span class="p">),</span>
<span class="p">])</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="n">Trade</span><span class="o">.</span><span class="n">close_date</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
<span class="c1"># Summarize profit for this pair.</span>
<span class="n">curdayprofit</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">trade</span><span class="o">.</span><span class="n">close_profit</span> <span class="k">for</span> <span class="n">trade</span> <span class="ow">in</span> <span class="n">trades</span><span class="p">)</span>
</code></pre></div>
<p>Get amount of stake_currency currently invested in Trades:</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">config</span><span class="p">[</span><span class="s1">&#39;runmode&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</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">total_stakes</span> <span class="o">=</span> <span class="n">Trade</span><span class="o">.</span><span class="n">total_open_trades_stakes</span><span class="p">()</span>
</code></pre></div>
<p>Retrieve performance per pair.
Returns a List of dicts per pair.</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">config</span><span class="p">[</span><span class="s1">&#39;runmode&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</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">performance</span> <span class="o">=</span> <span class="n">Trade</span><span class="o">.</span><span class="n">get_overall_performance</span><span class="p">()</span>
</code></pre></div>
<p>Sample return value: ETH/BTC had 5 trades, with a total profit of 1.5% (ratio of 0.015).</p>
<div class="highlight"><pre><span></span><code><span class="p">{</span><span class="nt">&quot;pair&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;ETH/BTC&quot;</span><span class="p">,</span><span class="w"> </span><span class="nt">&quot;profit&quot;</span><span class="p">:</span><span class="w"> </span><span class="mf">0.015</span><span class="p">,</span><span class="w"> </span><span class="nt">&quot;count&quot;</span><span class="p">:</span><span class="w"> </span><span class="mi">5</span><span class="p">}</span>
</code></pre></div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Trade history is not available during backtesting or hyperopt.</p>
</div>
<h2 id="prevent-trades-from-happening-for-a-specific-pair">Prevent trades from happening for a specific pair<a class="headerlink" href="#prevent-trades-from-happening-for-a-specific-pair" title="Permanent link">&para;</a></h2>
<p>Freqtrade locks pairs automatically for the current candle (until that candle is over) when a pair is sold, preventing an immediate re-buy of that pair.</p>
<p>Locked pairs will show the message <code>Pair &lt;pair&gt; is currently locked.</code>.</p>
<h3 id="locking-pairs-from-within-the-strategy">Locking pairs from within the strategy<a class="headerlink" href="#locking-pairs-from-within-the-strategy" title="Permanent link">&para;</a></h3>
<p>Sometimes it may be desired to lock a pair after certain events happen (e.g. multiple losing trades in a row).</p>
<p>Freqtrade has an easy method to do this from within the strategy, by calling <code>self.lock_pair(pair, until, [reason])</code>.
<code>until</code> must be a datetime object in the future, after which trading will be re-enabled for that pair, while <code>reason</code> is an optional string detailing why the pair was locked.</p>
<p>Locks can also be lifted manually, by calling <code>self.unlock_pair(pair)</code> or <code>self.unlock_reason(&lt;reason&gt;)</code> - providing reason the pair was locked with.
<code>self.unlock_reason(&lt;reason&gt;)</code> will unlock all pairs currently locked with the provided reason.</p>
<p>To verify if a pair is currently locked, use <code>self.is_pair_locked(pair)</code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Locked pairs will always be rounded up to the next candle. So assuming a <code>5m</code> timeframe, a lock with <code>until</code> set to 10:18 will lock the pair until the candle from 10:15-10:20 will be finished.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Manually locking pairs is not available during backtesting, only locks via Protections are allowed.</p>
</div>
<h4 id="pair-locking-example">Pair locking example<a class="headerlink" href="#pair-locking-example" title="Permanent link">&para;</a></h4>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">freqtrade.persistence</span> <span class="kn">import</span> <span class="n">Trade</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">timedelta</span><span class="p">,</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timezone</span>
<span class="c1"># Put the above lines a the top of the strategy file, next to all the other imports</span>
<span class="c1"># --------</span>
<span class="c1"># Within populate indicators (or populate_buy):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;runmode&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">value</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="c1"># fetch closed trades for the last 2 days</span>
<span class="n">trades</span> <span class="o">=</span> <span class="n">Trade</span><span class="o">.</span><span class="n">get_trades</span><span class="p">([</span><span class="n">Trade</span><span class="o">.</span><span class="n">pair</span> <span class="o">==</span> <span class="n">metadata</span><span class="p">[</span><span class="s1">&#39;pair&#39;</span><span class="p">],</span>
<span class="n">Trade</span><span class="o">.</span><span class="n">open_date</span> <span class="o">&gt;</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span> <span class="o">-</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">2</span><span class="p">),</span>
<span class="n">Trade</span><span class="o">.</span><span class="n">is_open</span><span class="o">.</span><span class="n">is_</span><span class="p">(</span><span class="kc">False</span><span class="p">),</span>
<span class="p">])</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
<span class="c1"># Analyze the conditions you&#39;d like to lock the pair .... will probably be different for every strategy</span>
<span class="n">sumprofit</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">trade</span><span class="o">.</span><span class="n">close_profit</span> <span class="k">for</span> <span class="n">trade</span> <span class="ow">in</span> <span class="n">trades</span><span class="p">)</span>
<span class="k">if</span> <span class="n">sumprofit</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="c1"># Lock pair for 12 hours</span>
<span class="bp">self</span><span class="o">.</span><span class="n">lock_pair</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="n">until</span><span class="o">=</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">(</span><span class="n">timezone</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">12</span><span class="p">))</span>
</code></pre></div>
<h2 id="print-created-dataframe">Print created dataframe<a class="headerlink" href="#print-created-dataframe" title="Permanent link">&para;</a></h2>
<p>To inspect the created dataframe, you can issue a print-statement in either <code>populate_entry_trend()</code> or <code>populate_exit_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_entry_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="p">[</span><span class="s1">&#39;enter_long&#39;</span><span class="p">,</span> <span class="s1">&#39;enter_tag&#39;</span><span class="p">]]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;somestring&#39;</span><span class="p">)</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>
<h2 id="common-mistakes-when-developing-strategies">Common mistakes when developing strategies<a class="headerlink" href="#common-mistakes-when-developing-strategies" title="Permanent link">&para;</a></h2>
<h3 id="peeking-into-the-future-while-backtesting">Peeking into the future while backtesting<a class="headerlink" href="#peeking-into-the-future-while-backtesting" title="Permanent link">&para;</a></h3>
<p>Backtesting analyzes the whole time-range at once for performance reasons. Because of this, strategy authors need to make sure that strategies do not look-ahead into the future.
This is a common pain-point, which can cause huge differences between backtesting and dry/live run methods, since they all use data which is not available during dry/live runs, so these strategies will perform well during backtesting, but will fail / perform badly in real conditions.</p>
<p>The following lists some common patterns which should be avoided to prevent frustration:</p>
<ul>
<li>don't use <code>shift(-1)</code>. This uses data from the future, which is not available.</li>
<li>don't use <code>.iloc[-1]</code> or any other absolute position in the dataframe, this will be different between dry-run and backtesting.</li>
<li>don't use <code>dataframe['volume'].mean()</code>. This uses the full DataFrame for backtesting, including data from the future. Use <code>dataframe['volume'].rolling(&lt;window&gt;).mean()</code> instead</li>
<li>don't use <code>.resample('1h')</code>. This uses the left border of the interval, so moves data from an hour to the start of the hour. Use <code>.resample('1h', label='right')</code> instead.</li>
</ul>
<h3 id="colliding-signals">Colliding signals<a class="headerlink" href="#colliding-signals" title="Permanent link">&para;</a></h3>
<p>When conflicting signals collide (e.g. both <code>'enter_long'</code> and <code>'exit_long'</code> are 1), freqtrade will do nothing and ignore the entry signal. This will avoid trades that enter, and exit immediately. Obviously, this can potentially lead to missed entries.</p>
<p>The following rules apply, and entry signals will be ignored if more than one of the 3 signals is set:</p>
<ul>
<li><code>enter_long</code> -&gt; <code>exit_long</code>, <code>enter_short</code></li>
<li><code>enter_short</code> -&gt; <code>exit_short</code>, <code>enter_long</code></li>
</ul>
<h2 id="further-strategy-ideas">Further strategy ideas<a class="headerlink" href="#further-strategy-ideas" title="Permanent link">&para;</a></h2>
<p>To get additional Ideas for strategies, head over to the <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>
<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>
</div>
</main>
<footer class="md-footer">
<nav class="md-footer__inner md-grid" aria-label="Footer">
<a href="../configuration/" class="md-footer__link md-footer__link--prev" aria-label="Previous: Configuration" rel="prev">
<div class="md-footer__button md-icon">
<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>
</div>
<div class="md-footer__title">
<div class="md-ellipsis">
<span class="md-footer__direction">
Previous
</span>
Configuration
</div>
</div>
</a>
<a href="../strategy-callbacks/" class="md-footer__link md-footer__link--next" aria-label="Next: Strategy Callbacks" rel="next">
<div class="md-footer__title">
<div class="md-ellipsis">
<span class="md-footer__direction">
Next
</span>
Strategy Callbacks
</div>
</div>
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
</div>
</a>
</nav>
<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>
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!-- Load binance SDK -->
<script async defer src="https://public.bnbstatic.com/static/js/broker-sdk/broker-sdk@1.0.0.min.js"></script>
<script>
window.onload = function () {
var sidebar = document.getElementById('widget-wrapper')
var newDiv = document.createElement("div");
newDiv.id = "widget";
try {
sidebar.prepend(newDiv);
window.binanceBrokerPortalSdk.initBrokerSDK('#widget', {
apiHost: 'https://www.binance.com',
brokerId: 'R4BD3S82',
slideTime: 4e4,
});
} catch(err) {
console.log(err)
}
}
</script>
</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.2a1c317c.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "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.title": "Select version"}, "version": {"provider": "mike"}}</script>
<script src="../assets/javascripts/bundle.a6c66575.min.js"></script>
<script src="../javascripts/config.js"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</body>
</html>