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

3434 lines
172 KiB
HTML
Raw Normal View History

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="Freqtrade is a free and open source crypto trading bot written in Python, designed to support all major exchanges and be controlled via Telegram or builtin Web UI">
<link rel="canonical" href="https://www.freqtrade.io/en/stable/strategy-customization/">
<link rel="prev" href="../configuration/">
<link rel="next" href="../strategy-callbacks/">
<link rel="icon" href="../images/logo.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.5.40">
<title>Strategy Customization - Freqtrade</title>
<link rel="stylesheet" href="../assets/stylesheets/main.8c3ca2c6.min.css">
<link rel="stylesheet" href="../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<link rel="stylesheet" href="../stylesheets/ft.extra.css">
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
<script id="__analytics">function __md_analytics(){function e(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],e("js",new Date),e("config","G-VH170LG9M5"),document.addEventListener("DOMContentLoaded",(function(){document.forms.search&&document.forms.search.query.addEventListener("blur",(function(){this.value&&e("event","search",{search_term:this.value})}));document$.subscribe((function(){var t=document.forms.feedback;if(void 0!==t)for(var a of t.querySelectorAll("[type=submit]"))a.addEventListener("click",(function(a){a.preventDefault();var n=document.location.pathname,d=this.getAttribute("data-md-value");e("event","feedback",{page:n,data:d}),t.firstElementChild.disabled=!0;var r=t.querySelector(".md-feedback__note [data-md-value='"+d+"']");r&&(r.hidden=!1)})),t.hidden=!1})),location$.subscribe((function(t){e("config","G-VH170LG9M5",{page_path:t.pathname})}))}));var t=document.createElement("script");t.async=!0,t.src="https://www.googletagmanager.com/gtag/js?id=G-VH170LG9M5",document.getElementById("__analytics").insertAdjacentElement("afterEnd",t)}</script>
<script>"undefined"!=typeof __md_analytics&&__md_analytics()</script>
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="blue-grey" data-md-color-accent="tear">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#strategy-customization" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<div data-md-color-scheme="default" data-md-component="outdated" hidden>
</div>
<header class="md-header md-header--shadow" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="Freqtrade" class="md-header__button md-logo" aria-label="Freqtrade" data-md-component="logo">
<img src="../images/logo.png" alt="logo">
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></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_0">
<label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" 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-6m0 10H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h10c2.21 0 4 1.79 4 4s-1.79 4-4 4M7 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3"/></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_1">
<label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" 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 3"/></svg>
</label>
</form>
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
<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.52 6.52 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 5"/></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.52 6.52 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 5"/></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 11z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<a href="javascript:void(0)" class="md-search__icon md-icon" title="Share" aria-label="Share" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91s2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08"/></svg>
</a>
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</nav>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
<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.6.0 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 2024 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.81"/></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 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.6.0 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 2024 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.81"/></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">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../docker_quickstart/" class="md-nav__link">
<span class="md-ellipsis">
Quickstart with Docker
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
Installation
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<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">
<span class="md-ellipsis">
Linux/MacOS/Raspberry
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../windows_installation/" class="md-nav__link">
<span class="md-ellipsis">
Windows
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../bot-basics/" class="md-nav__link">
<span class="md-ellipsis">
Freqtrade Basics
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../configuration/" class="md-nav__link">
<span class="md-ellipsis">
Configuration
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Strategy Customization
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Strategy Customization
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#develop-your-own-strategy" class="md-nav__link">
<span class="md-ellipsis">
Develop your own strategy
</span>
</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">
<span class="md-ellipsis">
Anatomy of a strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#dataframe" class="md-nav__link">
<span class="md-ellipsis">
Dataframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#customize-indicators" class="md-nav__link">
<span class="md-ellipsis">
Customize Indicators
</span>
</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">
<span class="md-ellipsis">
Indicator libraries
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#strategy-startup-period" class="md-nav__link">
<span class="md-ellipsis">
Strategy startup period
</span>
</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">
<span class="md-ellipsis">
Example
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#entry-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Entry signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#exit-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Exit signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#minimal-roi" class="md-nav__link">
<span class="md-ellipsis">
Minimal ROI
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss" class="md-nav__link">
<span class="md-ellipsis">
Stoploss
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#timeframe" class="md-nav__link">
<span class="md-ellipsis">
Timeframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#can-short" class="md-nav__link">
<span class="md-ellipsis">
Can short
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#metadata-dict" class="md-nav__link">
<span class="md-ellipsis">
Metadata dict
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#imports-necessary-for-a-strategy" class="md-nav__link">
<span class="md-ellipsis">
Imports necessary for a strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#strategy-file-loading" class="md-nav__link">
<span class="md-ellipsis">
Strategy file loading
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs" class="md-nav__link">
<span class="md-ellipsis">
Informative Pairs
</span>
</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">
<span class="md-ellipsis">
Get data for non-tradeable pairs
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs-decorator-informative" class="md-nav__link">
<span class="md-ellipsis">
Informative pairs decorator (@informative())
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#merge_informative_pair" class="md-nav__link">
<span class="md-ellipsis">
merge_informative_pair()
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Additional data (DataProvider)
</span>
</a>
<nav class="md-nav" aria-label="Additional data (DataProvider)">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Possible options for DataProvider
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#example-usages" class="md-nav__link">
<span class="md-ellipsis">
Example Usages
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#available_pairs" class="md-nav__link">
<span class="md-ellipsis">
available_pairs
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#current_whitelist" class="md-nav__link">
<span class="md-ellipsis">
current_whitelist()
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#get_pair_dataframepair-timeframe" class="md-nav__link">
<span class="md-ellipsis">
get_pair_dataframe(pair, timeframe)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#get_analyzed_dataframepair-timeframe" class="md-nav__link">
<span class="md-ellipsis">
get_analyzed_dataframe(pair, timeframe)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#orderbookpair-maximum" class="md-nav__link">
<span class="md-ellipsis">
orderbook(pair, maximum)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#tickerpair" class="md-nav__link">
<span class="md-ellipsis">
ticker(pair)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#send-notification" class="md-nav__link">
<span class="md-ellipsis">
Send Notification
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#complete-data-provider-sample" class="md-nav__link">
<span class="md-ellipsis">
Complete Data-provider sample
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-wallets" class="md-nav__link">
<span class="md-ellipsis">
Additional data (Wallets)
</span>
</a>
<nav class="md-nav" aria-label="Additional data (Wallets)">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-wallets" class="md-nav__link">
<span class="md-ellipsis">
Possible options for Wallets
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-trades" class="md-nav__link">
<span class="md-ellipsis">
Additional data (Trades)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#prevent-trades-from-happening-for-a-specific-pair" class="md-nav__link">
<span class="md-ellipsis">
Prevent trades from happening for a specific pair
</span>
</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">
<span class="md-ellipsis">
Locking pairs from within the strategy
</span>
</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">
<span class="md-ellipsis">
Pair locking example
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#print-created-dataframe" class="md-nav__link">
<span class="md-ellipsis">
Print created dataframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#common-mistakes-when-developing-strategies" class="md-nav__link">
<span class="md-ellipsis">
Common mistakes when developing strategies
</span>
</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">
<span class="md-ellipsis">
Peeking into the future while backtesting
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#colliding-signals" class="md-nav__link">
<span class="md-ellipsis">
Colliding signals
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#further-strategy-ideas" class="md-nav__link">
<span class="md-ellipsis">
Further strategy ideas
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#next-step" class="md-nav__link">
<span class="md-ellipsis">
Next step
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../strategy-callbacks/" class="md-nav__link">
<span class="md-ellipsis">
Strategy Callbacks
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../stoploss/" class="md-nav__link">
<span class="md-ellipsis">
Stoploss
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../plugins/" class="md-nav__link">
<span class="md-ellipsis">
Plugins
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../bot-usage/" class="md-nav__link">
<span class="md-ellipsis">
Start the bot
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_11" >
<label class="md-nav__link" for="__nav_11" id="__nav_11_label" tabindex="0">
<span class="md-ellipsis">
Control the bot
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_11_label" aria-expanded="false">
<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">
<span class="md-ellipsis">
Telegram
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../freq-ui/" class="md-nav__link">
<span class="md-ellipsis">
freqUI
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../rest-api/" class="md-nav__link">
<span class="md-ellipsis">
REST API
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../webhook-config/" class="md-nav__link">
<span class="md-ellipsis">
Web Hook
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../data-download/" class="md-nav__link">
<span class="md-ellipsis">
Data Downloading
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../backtesting/" class="md-nav__link">
<span class="md-ellipsis">
Backtesting
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../hyperopt/" class="md-nav__link">
<span class="md-ellipsis">
Hyperopt
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_15" >
<label class="md-nav__link" for="__nav_15" id="__nav_15_label" tabindex="0">
<span class="md-ellipsis">
FreqAI
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_15_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_15">
<span class="md-nav__icon md-icon"></span>
FreqAI
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../freqai/" class="md-nav__link">
<span class="md-ellipsis">
Introduction
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../freqai-configuration/" class="md-nav__link">
<span class="md-ellipsis">
Configuration
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../freqai-parameter-table/" class="md-nav__link">
<span class="md-ellipsis">
Parameter table
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../freqai-feature-engineering/" class="md-nav__link">
<span class="md-ellipsis">
Feature engineering
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../freqai-running/" class="md-nav__link">
<span class="md-ellipsis">
Running FreqAI
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../freqai-reinforcement-learning/" class="md-nav__link">
<span class="md-ellipsis">
Reinforcement Learning
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../freqai-developers/" class="md-nav__link">
<span class="md-ellipsis">
Developer guide
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../leverage/" class="md-nav__link">
<span class="md-ellipsis">
Short / Leverage
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../utils/" class="md-nav__link">
<span class="md-ellipsis">
Utility Sub-commands
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../plotting/" class="md-nav__link">
<span class="md-ellipsis">
Plotting
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../exchanges/" class="md-nav__link">
<span class="md-ellipsis">
Exchange-specific Notes
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_20" >
<label class="md-nav__link" for="__nav_20" id="__nav_20_label" tabindex="0">
<span class="md-ellipsis">
Data Analysis
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_20_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_20">
<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">
<span class="md-ellipsis">
Jupyter Notebooks
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../strategy_analysis_example/" class="md-nav__link">
<span class="md-ellipsis">
Strategy analysis
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../advanced-backtesting/" class="md-nav__link">
<span class="md-ellipsis">
Backtest analysis
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_21" >
<label class="md-nav__link" for="__nav_21" id="__nav_21_label" tabindex="0">
<span class="md-ellipsis">
Advanced Topics
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_21_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_21">
<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">
<span class="md-ellipsis">
Advanced Post-installation Tasks
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../trade-object/" class="md-nav__link">
<span class="md-ellipsis">
Trade Object
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../lookahead-analysis/" class="md-nav__link">
<span class="md-ellipsis">
Lookahead analysis
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../recursive-analysis/" class="md-nav__link">
<span class="md-ellipsis">
Recursive analysis
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../strategy-advanced/" class="md-nav__link">
<span class="md-ellipsis">
Advanced Strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../advanced-hyperopt/" class="md-nav__link">
<span class="md-ellipsis">
Advanced Hyperopt
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../advanced-orderflow/" class="md-nav__link">
<span class="md-ellipsis">
Orderflow
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../producer-consumer/" class="md-nav__link">
<span class="md-ellipsis">
Producer/Consumer mode
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../sql_cheatsheet/" class="md-nav__link">
<span class="md-ellipsis">
SQL Cheat-sheet
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../edge/" class="md-nav__link">
<span class="md-ellipsis">
Edge Positioning
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../faq/" class="md-nav__link">
<span class="md-ellipsis">
FAQ
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../strategy_migration/" class="md-nav__link">
<span class="md-ellipsis">
Strategy migration
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../updating/" class="md-nav__link">
<span class="md-ellipsis">
Updating Freqtrade
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../deprecated/" class="md-nav__link">
<span class="md-ellipsis">
Deprecated Features
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../developer/" class="md-nav__link">
<span class="md-ellipsis">
Contributors Guide
</span>
</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">
<span class="md-ellipsis">
Develop your own strategy
</span>
</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">
<span class="md-ellipsis">
Anatomy of a strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#dataframe" class="md-nav__link">
<span class="md-ellipsis">
Dataframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#customize-indicators" class="md-nav__link">
<span class="md-ellipsis">
Customize Indicators
</span>
</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">
<span class="md-ellipsis">
Indicator libraries
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#strategy-startup-period" class="md-nav__link">
<span class="md-ellipsis">
Strategy startup period
</span>
</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">
<span class="md-ellipsis">
Example
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#entry-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Entry signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#exit-signal-rules" class="md-nav__link">
<span class="md-ellipsis">
Exit signal rules
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#minimal-roi" class="md-nav__link">
<span class="md-ellipsis">
Minimal ROI
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#stoploss" class="md-nav__link">
<span class="md-ellipsis">
Stoploss
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#timeframe" class="md-nav__link">
<span class="md-ellipsis">
Timeframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#can-short" class="md-nav__link">
<span class="md-ellipsis">
Can short
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#metadata-dict" class="md-nav__link">
<span class="md-ellipsis">
Metadata dict
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#imports-necessary-for-a-strategy" class="md-nav__link">
<span class="md-ellipsis">
Imports necessary for a strategy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#strategy-file-loading" class="md-nav__link">
<span class="md-ellipsis">
Strategy file loading
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs" class="md-nav__link">
<span class="md-ellipsis">
Informative Pairs
</span>
</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">
<span class="md-ellipsis">
Get data for non-tradeable pairs
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#informative-pairs-decorator-informative" class="md-nav__link">
<span class="md-ellipsis">
Informative pairs decorator (@informative())
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#merge_informative_pair" class="md-nav__link">
<span class="md-ellipsis">
merge_informative_pair()
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Additional data (DataProvider)
</span>
</a>
<nav class="md-nav" aria-label="Additional data (DataProvider)">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-dataprovider" class="md-nav__link">
<span class="md-ellipsis">
Possible options for DataProvider
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#example-usages" class="md-nav__link">
<span class="md-ellipsis">
Example Usages
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#available_pairs" class="md-nav__link">
<span class="md-ellipsis">
available_pairs
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#current_whitelist" class="md-nav__link">
<span class="md-ellipsis">
current_whitelist()
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#get_pair_dataframepair-timeframe" class="md-nav__link">
<span class="md-ellipsis">
get_pair_dataframe(pair, timeframe)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#get_analyzed_dataframepair-timeframe" class="md-nav__link">
<span class="md-ellipsis">
get_analyzed_dataframe(pair, timeframe)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#orderbookpair-maximum" class="md-nav__link">
<span class="md-ellipsis">
orderbook(pair, maximum)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#tickerpair" class="md-nav__link">
<span class="md-ellipsis">
ticker(pair)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#send-notification" class="md-nav__link">
<span class="md-ellipsis">
Send Notification
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#complete-data-provider-sample" class="md-nav__link">
<span class="md-ellipsis">
Complete Data-provider sample
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-wallets" class="md-nav__link">
<span class="md-ellipsis">
Additional data (Wallets)
</span>
</a>
<nav class="md-nav" aria-label="Additional data (Wallets)">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#possible-options-for-wallets" class="md-nav__link">
<span class="md-ellipsis">
Possible options for Wallets
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#additional-data-trades" class="md-nav__link">
<span class="md-ellipsis">
Additional data (Trades)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#prevent-trades-from-happening-for-a-specific-pair" class="md-nav__link">
<span class="md-ellipsis">
Prevent trades from happening for a specific pair
</span>
</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">
<span class="md-ellipsis">
Locking pairs from within the strategy
</span>
</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">
<span class="md-ellipsis">
Pair locking example
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#print-created-dataframe" class="md-nav__link">
<span class="md-ellipsis">
Print created dataframe
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#common-mistakes-when-developing-strategies" class="md-nav__link">
<span class="md-ellipsis">
Common mistakes when developing strategies
</span>
</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">
<span class="md-ellipsis">
Peeking into the future while backtesting
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#colliding-signals" class="md-nav__link">
<span class="md-ellipsis">
Colliding signals
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#further-strategy-ideas" class="md-nav__link">
<span class="md-ellipsis">
Further strategy ideas
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#next-step" class="md-nav__link">
<span class="md-ellipsis">
Next step
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="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="https://ta-lib.github.io/ta-lib-python/">ta-lib</a></li>
<li><a href="https://twopirllc.github.io/pandas-ta/">pandas-ta</a></li>
<li><a href="https://technical.freqtrade.io">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. In the case where a user includes higher timeframes with informative pairs, the <code>startup_candle_count</code> does not necessarily change. The value is the maximum period (in candles) that any of the informatives timeframes need to compute stable indicators.</p>
<p>You can use <a href="../recursive-analysis/">recursive-analysis</a> to check and find the correct <code>startup_candle_count</code> to be used.</p>
<p>In this example strategy, this should be set to 400 (<code>startup_candle_count = 400</code>), since the minimum needed history for ema100 calculation to make sure the value is correct is 400 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 400, backtesting knows it needs 400 candles to generate valid buy signals. It will load data from <code>20190101 - (400 * 5m)</code> - which is ~2018-12-30 11:40: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-02 09:20: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.
The exit-signal can be suppressed by setting <code>use_exit_signal</code> to false in the configuration or strategy.
<code>use_exit_signal</code> will not influence <a href="#colliding-signals">signal collision rules</a> - which will still apply and can prevent entries.</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 empty dictionary:</p>
<div class="highlight"><pre><span></span><code><span class="n">minimal_roi</span> <span class="o">=</span> <span class="p">{}</span>
</code></pre></div>
<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>
<details class="info">
<summary>Orders that don't fill immediately</summary>
<p><code>minimal_roi</code> will take the <code>trade.open_date</code> as reference, which is the time the trade was initialized / the first order for this trade was placed.<br />
This will also hold true for limit orders that don't fill immediately (usually in combination with "off-spot" prices through <code>custom_entry_price()</code>), as well as for cases where the initial order is replaced through <code>adjust_entry_price()</code>.
The time used will still be from the initial <code>trade.open_date</code> (when the initial order was first placed), not from the newly placed order date.</p>
</details>
<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-persistent">Storing information</a> section.</p>
<h2 id="imports-necessary-for-a-strategy">Imports necessary for a strategy<a class="headerlink" href="#imports-necessary-for-a-strategy" title="Permanent link">&para;</a></h2>
<p>When creating a strategy, you will need to import the necessary modules and classes. The following imports are required for a strategy:</p>
<p>By default, we recommend the following imports as a base line for your strategy:
This will cover all imports necessary for freqtrade functions to work.
Obviously you can add more imports as needed for your strategy.</p>
<div class="highlight"><pre><span></span><code><span class="c1"># flake8: noqa: F401</span>
<span class="c1"># isort: skip_file</span>
<span class="c1"># --- Do not remove these imports ---</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span><span class="p">,</span> <span class="n">timezone</span>
<span class="kn">from</span> <span class="nn">pandas</span> <span class="kn">import</span> <span class="n">DataFrame</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Dict</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="n">Tuple</span>
<span class="kn">from</span> <span class="nn">freqtrade.strategy</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">IStrategy</span><span class="p">,</span>
<span class="n">Trade</span><span class="p">,</span>
<span class="n">Order</span><span class="p">,</span>
<span class="n">PairLocks</span><span class="p">,</span>
<span class="n">informative</span><span class="p">,</span> <span class="c1"># @informative decorator</span>
<span class="c1"># Hyperopt Parameters</span>
<span class="n">BooleanParameter</span><span class="p">,</span>
<span class="n">CategoricalParameter</span><span class="p">,</span>
<span class="n">DecimalParameter</span><span class="p">,</span>
<span class="n">IntParameter</span><span class="p">,</span>
<span class="n">RealParameter</span><span class="p">,</span>
<span class="c1"># timeframe helpers</span>
<span class="n">timeframe_to_minutes</span><span class="p">,</span>
<span class="n">timeframe_to_next_date</span><span class="p">,</span>
<span class="n">timeframe_to_prev_date</span><span class="p">,</span>
<span class="c1"># Strategy helper functions</span>
<span class="n">merge_informative_pair</span><span class="p">,</span>
<span class="n">stoploss_from_absolute</span><span class="p">,</span>
<span class="n">stoploss_from_open</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># --------------------------------</span>
<span class="c1"># Add your lib to import here</span>
<span class="kn">import</span> <span class="nn">talib.abstract</span> <span class="k">as</span> <span class="nn">ta</span>
<span class="kn">from</span> <span class="nn">technical</span> <span class="kn">import</span> <span class="n">qtpylib</span>
</code></pre></div>
<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.
In general, spot pairs cannot be used in futures markets, and futures candles can't be used as informative pairs for spot bots.
Details about this may vary, if they do, 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 (recommended)</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 (only valid for bots running on spot markets).</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 (only bots with `trading_mode=futures`)</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 (only bots with `trading_mode=futures`)</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. Also supports limited pair format strings (see below)</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"> Pair format supports these format variables:</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"> Format string additionally supports this variables.</span>
<span class="sd"> * {asset} - full name of the asset, for example &#39;BTC/USDT&#39;.</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_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;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">_</span><span class="si">{timeframe}</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>
<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>For a full sample, please refer to the <a href="#complete-data-provider-sample">complete data provider example</a> below.</p>
<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>
<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">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-1000 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>
<details class="note">
<summary>Plotting with current_whitelist</summary>
<p>Current whitelist is not supported for <code>plot-dataframe</code>, as this command is usually used by providing an explicit pairlist - and would therefore make the return values of this method misleading.
It's also not supported for freqUI visualization in <a href="../utils/#webserver-mode">webserver mode</a> - as the configuration for webserver mode doesn't require a pairlist to be set.</p>
</details>
<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="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>In backtesting, <code>dp.get_pair_dataframe()</code> behavior differs depending on where it's called.
Within <code>populate_*()</code> methods, <code>dp.get_pair_dataframe()</code> returns the full timerange. Please make sure to not "look into the future" to avoid surprises when running in dry/live mode.
Within <a href="../strategy-callbacks/">callbacks</a>, you'll get the full timerange up to the current (simulated) candle.</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="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.
You can check for this with <code>if dataframe.empty:</code> and handle this case accordingly.
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="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 up-to-date 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="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, some exchanges
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 without runmode checks will lead to wrong results.</p>
</div>
<h3 id="send-notification">Send Notification<a class="headerlink" href="#send-notification" title="Permanent link">&para;</a></h3>
<p>The dataprovider <code>.send_msg()</code> function allows you to send custom notifications from your strategy.
Identical notifications will only be sent once per candle, unless the 2<sup>nd</sup> argument (<code>always_send</code>) is set to True.</p>
<div class="highlight"><pre><span></span><code> <span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">send_msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</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"> just got hot!&quot;</span><span class="p">)</span>
<span class="c1"># Force send this notification, avoid caching (Please read warning below!)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dp</span><span class="o">.</span><span class="n">send_msg</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</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"> just got hot!&quot;</span><span class="p">,</span> <span class="n">always_send</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</code></pre></div>
<p>Notifications will only be sent in trading modes (Live/Dry-run) - so this method can be called without conditions for backtesting.</p>
<div class="admonition warning">
<p class="admonition-title">Spamming</p>
<p>You can spam yourself pretty good by setting <code>always_send=True</code> in this method. Use this with great care and only in conditions you know will not happen throughout a candle to avoid a message every 5 seconds.</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="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">Backtesting / Hyperopt</p>
<p>Wallets behaves differently depending on the function it's called.
Within <code>populate_*()</code> methods, it'll return the full wallet as configured.
Within <a href="../strategy-callbacks/">callbacks</a>, you'll get the wallet state corresponding to the actual simulated wallet at that point in the simulation process.</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="n">trades</span> <span class="o">=</span> <span class="n">Trade</span><span class="o">.</span><span class="n">get_trades_proxy</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">open_date</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">days</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span>
<span class="n">is_open</span><span class="o">=</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>For a full list of available methods, please consult the <a href="../trade-object/">Trade object</a> documentation.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Trade history is not available in <code>populate_*</code> methods during backtesting or hyperopt, and will result in empty results.</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_proxy</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">is_open</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">open_date</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">days</span><span class="o">=</span><span class="mi">2</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> or other negative values. This uses data from the future in backtesting, which is not available in dry or live modes.</li>
<li>don't use <code>.iloc[-1]</code> or any other absolute position in the dataframe within <code>populate_</code> functions, as this will be different between dry-run and backtesting. Absolute <code>iloc</code> indexing is safe to use in callbacks however - see <a href="../strategy-callbacks/">Strategy Callbacks</a>.</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>
<div class="admonition tip">
<p class="admonition-title">Identifying problems</p>
<p>You may also want to check the 2 helper commands <a href="../lookahead-analysis/">lookahead-analysis</a> and <a href="../recursive-analysis/">recursive-analysis</a>, which can each help you figure out problems with your strategy in different ways.
Please treat them as what they are - helpers to identify most common problems. A negative result of each does not guarantee that there's none of the above errors included.</p>
</div>
<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>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg>
Back to top
</button>
</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">
<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 11z"/></svg>
</div>
<div class="md-footer__title">
<span class="md-footer__direction">
Previous
</span>
<div class="md-ellipsis">
Configuration
</div>
</div>
</a>
<a href="../strategy-callbacks/" class="md-footer__link md-footer__link--next" aria-label="Next: Strategy Callbacks">
<div class="md-footer__title">
<span class="md-footer__direction">
Next
</span>
<div class="md-ellipsis">
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 11z"/></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>
</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": ["content.code.annotate", "search.share", "content.code.copy", "navigation.top", "navigation.footer"], "search": "../assets/javascripts/workers/search.6ce7567c.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"alias": true, "provider": "mike"}}</script>
<script src="../assets/javascripts/bundle.525ec568.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>