3360 lines
118 KiB
HTML
3360 lines
118 KiB
HTML
|
|
<!doctype html>
|
|
<html lang="en" class="no-js">
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
|
|
<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="../strategy-101/">
|
|
|
|
|
|
<link rel="next" href="../strategy-callbacks/">
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="icon" href="../images/logo.png">
|
|
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.7.6">
|
|
|
|
|
|
|
|
<title>Strategy Customization - Freqtrade</title>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../assets/stylesheets/main.484c7ddc.min.css">
|
|
|
|
|
|
<link rel="stylesheet" href="../assets/stylesheets/palette.ab4e12ef.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 512 512"><!--! Font Awesome Free 7.1.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 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></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 512 512"><!--! Font Awesome Free 7.1.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 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></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">
|
|
<a href="../installation/" class="md-nav__link">
|
|
|
|
|
|
|
|
<span class="md-ellipsis">
|
|
|
|
|
|
Installation
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
</a>
|
|
</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">
|
|
<a href="../strategy-101/" class="md-nav__link">
|
|
|
|
|
|
|
|
<span class="md-ellipsis">
|
|
|
|
|
|
Strategy Quickstart
|
|
|
|
|
|
|
|
</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="#generating-a-strategy-template" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Generating a strategy template
|
|
|
|
</span>
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<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="#bot-modes" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Bot modes
|
|
|
|
</span>
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</li>
|
|
|
|
<li class="md-nav__item">
|
|
<a href="#diving-in-deeper" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Diving in deeper
|
|
|
|
</span>
|
|
</a>
|
|
|
|
<nav class="md-nav" aria-label="Diving in deeper">
|
|
<ul class="md-nav__list">
|
|
|
|
<li class="md-nav__item">
|
|
<a href="#dataframe" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Dataframe
|
|
|
|
</span>
|
|
</a>
|
|
|
|
<nav class="md-nav" aria-label="Dataframe">
|
|
<ul class="md-nav__list">
|
|
|
|
<li class="md-nav__item">
|
|
<a href="#why-cant-i-see-real-time-candle-data" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Why can't I see "real time" candle data?
|
|
|
|
</span>
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</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>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</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_12" >
|
|
|
|
|
|
<label class="md-nav__link" for="__nav_12" id="__nav_12_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_12_label" aria-expanded="false">
|
|
<label class="md-nav__title" for="__nav_12">
|
|
<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_16" >
|
|
|
|
|
|
<label class="md-nav__link" for="__nav_16" id="__nav_16_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_16_label" aria-expanded="false">
|
|
<label class="md-nav__title" for="__nav_16">
|
|
<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_21" >
|
|
|
|
|
|
<label class="md-nav__link" for="__nav_21" id="__nav_21_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_21_label" aria-expanded="false">
|
|
<label class="md-nav__title" for="__nav_21">
|
|
<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_22" >
|
|
|
|
|
|
<label class="md-nav__link" for="__nav_22" id="__nav_22_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_22_label" aria-expanded="false">
|
|
<label class="md-nav__title" for="__nav_22">
|
|
<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>
|
|
|
|
|
|
|
|
|
|
</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="#generating-a-strategy-template" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Generating a strategy template
|
|
|
|
</span>
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<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="#bot-modes" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Bot modes
|
|
|
|
</span>
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</li>
|
|
|
|
<li class="md-nav__item">
|
|
<a href="#diving-in-deeper" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Diving in deeper
|
|
|
|
</span>
|
|
</a>
|
|
|
|
<nav class="md-nav" aria-label="Diving in deeper">
|
|
<ul class="md-nav__list">
|
|
|
|
<li class="md-nav__item">
|
|
<a href="#dataframe" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Dataframe
|
|
|
|
</span>
|
|
</a>
|
|
|
|
<nav class="md-nav" aria-label="Dataframe">
|
|
<ul class="md-nav__list">
|
|
|
|
<li class="md-nav__item">
|
|
<a href="#why-cant-i-see-real-time-candle-data" class="md-nav__link">
|
|
<span class="md-ellipsis">
|
|
|
|
Why can't I see "real time" candle data?
|
|
|
|
</span>
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</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>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="md-content" data-md-component="content">
|
|
|
|
<article class="md-content__inner md-typeset">
|
|
|
|
|
|
|
|
|
|
|
|
<a href="https://github.com/freqtrade/freqtrade/edit/develop/docs/strategy-customization.md" title="Edit this page" class="md-content__button md-icon" rel="edit">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10 20H6V4h7v5h5v3.1l2-2V8l-6-6H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h4zm10.2-7c.1 0 .3.1.4.2l1.3 1.3c.2.2.2.6 0 .8l-1 1-2.1-2.1 1-1c.1-.1.2-.2.4-.2m0 3.9L14.1 23H12v-2.1l6.1-6.1z"/></svg>
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<h1 id="strategy-customization">Strategy Customization<a class="headerlink" href="#strategy-customization" title="Permanent link">¶</a></h1>
|
|
<p>This page explains how to customize your strategies, add new indicators and set up trading rules.</p>
|
|
<p>If you haven't already, please familiarize yourself with:</p>
|
|
<ul>
|
|
<li>the <a href="../strategy-101/">Freqtrade strategy 101</a>, which provides a quick start to strategy development</li>
|
|
<li>the <a href="../bot-basics/">Freqtrade bot basics</a>, which provides overall info on how the bot operates</li>
|
|
</ul>
|
|
<h2 id="develop-your-own-strategy">Develop your own strategy<a class="headerlink" href="#develop-your-own-strategy" title="Permanent link">¶</a></h2>
|
|
<p>The bot includes a default strategy file.</p>
|
|
<p>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.</p>
|
|
<p>This document intends to help you convert your ideas into a working strategy.</p>
|
|
<h3 id="generating-a-strategy-template">Generating a strategy template<a class="headerlink" href="#generating-a-strategy-template" title="Permanent link">¶</a></h3>
|
|
<p>To get started, you can use the command:</p>
|
|
<p><code>bash
|
|
freqtrade new-strategy --strategy AwesomeStrategy</code></p>
|
|
<p>This will create a new strategy called <code>AwesomeStrategy</code> from a template, which will be located using the filename <code>user_data/strategies/AwesomeStrategy.py</code>.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>There is a difference between the <em>name</em> of the strategy and the filename. In most commands, Freqtrade uses the <em>name</em> of the strategy, <em>not the filename</em>.</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>The <code>new-strategy</code> command generates starting examples which will 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 more complicated features defined.</p>
|
|
</details>
|
|
<h3 id="anatomy-of-a-strategy">Anatomy of a strategy<a class="headerlink" href="#anatomy-of-a-strategy" title="Permanent link">¶</a></h3>
|
|
<p>A strategy file contains all the information needed to build the strategy logic:</p>
|
|
<ul>
|
|
<li>Candle data in OHLCV format</li>
|
|
<li>Indicators</li>
|
|
<li>Entry logic<ul>
|
|
<li>Signals</li>
|
|
</ul>
|
|
</li>
|
|
<li>Exit logic<ul>
|
|
<li>Signals</li>
|
|
<li>Minimal ROI</li>
|
|
<li>Callbacks ("custom functions")</li>
|
|
</ul>
|
|
</li>
|
|
<li>Stoploss<ul>
|
|
<li>Fixed/absolute</li>
|
|
<li>Trailing</li>
|
|
<li>Callbacks ("custom functions")</li>
|
|
</ul>
|
|
</li>
|
|
<li>Pricing [optional]</li>
|
|
<li>Position adjustment [optional]</li>
|
|
</ul>
|
|
<p>The bot includes a sample strategy called <code>SampleStrategy</code> that you can use as a basis: <code>user_data/strategies/sample_strategy.py</code>.
|
|
You can test it with the parameter: <code>--strategy SampleStrategy</code>. Remember that you use the strategy class name, not the filename.</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>You may see older strategies set to interface version 2, and these will need to be updated to v3 terminology as future versions will require this to be set.</p>
|
|
<p>Starting the bot in dry or live mode is accomplished using the <code>trade</code> command:</p>
|
|
<p><code>bash
|
|
freqtrade trade --strategy AwesomeStrategy</code></p>
|
|
<h3 id="bot-modes">Bot modes<a class="headerlink" href="#bot-modes" title="Permanent link">¶</a></h3>
|
|
<p>Freqtrade strategies can be processed by the Freqtrade bot in 5 main modes:</p>
|
|
<ul>
|
|
<li>backtesting</li>
|
|
<li>hyperopting</li>
|
|
<li>dry ("forward testing")</li>
|
|
<li>live</li>
|
|
<li>FreqAI (not covered here)</li>
|
|
</ul>
|
|
<p>Check the <a href="../configuration/">configuration documentation</a> about how to set the bot to dry or live mode.</p>
|
|
<p><strong>Always use dry mode when testing as this gives you an idea of how your strategy will work in reality without risking capital.</strong></p>
|
|
<h2 id="diving-in-deeper">Diving in deeper<a class="headerlink" href="#diving-in-deeper" title="Permanent link">¶</a></h2>
|
|
<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>
|
|
<details class="hint">
|
|
<summary>Lookahead and recursive analysis</summary>
|
|
<p>Freqtrade includes two helpful commands to help assess common lookahead (using future data) and
|
|
recursive bias (variance in indicator values) issues. Before running a strategy in dry or live more,
|
|
you should always use these commands first. Please check the relevant documentation for
|
|
<a href="../lookahead-analysis/">lookahead</a> and <a href="../recursive-analysis/">recursive</a> analysis.</p>
|
|
</details>
|
|
<h3 id="dataframe">Dataframe<a class="headerlink" href="#dataframe" title="Permanent link">¶</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 in tabular format.</p>
|
|
<p>Each row in a dataframe corresponds to one candle on a chart, with the latest complete candle always being the last in the dataframe (sorted by date).</p>
|
|
<p>If we were to look at the first few rows of the main dataframe using the pandas <code>head()</code> function, we would see:</p>
|
|
<p>```output</p>
|
|
<blockquote>
|
|
<p>dataframe.head()
|
|
date open high low close volume
|
|
0 2021-11-09 23:25:00+00:00 67279.67 67321.84 67255.01 67300.97 44.62253
|
|
1 2021-11-09 23:30:00+00:00 67300.97 67301.34 67183.03 67187.01 61.38076
|
|
2 2021-11-09 23:35:00+00:00 67187.02 67187.02 67031.93 67123.81 113.42728
|
|
3 2021-11-09 23:40:00+00:00 67123.80 67222.40 67080.33 67160.48 78.96008
|
|
4 2021-11-09 23:45:00+00:00 67160.48 67160.48 66901.26 66943.37 111.39292
|
|
```</p>
|
|
</blockquote>
|
|
<p>A dataframe is a table where columns are not single values, but a series of data values. As such, simple python comparisons like the following will not work:</p>
|
|
<p><code>python
|
|
if dataframe['rsi'] > 30:
|
|
dataframe['enter_long'] = 1</code></p>
|
|
<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, i.e. <code>vectorisation</code>.</p>
|
|
<p><code>python
|
|
dataframe.loc[
|
|
(dataframe['rsi'] > 30)
|
|
, 'enter_long'] = 1</code></p>
|
|
<p>With this section, you have a new column in your dataframe, which has <code>1</code> assigned whenever RSI is above 30.</p>
|
|
<p>Freqtrade uses this new column as an entry signal, where it is assumed that a trade will subsequently open on the next open candle.</p>
|
|
<p>Pandas provides fast ways to calculate metrics, i.e. "vectorisation". To benefit from this speed, it is 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>
|
|
<details class="hint">
|
|
<summary>Signals vs Trades</summary>
|
|
<ul>
|
|
<li>Signals are generated from indicators at candle close, and are intentions to enter a trade.</li>
|
|
<li>Trades are orders that are executed (on the exchange in live mode) where a trade will then open as close to next candle open as possible.</li>
|
|
</ul>
|
|
</details>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Trade order assumptions</p>
|
|
<p>In backtesting, signals are generated on candle close. Trades are then initiated immeditely on next candle open.</p>
|
|
<p>In dry and live, this may be delayed due to all pair dataframes needing to be analysed first, then trade processing
|
|
for each of those pairs happens. This means that in dry/live you need to be mindful of having as low a computation
|
|
delay as possible, usually by running a low number of pairs and having a CPU with a good clock speed.</p>
|
|
</div>
|
|
<h4 id="why-cant-i-see-real-time-candle-data">Why can't I see "real time" candle data?<a class="headerlink" href="#why-cant-i-see-real-time-candle-data" title="Permanent link">¶</a></h4>
|
|
<p>Freqtrade does not store incomplete/unfinished candles in the dataframe.</p>
|
|
<p>The use of incomplete data for making strategy decisions is called "repainting" and you might see other platforms allow this.</p>
|
|
<p>Freqtrade does not. Only complete/finished candle data is available in the dataframe.</p>
|
|
<h3 id="customize-indicators">Customize Indicators<a class="headerlink" href="#customize-indicators" title="Permanent link">¶</a></h3>
|
|
<p>Entry and exit 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 from these three functions without removing/modifying the columns <code>"open", "high", "low", "close", "volume"</code>, otherwise these fields would contain something unexpected.</p>
|
|
<p>Sample:</p>
|
|
<p>```python
|
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
"""
|
|
Adds several different TA indicators to the given DataFrame</p>
|
|
<div class="codehilite"><pre><span></span><code>Performance Note: For the best performance be frugal on the number of indicators
|
|
you are using. Let uncomment only the indicator you are using in your strategies
|
|
or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
|
|
:param dataframe: Dataframe with data from the exchange
|
|
:param metadata: Additional information, like the currently traded pair
|
|
:return: a Dataframe with all mandatory indicators for the strategies
|
|
"""
|
|
dataframe['sar'] = ta.SAR(dataframe)
|
|
dataframe['adx'] = ta.ADX(dataframe)
|
|
stoch = ta.STOCHF(dataframe)
|
|
dataframe['fastd'] = stoch['fastd']
|
|
dataframe['fastk'] = stoch['fastk']
|
|
dataframe['bb_lower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband']
|
|
dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)
|
|
dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
|
|
dataframe['mfi'] = ta.MFI(dataframe)
|
|
dataframe['rsi'] = ta.RSI(dataframe)
|
|
dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
|
|
dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
|
|
dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
|
|
dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
|
|
dataframe['ao'] = awesome_oscillator(dataframe)
|
|
macd = ta.MACD(dataframe)
|
|
dataframe['macd'] = macd['macd']
|
|
dataframe['macdsignal'] = macd['macdsignal']
|
|
dataframe['macdhist'] = macd['macdhist']
|
|
hilbert = ta.HT_SINE(dataframe)
|
|
dataframe['htsine'] = hilbert['sine']
|
|
dataframe['htleadsine'] = hilbert['leadsine']
|
|
dataframe['plus_dm'] = ta.PLUS_DM(dataframe)
|
|
dataframe['plus_di'] = ta.PLUS_DI(dataframe)
|
|
dataframe['minus_dm'] = ta.MINUS_DM(dataframe)
|
|
dataframe['minus_di'] = ta.MINUS_DI(dataframe)
|
|
|
|
# remember to always return the dataframe
|
|
return dataframe
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<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">¶</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">¶</a></h3>
|
|
<p>Some indicators have an unstable startup period in which there isn't enough candle data to calculate any values (NaN), or the calculation is incorrect. This can lead to inconsistencies, since Freqtrade does not know how long this unstable period is and uses whatever indicator values are in the dataframe.</p>
|
|
<p>To account for this, the strategy can be assigned the <code>startup_candle_count</code> attribute.</p>
|
|
<p>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. When recursive analysis shows a variance of 0%, then you can be sure that you have enough startup candle data.</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>
|
|
<p><code>python
|
|
dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)</code></p>
|
|
<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">¶</a></h4>
|
|
<p>Let's try to backtest 1 month (January 2019) of 5m candles using an example strategy with EMA100, as above.</p>
|
|
<p><code>bash
|
|
freqtrade backtesting --timerange 20190101-20190201 --timeframe 5m</code></p>
|
|
<p>Assuming <code>startup_candle_count</code> is set to 400, backtesting knows it needs 400 candles to generate valid entry signals. It will load data from <code>20190101 - (400 * 5m)</code> - which is ~2018-12-30 11:40:00.</p>
|
|
<p>If this data is available, indicators will be calculated with this extended timerange. The unstable startup period (up to 2019-01-01 00:00:00) will then be removed before backtesting is carried out.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Unavailable startup candle data</p>
|
|
<p>If data for the startup period is not available, then the timerange will be adjusted to account for this startup period. In our example, backtesting would then start from 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">¶</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. The strategy may then produce invalid values, or cease to work entirely.</p>
|
|
<p>This method will also define a new column, <code>"enter_long"</code> (<code>"enter_short"</code> for shorts), which needs to contain <code>1</code> for entries, and <code>0</code> for "no action". <code>enter_long</code> is a mandatory column that must be set even if the strategy is shorting only.</p>
|
|
<p>You can name your entry signals by using the <code>"enter_tag"</code> column, which can help debug and assess your strategy later.</p>
|
|
<p>Sample from <code>user_data/strategies/sample_strategy.py</code>:</p>
|
|
<p>```python
|
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
"""
|
|
Based on TA indicators, populates the buy signal for the given dataframe
|
|
:param dataframe: DataFrame populated with indicators
|
|
:param metadata: Additional information, like the currently traded pair
|
|
:return: DataFrame with buy column
|
|
"""
|
|
dataframe.loc[
|
|
(
|
|
(qtpylib.crossed_above(dataframe['rsi'], 30)) & # Signal: RSI crosses above 30
|
|
(dataframe['tema'] <= dataframe['bb_middleband']) & # Guard
|
|
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
|
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
),
|
|
['enter_long', 'enter_tag']] = (1, 'rsi_cross')</p>
|
|
<div class="codehilite"><pre><span></span><code>return dataframe
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<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.
|
|
Shorting needs to be supported by your exchange and market configuration!
|
|
Also, make sure you set <a href="#can-short"><code>can_short</code></a> appropriately on your strategy if you intend to short.</p>
|
|
<p>```python</p>
|
|
<h1 id="allow-both-long-and-short-trades">allow both long and short trades<a class="headerlink" href="#allow-both-long-and-short-trades" title="Permanent link">¶</a></h1>
|
|
<p>can_short = True</p>
|
|
<p>def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe.loc[
|
|
(
|
|
(qtpylib.crossed_above(dataframe['rsi'], 30)) & # Signal: RSI crosses above 30
|
|
(dataframe['tema'] <= dataframe['bb_middleband']) & # Guard
|
|
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
|
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
),
|
|
['enter_long', 'enter_tag']] = (1, 'rsi_cross')</p>
|
|
<div class="codehilite"><pre><span></span><code>dataframe.loc[
|
|
(
|
|
(qtpylib.crossed_below(dataframe['rsi'], 70)) & # Signal: RSI crosses below 70
|
|
(dataframe['tema'] > dataframe['bb_middleband']) & # Guard
|
|
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
|
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
),
|
|
['enter_short', 'enter_tag']] = (1, 'rsi_cross')
|
|
|
|
return dataframe
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
</details>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>Buying requires sellers to buy from. Therefore volume needs to be > 0 (<code>dataframe['volume'] > 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">¶</a></h3>
|
|
<p>Edit the method <code>populate_exit_trend()</code> into your strategy file to update your exit strategy.</p>
|
|
<p>The exit-signal can be suppressed by setting <code>use_exit_signal</code> to false in the configuration or strategy.</p>
|
|
<p><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. The strategy may then produce invalid values, or cease to work entirely.</p>
|
|
<p>This method will also define a new column, <code>"exit_long"</code> (<code>"exit_short"</code> for shorts), which needs to contain <code>1</code> for exits, and <code>0</code> for "no action".</p>
|
|
<p>You can name your exit signals by using the <code>"exit_tag"</code> column, which can help debug and assess your strategy later.</p>
|
|
<p>Sample from <code>user_data/strategies/sample_strategy.py</code>:</p>
|
|
<p><code>python
|
|
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
"""
|
|
Based on TA indicators, populates the exit signal for the given dataframe
|
|
:param dataframe: DataFrame populated with indicators
|
|
:param metadata: Additional information, like the currently traded pair
|
|
:return: DataFrame with buy column
|
|
"""
|
|
dataframe.loc[
|
|
(
|
|
(qtpylib.crossed_above(dataframe['rsi'], 70)) & # Signal: RSI crosses above 70
|
|
(dataframe['tema'] > dataframe['bb_middleband']) & # Guard
|
|
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
|
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
),
|
|
['exit_long', 'exit_tag']] = (1, 'rsi_too_high')
|
|
return dataframe</code></p>
|
|
<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.
|
|
Shorting needs to be supported by your exchange and market configuration!
|
|
Also, make sure you set <a href="#can-short"><code>can_short</code></a> appropriately on your strategy if you intend to short.</p>
|
|
<p>```python</p>
|
|
<h1 id="allow-both-long-and-short-trades_1">allow both long and short trades<a class="headerlink" href="#allow-both-long-and-short-trades_1" title="Permanent link">¶</a></h1>
|
|
<p>can_short = True</p>
|
|
<p>def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe.loc[
|
|
(
|
|
(qtpylib.crossed_above(dataframe['rsi'], 70)) & # Signal: RSI crosses above 70
|
|
(dataframe['tema'] > dataframe['bb_middleband']) & # Guard
|
|
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard
|
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
),
|
|
['exit_long', 'exit_tag']] = (1, 'rsi_too_high')
|
|
dataframe.loc[
|
|
(
|
|
(qtpylib.crossed_below(dataframe['rsi'], 30)) & # Signal: RSI crosses below 30
|
|
(dataframe['tema'] < dataframe['bb_middleband']) & # Guard
|
|
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard
|
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
|
),
|
|
['exit_short', 'exit_tag']] = (1, 'rsi_too_low')
|
|
return dataframe
|
|
```</p>
|
|
</details>
|
|
<h3 id="minimal-roi">Minimal ROI<a class="headerlink" href="#minimal-roi" title="Permanent link">¶</a></h3>
|
|
<p>The <code>minimal_roi</code> strategy variable 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, i.e. a python <code>dict</code>, 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>
|
|
<p><code>python
|
|
minimal_roi = {
|
|
"40": 0.0,
|
|
"30": 0.01,
|
|
"20": 0.02,
|
|
"0": 0.04
|
|
}</code></p>
|
|
<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>
|
|
<h4 id="disabling-minimal-roi">Disabling minimal ROI<a class="headerlink" href="#disabling-minimal-roi" title="Permanent link">¶</a></h4>
|
|
<p>To disable ROI completely, set it to an empty dictionary:</p>
|
|
<p><code>python
|
|
minimal_roi = {}</code></p>
|
|
<h4 id="using-calculations-in-minimal-roi">Using calculations in minimal ROI<a class="headerlink" href="#using-calculations-in-minimal-roi" title="Permanent link">¶</a></h4>
|
|
<p>To use times based on candle duration (timeframe), the following snippet can be handy.</p>
|
|
<p>This will allow you to change the timeframe for the strategy, but the minimal ROI times will still be set as candles, e.g. after 3 candles.</p>
|
|
<p>``` python
|
|
from freqtrade.exchange import timeframe_to_minutes</p>
|
|
<p>class AwesomeStrategy(IStrategy):</p>
|
|
<div class="codehilite"><pre><span></span><code>timeframe = "1d"
|
|
timeframe_mins = timeframe_to_minutes(timeframe)
|
|
minimal_roi = {
|
|
"0": 0.05, # 5% for the first 3 candles
|
|
str(timeframe_mins * 3): 0.02, # 2% after 3 candles
|
|
str(timeframe_mins * 6): 0.01, # 1% After 6 candles
|
|
}
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<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, i.e. when the first order for this trade was placed.
|
|
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 price 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 or adjusted order date.</p>
|
|
</details>
|
|
<h3 id="stoploss">Stoploss<a class="headerlink" href="#stoploss" title="Permanent link">¶</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>
|
|
<p><code>python
|
|
stoploss = -0.10</code></p>
|
|
<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">¶</a></h3>
|
|
<p>This is the periodicity of candles the bot should use in the strategy.</p>
|
|
<p>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 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">¶</a></h3>
|
|
<p>To use short signals in futures markets, you will have to set <code>can_short = True</code>.</p>
|
|
<p>Strategies which enable this will fail to load on spot markets.</p>
|
|
<p>If you have <code>1</code> values in the <code>enter_short</code> column to raise short signals, setting <code>can_short = False</code> (which is the default) will mean that these short signals are ignored, even if you have specified futures markets in your configuration.</p>
|
|
<h3 id="metadata-dict">Metadata dict<a class="headerlink" href="#metadata-dict" title="Permanent link">¶</a></h3>
|
|
<p>The <code>metadata</code> 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> (or <code>XRP/BTC:BTC</code> for futures markets).</p>
|
|
<p>The metadata dict should not be modified and does not persist information across multiple functions in your strategy.</p>
|
|
<p>Instead, please check 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">¶</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>
|
|
<p>``` python</p>
|
|
<h1 id="flake8-noqa-f401">flake8: noqa: F401<a class="headerlink" href="#flake8-noqa-f401" title="Permanent link">¶</a></h1>
|
|
<h1 id="isort-skip_file">isort: skip_file<a class="headerlink" href="#isort-skip_file" title="Permanent link">¶</a></h1>
|
|
<h1 id="-do-not-remove-these-imports-">--- Do not remove these imports ---<a class="headerlink" href="#-do-not-remove-these-imports-" title="Permanent link">¶</a></h1>
|
|
<p>import numpy as np
|
|
import pandas as pd
|
|
from datetime import datetime, timedelta, timezone
|
|
from pandas import DataFrame
|
|
from typing import Dict, Optional, Union, Tuple</p>
|
|
<p>from freqtrade.strategy import (
|
|
IStrategy,
|
|
Trade,
|
|
Order,
|
|
PairLocks,
|
|
informative, # @informative decorator
|
|
# Hyperopt Parameters
|
|
BooleanParameter,
|
|
CategoricalParameter,
|
|
DecimalParameter,
|
|
IntParameter,
|
|
RealParameter,
|
|
# timeframe helpers
|
|
timeframe_to_minutes,
|
|
timeframe_to_next_date,
|
|
timeframe_to_prev_date,
|
|
# Strategy helper functions
|
|
merge_informative_pair,
|
|
stoploss_from_absolute,
|
|
stoploss_from_open,
|
|
)</p>
|
|
<h1 id="-">--------------------------------<a class="headerlink" href="#-" title="Permanent link">¶</a></h1>
|
|
<h1 id="add-your-lib-to-import-here">Add your lib to import here<a class="headerlink" href="#add-your-lib-to-import-here" title="Permanent link">¶</a></h1>
|
|
<p>import talib.abstract as ta
|
|
from technical import qtpylib
|
|
```</p>
|
|
<h2 id="strategy-file-loading">Strategy file loading<a class="headerlink" href="#strategy-file-loading" title="Permanent link">¶</a></h2>
|
|
<p>By default, freqtrade will attempt to load strategies from all <code>.py</code> files within the <code>userdir</code> (default <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 in dry (or live, depending on your configuration) mode with:</p>
|
|
<p><code>bash
|
|
freqtrade trade --strategy AwesomeStrategy</code></p>
|
|
<p>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">¶</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">¶</a></h3>
|
|
<p>Data for additional, informative pairs (reference pairs) can be beneficial for some strategies to see data on a wider timeframe.</p>
|
|
<p>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).</p>
|
|
<p>These pairs will <strong>not</strong> be traded unless they are also specified in the pair whitelist, or have been selected by Dynamic Whitelisting, e.g. <code>VolumePairlist</code>.</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>
|
|
<p><code>python
|
|
def informative_pairs(self):
|
|
return [("ETH/USDT", "5m"),
|
|
("BTC/TUSD", "15m"),
|
|
]</code></p>
|
|
<p>A full sample can be found <a href="#complete-dataprovider-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>
|
|
<p><code>python
|
|
def informative_pairs(self):
|
|
return [
|
|
("ETH/USDT", "5m", ""), # Uses default candletype, depends on trading_mode (recommended)
|
|
("ETH/USDT", "5m", "spot"), # Forces usage of spot candles (only valid for bots running on spot markets).
|
|
("BTC/TUSD", "15m", "futures"), # Uses futures candles (only bots with `trading_mode=futures`)
|
|
("BTC/TUSD", "15m", "mark"), # Uses mark candles (only bots with `trading_mode=futures`)
|
|
]</code></p>
|
|
</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">¶</a></h3>
|
|
<p>To easily define informative pairs, use the <code>@informative</code> decorator. All decorated <code>populate_indicators_*</code> methods run in isolation,
|
|
and do not have access to data from other informative pairs. However, all informative dataframes for each pair are merged and passed to main <code>populate_indicators()</code> method.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>Do not use the <code>@informative</code> decorator if you need to use data from one informative pair when generating another informative pair. Instead, define informative pairs manually as described <a href="#complete-dataprovider-sample">in the DataProvider section</a>.</p>
|
|
</div>
|
|
<p>When hyperopting, use of the hyperoptable parameter <code>.value</code> attribute is not supported. Please use the <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>
|
|
<p>``` python
|
|
def informative(
|
|
timeframe: str,
|
|
asset: str = "",
|
|
fmt: str | Callable[[Any], str] | None = None,
|
|
*,
|
|
candle_type: CandleType | str | None = None,
|
|
ffill: bool = True,
|
|
) -> Callable[[PopulateIndicators], PopulateIndicators]:
|
|
"""
|
|
A decorator for populate_indicators_Nn(self, dataframe, metadata), allowing these functions to
|
|
define informative indicators.</p>
|
|
<div class="codehilite"><pre><span></span><code>Example usage:
|
|
|
|
@informative('1h')
|
|
def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
return dataframe
|
|
|
|
:param timeframe: Informative timeframe. Must always be equal or higher than strategy timeframe.
|
|
:param asset: Informative asset, for example BTC, BTC/USDT, ETH/BTC. Do not specify to use
|
|
current pair. Also supports limited pair format strings (see below)
|
|
:param fmt: Column format (str) or column formatter (callable(name, asset, timeframe)). When not
|
|
specified, defaults to:
|
|
* {base}_{quote}_{column}_{timeframe} if asset is specified.
|
|
* {column}_{timeframe} if asset is not specified.
|
|
Pair format supports these format variables:
|
|
* {base} - base currency in lower case, for example 'eth'.
|
|
* {BASE} - same as {base}, except in upper case.
|
|
* {quote} - quote currency in lower case, for example 'usdt'.
|
|
* {QUOTE} - same as {quote}, except in upper case.
|
|
Format string additionally supports this variables.
|
|
* {asset} - full name of the asset, for example 'BTC/USDT'.
|
|
* {column} - name of dataframe column.
|
|
* {timeframe} - timeframe of informative dataframe.
|
|
:param ffill: ffill dataframe after merging informative pair.
|
|
:param candle_type: '', mark, index, premiumIndex, or funding_rate
|
|
"""
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
</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>
|
|
<p>``` python</p>
|
|
<p>from datetime import datetime
|
|
from freqtrade.persistence import Trade
|
|
from freqtrade.strategy import IStrategy, informative</p>
|
|
<p>class AwesomeStrategy(IStrategy):</p>
|
|
<div class="codehilite"><pre><span></span><code># This method is not required.
|
|
# def informative_pairs(self): ...
|
|
|
|
# Define informative upper timeframe for each pair. Decorators can be stacked on same
|
|
# method. Available in populate_indicators as 'rsi_30m' and 'rsi_1h'.
|
|
@informative('30m')
|
|
@informative('1h')
|
|
def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
return dataframe
|
|
|
|
# Define BTC/STAKE informative pair. Available in populate_indicators and other methods as
|
|
# 'btc_rsi_1h'. Current stake currency should be specified as {stake} format variable
|
|
# instead of hard-coding actual stake currency. Available in populate_indicators and other
|
|
# methods as 'btc_usdt_rsi_1h' (when stake currency is USDT).
|
|
@informative('1h', 'BTC/{stake}')
|
|
def populate_indicators_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
return dataframe
|
|
|
|
# Define BTC/ETH informative pair. You must specify quote currency if it is different from
|
|
# stake currency. Available in populate_indicators and other methods as 'eth_btc_rsi_1h'.
|
|
@informative('1h', 'ETH/BTC')
|
|
def populate_indicators_eth_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
return dataframe
|
|
|
|
# Define BTC/STAKE informative pair. A custom formatter may be specified for formatting
|
|
# column names. A callable `fmt(**kwargs) -> str` may be specified, to implement custom
|
|
# formatting. Available in populate_indicators and other methods as 'rsi_upper_1h'.
|
|
@informative('1h', 'BTC/{stake}', '{column}_{timeframe}')
|
|
def populate_indicators_btc_1h_2(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe['rsi_upper'] = ta.RSI(dataframe, timeperiod=14)
|
|
return dataframe
|
|
|
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
# Strategy timeframe indicators for current pair.
|
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
# Informative pairs are available in this method.
|
|
dataframe['rsi_less'] = dataframe['rsi'] < dataframe['rsi_1h']
|
|
return dataframe
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
</details>
|
|
<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>
|
|
<p>``` python
|
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
stake = self.config['stake_currency']
|
|
dataframe.loc[
|
|
(
|
|
(dataframe[f'btc_{stake}_rsi_1h'] < 35)
|
|
&
|
|
(dataframe['volume'] > 0)
|
|
),
|
|
['enter_long', 'enter_tag']] = (1, 'buy_signal_rsi')</p>
|
|
<div class="codehilite"><pre><span></span><code>return dataframe
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<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 the <code>@informative()</code> decorator must always have unique names! Reusing the same name (for example when copy-pasting already defined informative methods) will overwrite previously defined methods and not produce any errors due to limitations of Python programming language. In such cases you will find that indicators created in methods higher up in the strategy file 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">¶</a></h3>
|
|
<p>This method helps you merge an informative pair to the regular main dataframe safely and consistently, without lookahead bias.</p>
|
|
<p>Options:</p>
|
|
<ul>
|
|
<li>Rename the columns 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-dataprovider-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>
|
|
<p><code>python
|
|
'date', 'open', 'high', 'low', 'close', 'rsi' # from the original dataframe
|
|
'date_1d', 'open_1d', 'high_1d', 'low_1d', 'close_1d', 'rsi_1d' # from the informative dataframe</code></p>
|
|
</div>
|
|
<details class="example">
|
|
<summary>Column renaming - 1h</summary>
|
|
<p>Assuming <code>inf_tf = '1h'</code> the resulting columns will be:</p>
|
|
<p><code>python
|
|
'date', 'open', 'high', 'low', 'close', 'rsi' # from the original dataframe
|
|
'date_1h', 'open_1h', 'high_1h', 'low_1h', 'close_1h', 'rsi_1h' # from the informative dataframe</code></p>
|
|
</details>
|
|
<details class="example">
|
|
<summary>Custom implementation</summary>
|
|
<p>A custom implementation for this is possible, and can be done as follows:</p>
|
|
<p>``` python</p>
|
|
<h1 id="shift-date-by-1-candle">Shift date by 1 candle<a class="headerlink" href="#shift-date-by-1-candle" title="Permanent link">¶</a></h1>
|
|
<h1 id="this-is-necessary-since-the-data-is-always-the-open-date">This is necessary since the data is always the "open date"<a class="headerlink" href="#this-is-necessary-since-the-data-is-always-the-open-date" title="Permanent link">¶</a></h1>
|
|
<h1 id="and-a-15m-candle-starting-at-1215-should-not-know-the-close-of-the-1h-candle-from-1200-to-1300">and a 15m candle starting at 12:15 should not know the close of the 1h candle from 12:00 to 13:00<a class="headerlink" href="#and-a-15m-candle-starting-at-1215-should-not-know-the-close-of-the-1h-candle-from-1200-to-1300" title="Permanent link">¶</a></h1>
|
|
<p>minutes = timeframe_to_minutes(inf_tf)</p>
|
|
<h1 id="only-do-this-if-the-timeframes-are-different">Only do this if the timeframes are different:<a class="headerlink" href="#only-do-this-if-the-timeframes-are-different" title="Permanent link">¶</a></h1>
|
|
<p>informative['date_merge'] = informative["date"] + pd.to_timedelta(minutes, 'm')</p>
|
|
<h1 id="rename-columns-to-be-unique">Rename columns to be unique<a class="headerlink" href="#rename-columns-to-be-unique" title="Permanent link">¶</a></h1>
|
|
<p>informative.columns = [f"{col}_{inf_tf}" for col in informative.columns]</p>
|
|
<h1 id="assuming-inf_tf-1d-then-the-columns-will-now-be">Assuming inf_tf = '1d' - then the columns will now be:<a class="headerlink" href="#assuming-inf_tf-1d-then-the-columns-will-now-be" title="Permanent link">¶</a></h1>
|
|
<h1 id="date_1d-open_1d-high_1d-low_1d-close_1d-rsi_1d">date_1d, open_1d, high_1d, low_1d, close_1d, rsi_1d<a class="headerlink" href="#date_1d-open_1d-high_1d-low_1d-close_1d-rsi_1d" title="Permanent link">¶</a></h1>
|
|
<h1 id="combine-the-2-dataframes">Combine the 2 dataframes<a class="headerlink" href="#combine-the-2-dataframes" title="Permanent link">¶</a></h1>
|
|
<h1 id="all-indicators-on-the-informative-sample-must-be-calculated-before-this-point">all indicators on the informative sample MUST be calculated before this point<a class="headerlink" href="#all-indicators-on-the-informative-sample-must-be-calculated-before-this-point" title="Permanent link">¶</a></h1>
|
|
<p>dataframe = pd.merge(dataframe, informative, left_on='date', right_on=f'date_merge_{inf_tf}', how='left')</p>
|
|
<h1 id="ffill-to-have-the-1d-value-available-in-every-row-throughout-the-day">FFill to have the 1d value available in every row throughout the day.<a class="headerlink" href="#ffill-to-have-the-1d-value-available-in-every-row-throughout-the-day" title="Permanent link">¶</a></h1>
|
|
<h1 id="without-this-comparisons-would-only-work-once-per-day">Without this, comparisons would only work once per day.<a class="headerlink" href="#without-this-comparisons-would-only-work-once-per-day" title="Permanent link">¶</a></h1>
|
|
<p>dataframe = dataframe.ffill()</p>
|
|
<p>```</p>
|
|
</details>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Informative timeframe < timeframe</p>
|
|
<p>Using informative timeframes smaller than the main 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 this documentation).</p>
|
|
</div>
|
|
<h2 id="additional-data-dataprovider">Additional data (DataProvider)<a class="headerlink" href="#additional-data-dataprovider" title="Permanent link">¶</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, i.e. failures do not raise an exception.</p>
|
|
<p>Please always check the mode of operation to select the correct method to get data (see below for examples).</p>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Hyperopt Limitations</p>
|
|
<p>The DataProvider is available during hyperopt, however it can only be used in <code>populate_indicators()</code> <strong>within a strategy</strong>, not within a hyperopt class file.
|
|
It is also not available in <code>populate_entry_trend()</code> and <code>populate_exit_trend()</code> methods.</p>
|
|
</div>
|
|
<h3 id="possible-options-for-dataprovider">Possible options for DataProvider<a class="headerlink" href="#possible-options-for-dataprovider" title="Permanent link">¶</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><a href="#check_delistingpair"><code>check_delisting(pair)</code></a> - Return Datetime of the pair delisting schedule if any, otherwise return None</li>
|
|
<li><a href="#funding_ratepair"><code>funding_rate(pair)</code></a> - Returns current funding rate data for the pair.</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">¶</a></h3>
|
|
<h3 id="available_pairs"><em>available_pairs</em><a class="headerlink" href="#available_pairs" title="Permanent link">¶</a></h3>
|
|
<p><code>python
|
|
for pair, timeframe in self.dp.available_pairs:
|
|
print(f"available {pair}, {timeframe}")</code></p>
|
|
<h3 id="current_whitelist"><em>current_whitelist()</em><a class="headerlink" href="#current_whitelist" title="Permanent link">¶</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 exchange pairs by volume.</p>
|
|
<p>The strategy logic 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 enter and exit.</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 users 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! We have a problem!</p>
|
|
<p>This is where calling <code>self.dp.current_whitelist()</code> comes in handy to retrieve only those pairs in the whitelist.</p>
|
|
<p>```python
|
|
def informative_pairs(self):</p>
|
|
<div class="codehilite"><pre><span></span><code> # get access to all pairs available in whitelist.
|
|
pairs = self.dp.current_whitelist()
|
|
# Assign timeframe to each pair so they can be downloaded and cached for strategy.
|
|
informative_pairs = [(pair, '1d') for pair in pairs]
|
|
return informative_pairs
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<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">¶</a></h3>
|
|
<p>``` python</p>
|
|
<h1 id="fetch-live-historical-candle-ohlcv-data-for-the-first-informative-pair">fetch live / historical candle (OHLCV) data for the first informative pair<a class="headerlink" href="#fetch-live-historical-candle-ohlcv-data-for-the-first-informative-pair" title="Permanent link">¶</a></h1>
|
|
<p>inf_pair, inf_timeframe = self.informative_pairs()[0]
|
|
informative = self.dp.get_pair_dataframe(pair=inf_pair,
|
|
timeframe=inf_timeframe)
|
|
```</p>
|
|
<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">¶</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>
|
|
<p>``` python</p>
|
|
<h1 id="fetch-current-dataframe">fetch current dataframe<a class="headerlink" href="#fetch-current-dataframe" title="Permanent link">¶</a></h1>
|
|
<p>dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=metadata['pair'],
|
|
timeframe=self.timeframe)
|
|
```</p>
|
|
<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">¶</a></h3>
|
|
<p>Retrieve the current order book for a pair.</p>
|
|
<p><code>python
|
|
if self.dp.runmode.value in ('live', 'dry_run'):
|
|
ob = self.dp.orderbook(metadata['pair'], 1)
|
|
dataframe['best_bid'] = ob['bids'][0][0]
|
|
dataframe['best_ask'] = ob['asks'][0][0]</code></p>
|
|
<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 be formatted as follows:</p>
|
|
<p><code>js
|
|
{
|
|
'bids': [
|
|
[ price, amount ], // [ float, float ]
|
|
[ price, amount ],
|
|
...
|
|
],
|
|
'asks': [
|
|
[ price, amount ],
|
|
[ price, amount ],
|
|
//...
|
|
],
|
|
//...
|
|
}</code></p>
|
|
<p>Therefore, using <code>ob['bids'][0][0]</code> as demonstrated above will use 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">¶</a></h3>
|
|
<p><code>python
|
|
if self.dp.runmode.value in ('live', 'dry_run'):
|
|
ticker = self.dp.ticker(metadata['pair'])
|
|
dataframe['last_price'] = ticker['last']
|
|
dataframe['volume24h'] = ticker['quoteVolume']
|
|
dataframe['vwap'] = ticker['vwap']</code></p>
|
|
<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, and some exchanges
|
|
do not always fill 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 / real-time values. As such, usage during backtesting / hyperopt without runmode checks will lead to wrong results, e.g. your whole dataframe will contain the same single value in all rows.</p>
|
|
</div>
|
|
<h3 id="check_delistingpair"><em>check_delisting(pair)</em><a class="headerlink" href="#check_delistingpair" title="Permanent link">¶</a></h3>
|
|
<p><code>python
|
|
def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs):
|
|
if self.dp.runmode.value in ('live', 'dry_run'):
|
|
delisting_dt = self.dp.check_delisting(pair)
|
|
if delisting_dt is not None:
|
|
return "delist"</code></p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Availabiity of delisting information</p>
|
|
<p>This method is only available for certain exchanges and will return <code>None</code> in cases this is not available or if the pair is not scheduled for delisting.</p>
|
|
</div>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning about backtesting</p>
|
|
<p>This method will always return up-to-date / real-time values. As such, usage during backtesting / hyperopt without runmode checks will lead to wrong results, e.g. your whole dataframe will contain the same single value in all rows.</p>
|
|
</div>
|
|
<h3 id="funding_ratepair"><em>funding_rate(pair)</em><a class="headerlink" href="#funding_ratepair" title="Permanent link">¶</a></h3>
|
|
<p>Retrieves the current funding rate for the pair and only works for futures pairs in the format of <code>base/quote:settle</code> (e.g. <code>ETH/USDT:USDT</code>).</p>
|
|
<p><code>python
|
|
if self.dp.runmode.value in ('live', 'dry_run'):
|
|
funding_rate = self.dp.funding_rate(metadata['pair'])
|
|
dataframe['current_funding_rate'] = funding_rate['fundingRate']
|
|
dataframe['next_funding_timestamp'] = funding_rate['fundingTimestamp']
|
|
dataframe['next_funding_datetime'] = funding_rate['fundingDatetime']</code></p>
|
|
<p>The funding rate structure is aligned with the funding rate structure from <a href="https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-structure">ccxt</a>, so the result will be formatted as follows:</p>
|
|
<p><code>python
|
|
{
|
|
"info": {
|
|
# ...
|
|
},
|
|
"symbol": "BTC/USDT:USDT",
|
|
"markPrice": 110730.7,
|
|
"indexPrice": 110782.52,
|
|
"interestRate": 0.0001,
|
|
"estimatedSettlePrice": 110822.67200153,
|
|
"timestamp": 1757146321001,
|
|
"datetime": "2025-09-06T08:12:01.001Z",
|
|
"fundingRate": 5.609e-05,
|
|
"fundingTimestamp": 1757174400000,
|
|
"fundingDatetime": "2025-09-06T16:00:00.000Z",
|
|
"nextFundingRate": None,
|
|
"nextFundingTimestamp": None,
|
|
"nextFundingDatetime": None,
|
|
"previousFundingRate": None,
|
|
"previousFundingTimestamp": None,
|
|
"previousFundingDatetime": None,
|
|
"interval": None,
|
|
}</code></p>
|
|
<p>Therefore, using <code>funding_rate['fundingRate']</code> as demonstrated above will use the current funding rate.
|
|
Actually available data will vary between exchanges, so this code may not work as expected across exchanges.</p>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning about backtesting</p>
|
|
<p>Current funding-rate 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.
|
|
We recommend to use the historically available funding rate for backtesting (which is automatically downloaded, and is at the frequency of what the exchange provides, usually 4h or 8h).
|
|
<code>self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe='8h', candle_type="funding_rate")</code></p>
|
|
</div>
|
|
<h3 id="send-notification">Send Notification<a class="headerlink" href="#send-notification" title="Permanent link">¶</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>
|
|
<p>``` python
|
|
self.dp.send_msg(f"{metadata['pair']} just got hot!")</p>
|
|
<div class="codehilite"><pre><span></span><code># Force send this notification, avoid caching (Please read warning below!)
|
|
self.dp.send_msg(f"{metadata['pair']} just got hot!", always_send=True)
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<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-dataprovider-sample">Complete DataProvider sample<a class="headerlink" href="#complete-dataprovider-sample" title="Permanent link">¶</a></h3>
|
|
<p>```python
|
|
from freqtrade.strategy import IStrategy, merge_informative_pair
|
|
from pandas import DataFrame</p>
|
|
<p>class SampleStrategy(IStrategy):
|
|
# strategy init stuff...</p>
|
|
<div class="codehilite"><pre><span></span><code>timeframe = '5m'
|
|
|
|
# more strategy init stuff..
|
|
|
|
def informative_pairs(self):
|
|
|
|
# get access to all pairs available in whitelist.
|
|
pairs = self.dp.current_whitelist()
|
|
# Assign tf to each pair so they can be downloaded and cached for strategy.
|
|
informative_pairs = [(pair, '1d') for pair in pairs]
|
|
# Optionally Add additional "static" pairs
|
|
informative_pairs += [("ETH/USDT", "5m"),
|
|
("BTC/TUSD", "15m"),
|
|
]
|
|
return informative_pairs
|
|
|
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
if not self.dp:
|
|
# Don't do anything if DataProvider is not available.
|
|
return dataframe
|
|
|
|
inf_tf = '1d'
|
|
# Get the informative pair
|
|
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=inf_tf)
|
|
# Get the 14 day rsi
|
|
informative['rsi'] = ta.RSI(informative, timeperiod=14)
|
|
|
|
# Use the helper function merge_informative_pair to safely merge the pair
|
|
# Automatically renames the columns and merges a shorter timeframe dataframe and a longer timeframe informative pair
|
|
# use ffill to have the 1d value available in every row throughout the day.
|
|
# Without this, comparisons between columns of the original and the informative pair would only work once per day.
|
|
# Full documentation of this method, see below
|
|
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, inf_tf, ffill=True)
|
|
|
|
# Calculate rsi of the original dataframe (5m timeframe)
|
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
|
|
|
# Do other stuff
|
|
# ...
|
|
|
|
return dataframe
|
|
|
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
|
|
dataframe.loc[
|
|
(
|
|
(qtpylib.crossed_above(dataframe['rsi'], 30)) & # Signal: RSI crosses above 30
|
|
(dataframe['rsi_1d'] < 30) & # Ensure daily RSI is < 30
|
|
(dataframe['volume'] > 0) # Ensure this candle had volume (important for backtesting)
|
|
),
|
|
['enter_long', 'enter_tag']] = (1, 'rsi_cross')
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<hr />
|
|
<h2 id="additional-data-wallets">Additional data (Wallets)<a class="headerlink" href="#additional-data-wallets" title="Permanent link">¶</a></h2>
|
|
<p>The strategy provides access to the <code>wallets</code> object. This contains the current balances of your wallets/accounts on the exchange.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Backtesting / Hyperopt</p>
|
|
<p>Wallets behaves differently depending on the function from which it is 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>Always check if <code>wallets</code> is available to avoid failures during backtesting.</p>
|
|
<p><code>python
|
|
if self.wallets:
|
|
free_eth = self.wallets.get_free('ETH')
|
|
used_eth = self.wallets.get_used('ETH')
|
|
total_eth = self.wallets.get_total('ETH')</code></p>
|
|
<h3 id="possible-options-for-wallets">Possible options for Wallets<a class="headerlink" href="#possible-options-for-wallets" title="Permanent link">¶</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">¶</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 the required object:</p>
|
|
<p><code>python
|
|
from freqtrade.persistence import Trade</code></p>
|
|
<p>The following example queries trades from today for the current pair (<code>metadata['pair']</code>). Other filters can easily be added.</p>
|
|
<p>``` python
|
|
trades = Trade.get_trades_proxy(pair=metadata['pair'],
|
|
open_date=datetime.now(timezone.utc) - timedelta(days=1),
|
|
is_open=False,
|
|
]).order_by(Trade.close_date).all()</p>
|
|
<h1 id="summarize-profit-for-this-pair">Summarize profit for this pair.<a class="headerlink" href="#summarize-profit-for-this-pair" title="Permanent link">¶</a></h1>
|
|
<p>curdayprofit = sum(trade.close_profit for trade in trades)
|
|
```</p>
|
|
<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">¶</a></h2>
|
|
<p>Freqtrade locks pairs automatically for the current candle (until that candle is over) when a pair exits, preventing an immediate re-entry of that pair.</p>
|
|
<p>This is to prevent "waterfalls" of many and frequent trades within a single candle.</p>
|
|
<p>Locked pairs will show the message <code>Pair <pair> 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">¶</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(<reason>)</code>, providing the reason the pair was unlocked.
|
|
<code>self.unlock_reason(<reason>)</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">¶</a></h4>
|
|
<p>``` python
|
|
from freqtrade.persistence import Trade
|
|
from datetime import timedelta, datetime, timezone</p>
|
|
<h1 id="put-the-above-lines-at-the-top-of-the-strategy-file-next-to-all-the-other-imports">Put the above lines at the top of the strategy file, next to all the other imports<a class="headerlink" href="#put-the-above-lines-at-the-top-of-the-strategy-file-next-to-all-the-other-imports" title="Permanent link">¶</a></h1>
|
|
<h1 id="-_1">--------<a class="headerlink" href="#-_1" title="Permanent link">¶</a></h1>
|
|
<h1 id="within-populate-indicators-or-populate_entry_trend">Within populate indicators (or populate_entry_trend):<a class="headerlink" href="#within-populate-indicators-or-populate_entry_trend" title="Permanent link">¶</a></h1>
|
|
<p>if self.config['runmode'].value in ('live', 'dry_run'):
|
|
# fetch closed trades for the last 2 days
|
|
trades = Trade.get_trades_proxy(
|
|
pair=metadata['pair'], is_open=False,
|
|
open_date=datetime.now(timezone.utc) - timedelta(days=2))
|
|
# Analyze the conditions you'd like to lock the pair .... will probably be different for every strategy
|
|
sumprofit = sum(trade.close_profit for trade in trades)
|
|
if sumprofit < 0:
|
|
# Lock pair for 12 hours
|
|
self.lock_pair(metadata['pair'], until=datetime.now(timezone.utc) + timedelta(hours=12))
|
|
```</p>
|
|
<h2 id="print-the-main-dataframe">Print the main dataframe<a class="headerlink" href="#print-the-main-dataframe" title="Permanent link">¶</a></h2>
|
|
<p>To inspect the current main 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>
|
|
<p>``` python
|
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
dataframe.loc[
|
|
(
|
|
#>> whatever condition<<<
|
|
),
|
|
['enter_long', 'enter_tag']] = (1, 'somestring')</p>
|
|
<div class="codehilite"><pre><span></span><code># Print the Analyzed pair
|
|
print(f"result for {metadata['pair']}")
|
|
|
|
# Inspect the last 5 rows
|
|
print(dataframe.tail())
|
|
|
|
return dataframe
|
|
</code></pre></div>
|
|
|
|
<p>```</p>
|
|
<p>Printing more than a few rows is also possible by using <code>print(dataframe)</code> instead of <code>print(dataframe.tail())</code>. However this is not recommended, as can results in a lot of output (~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">¶</a></h2>
|
|
<h3 id="looking-into-the-future-while-backtesting">Looking into the future while backtesting<a class="headerlink" href="#looking-into-the-future-while-backtesting" title="Permanent link">¶</a></h3>
|
|
<p>Backtesting analyzes the whole dataframe timerange at once for performance reasons. Because of this, strategy authors need to make sure that strategies do not lookahead into the future, i.e. using data that would not be available in dry or live mode.</p>
|
|
<p>This is a common pain-point, which can cause huge differences between backtesting and dry/live run methods. Strategies that look into the future will perform well during backtesting, often with incredible profits or winrates, but will fail or perform badly in real conditions.</p>
|
|
<p>The following list contains 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 functions that use all dataframe or column values, e.g. <code>dataframe['mean_volume'] = dataframe['volume'].mean()</code>. As backtesting uses the full dataframe, at any point in the dataframe, the <code>'mean_volume'</code> series would include data from the future. Use rolling() calculations instead, e.g. <code>dataframe['volume'].rolling(<window>).mean()</code>.</li>
|
|
<li>don't use <code>.resample('1h')</code>. This uses the left border of the period interval, so moves data from an hour boundary to the start of the hour. Use <code>.resample('1h', label='right')</code> instead.</li>
|
|
<li>don't use <code>.merge()</code> to combine longer timeframes onto shorter ones. Instead, use the <a href="#informative-pairs">informative pair</a> helpers. (A plain merge can implicitly cause a lookahead bias as date refers to open date, not close date).</li>
|
|
</ul>
|
|
<div class="admonition tip">
|
|
<p class="admonition-title">Identifying problems</p>
|
|
<p>You should always use the two 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 are none of the above errors included.</p>
|
|
</div>
|
|
<h3 id="colliding-signals">Colliding signals<a class="headerlink" href="#colliding-signals" title="Permanent link">¶</a></h3>
|
|
<p>When conflicting signals collide (e.g. both <code>'enter_long'</code> and <code>'exit_long'</code> are set to <code>1</code>), 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> -> <code>exit_long</code>, <code>enter_short</code></li>
|
|
<li><code>enter_short</code> -> <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">¶</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 examples, but results will depend on the current market situation, pairs used, etc. Therefore, these strategies should be considered only for learning purposes, not real world trading. Please backtest the strategy for your exchange/desired pairs first, then dry run to evaluate carefully, and use at your own risk.</p>
|
|
<p>Feel free to use any of them as inspiration for your own strategies. We're happy to accept Pull Requests containing new strategies to the repository.</p>
|
|
<h2 id="next-steps">Next steps<a class="headerlink" href="#next-steps" title="Permanent link">¶</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 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="../strategy-101/" class="md-footer__link md-footer__link--prev" aria-label="Previous: Strategy Quickstart">
|
|
<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">
|
|
Strategy Quickstart
|
|
</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 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">{"annotate": null, "base": "..", "features": ["content.code.annotate", "search.share", "content.code.copy", "content.action.edit", "navigation.top", "navigation.footer"], "search": "../assets/javascripts/workers/search.2c215733.min.js", "tags": null, "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.79ae519e.min.js"></script>
|
|
|
|
<script src="../javascripts/config.js"></script>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
|
|
|
|
|
</body>
|
|
</html> |