Skip to content

Commit

Permalink
Merge pull request #6104 from cardosofede/fix/cosmetic_issues_directi…
Browse files Browse the repository at this point in the history
…onal

Fix/cosmetic issues directional
  • Loading branch information
nikspz committed Feb 23, 2023
2 parents 680cf65 + 2558125 commit 9eddb8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Expand Up @@ -441,6 +441,7 @@ def to_format_status(self):
lines.extend([f"""
| Trading Pair: {self.trading_pair} | Exchange: {self.exchange} | Side: {self.side} | Amount: {self.amount:.4f}
| Entry price: {self.entry_price} | Close price: {self.close_price} --> PNL: {self.pnl * 100:.2f}%
| Status: {self.status}
"""])
else:
lines.extend([f"""
Expand All @@ -464,10 +465,10 @@ def to_format_status(self):
elif self.side == PositionSide.SHORT:
price_range = stop_loss_price - take_profit_price
progress = (stop_loss_price - current_price) / price_range
price_bar = [f'--{current_price:.2f}--' if i == int(price_scale * progress) else '-' for i in
price_bar = [f'--{current_price:.4f}--' if i == int(price_scale * progress) else '-' for i in
range(price_scale)]
price_bar.insert(0, f"SL:{stop_loss_price:.2f}")
price_bar.append(f"TP:{take_profit_price:.2f}")
price_bar.insert(0, f"SL:{stop_loss_price:.4f}")
price_bar.append(f"TP:{take_profit_price:.4f}")
lines.extend(["".join(price_bar), "\n"])
lines.extend(["-----------------------------------------------------------------------------------------------------------"])
return lines
1 change: 0 additions & 1 deletion scripts/advanced_directional_strategy_example.py
Expand Up @@ -178,7 +178,6 @@ def format_status(self) -> str:
if self.all_candles_ready:
lines.extend([
"\n############################################ Market Data ############################################\n"])
lines.extend([f"Value: {self.get_signal()}"])
values = {}
columns_to_show = ["timestamp", "open", "low", "high", "close", "volume", "BBP_21_2.0", "RSI_21_SMA_10"]
for candle_name, candles in self.candles.items():
Expand Down
16 changes: 8 additions & 8 deletions scripts/simple_directional_strategy_example.py
Expand Up @@ -36,7 +36,7 @@ class SimpleDirectionalStrategyExample(ScriptStrategyBase):
time_limit = 60 * 5

# Create the candles that we want to use and the thresholds for the indicators
eth_3m_candles = CandlesFactory.get_candle(connector=exchange,
eth_1m_candles = CandlesFactory.get_candle(connector=exchange,
trading_pair=trading_pair,
interval="1m", max_records=50)
rsi_lower_bound = 40
Expand All @@ -54,7 +54,7 @@ class SimpleDirectionalStrategyExample(ScriptStrategyBase):
def __init__(self, connectors: Dict[str, ConnectorBase]):
# Is necessary to start the Candles Feed.
super().__init__(connectors)
self.eth_3m_candles.start()
self.eth_1m_candles.start()

def get_active_executors(self):
return [signal_executor for signal_executor in self.active_executors
Expand All @@ -68,7 +68,7 @@ def on_tick(self):
if len(self.get_active_executors()) < self.max_executors:
signal_value = self.get_signal()
if signal_value > self.rsi_upper_bound or signal_value < self.rsi_lower_bound and self.is_margin_enough()\
and self.eth_3m_candles.is_ready:
and self.eth_1m_candles.is_ready:
# The rule that we are going to implement is:
# | RSI > 70 --> Short |
# | RSI < 30 --> Long |
Expand All @@ -89,7 +89,7 @@ def on_tick(self):
self.clean_and_store_executors()

def get_signal(self):
candle_df = self.eth_3m_candles.candles_df
candle_df = self.eth_1m_candles.candles_df
# Let's add some technical indicators
candle_df.ta.rsi(length=21, append=True)
rsi_value = candle_df.iat[-1, -1]
Expand All @@ -102,7 +102,7 @@ def on_stop(self):
"""
# we are going to close all the open positions when the bot stops
self.close_open_positions()
self.eth_3m_candles.stop()
self.eth_1m_candles.stop()

def format_status(self) -> str:
"""
Expand All @@ -129,16 +129,16 @@ def format_status(self) -> str:
for executor in self.active_executors:
lines.extend([f"|Signal id: {executor.timestamp}"])
lines.extend(executor.to_format_status())
if self.eth_3m_candles.is_ready:
if self.eth_1m_candles.is_ready:
lines.extend([
"\n############################################ Market Data ############################################\n"])
lines.extend([f"Value: {self.get_signal()}"])
columns_to_show = ["timestamp", "open", "low", "high", "close", "volume", "RSI_21"]
candles_df = self.eth_3m_candles.candles_df
candles_df = self.eth_1m_candles.candles_df
# Let's add some technical indicators
candles_df.ta.rsi(length=21, append=True)
candles_df["timestamp"] = pd.to_datetime(candles_df["timestamp"], unit="ms")
lines.extend([f"Candles: {self.eth_3m_candles.name} | Interval: {self.eth_3m_candles.interval}\n"])
lines.extend([f"Candles: {self.eth_1m_candles.name} | Interval: {self.eth_1m_candles.interval}\n"])
lines.extend([" " + line for line in candles_df[columns_to_show].tail().to_string(index=False).split("\n")])
lines.extend(["\n-----------------------------------------------------------------------------------------------------------\n"])
else:
Expand Down

0 comments on commit 9eddb8f

Please sign in to comment.