Timeframe
N/A
Direction
Long Only
Stoploss
N/A
Trailing Stop
No
ROI
N/A
Interface Version
N/A
Startup Candles
1000
Indicators
1
freqtrade/freqtrade-strategies
Sample strategy implementing Informative Pairs - compares stake_currency with USDT. Not performing very well - but should serve as an example how to use a referential pair against USDT. author@: xmatthias github@: https://github.com/freqtrade/freqtrade-strategies
freqtrade/freqtrade-strategies
Strategy 003 author@: Gerald Lonlas github@: https://github.com/freqtrade/freqtrade-strategies
freqtrade/freqtrade-strategies
from kektrade.exchange import *
from kektrade.database.types import *
from kektrade.strategy import *
from kektrade.misc import *
from pandas import DataFrame
import logging
import talib
import tqdm
from typing import Dict, Any
logger = logging.getLogger(__name__)
# This class is a sample. Feel free to customize it.
class Sma(IStrategy):
startup_candle_count = 1000
def populate_variables(self, variables: Dict[str, Any]) -> None:
variables["contracts"] = 0
def populate_indicators(self, dataframe: DataFrame, metadata: Dict[str, Any], parameters: Dict[str, Any]) -> DataFrame:
dataframe["sma_big"] = talib.SMA(dataframe.close, timeperiod=100)
dataframe["sma_small"] = talib.SMA(dataframe.close, timeperiod=50)
return dataframe
def tick(self, dataframe: DataFrame, index: int, metadata: Dict[str, Any], parameter: Dict[str, Any], variables: Dict[str, Any], exchange: IExchange) -> None:
df = dataframe
i = index
if variables["contracts"] == 0:
variables["contracts"] = exchange.get_contracts_percentage(1)
m = variables["contracts"]
if i > 10:
if (parameter["side"] == "long"):
if df.at[i, "sma_small"] > df.at[i, "sma_big"] and df.at[i - 1, "sma_small"] < df.at[i - 1, "sma_big"]:
c = m
exchange.open_order("", OrderType.MARKET, contracts=c)
elif df.at[i, "sma_small"] < df.at[i, "sma_big"]:
c = -exchange.get_position().contracts
if c != 0:
exchange.open_order("", OrderType.MARKET, contracts=c)
elif (parameter["side"] == "short"):
if df.at[i, "sma_small"] > df.at[i, "sma_big"]:
c = -exchange.get_position().contracts
if c != 0:
exchange.open_order("", OrderType.MARKET, contracts=c)
elif df.at[i, "sma_small"] < df.at[i, "sma_big"] and df.at[i - 1, "sma_small"] > df.at[i - 1, "sma_big"]:
c = -m
exchange.open_order("", OrderType.MARKET, contracts=c)
def get_indicators(self):
return [
{
"plot": True,
"name": "sma_big",
"overlay": True,
"scatter": False,
"color": "red"
},
{
"plot": True,
"name": "sma_small",
"overlay": True,
"scatter": False,
"color": "blue"
}
]