INNER CODE UNIT · Python
_is_it_time_to_open_short_position
Erfaniaa/crypto-trading-strategy-backtester · backtester.py:330
def _is_it_time_to_open_short_position(self):
main_condition = self.is_price_decreasing and not self.last_is_price_decreasing
is_too_early = self.candles_index < self.minimum_number_of_candles_to_start_trading
is_positions_list_empty = len(self.open_long_positions_list) == 0 and len(self.open_short_positions_list) == 0
is_ontime = False
if self.open_position_timeframe == "m15":
is_ontime = self.current_candle.open_time == utils.round_down_m1_to_m15_time(self.current_candle.open_time)
if self.open_position_timeframe == "h1":
is_ontime = self.current_candle.open_time == utils.round_down_m1_to_h1_time(self.current_candle.open_time)
if self.open_position_timeframe == "h2":
is_ontime = self.current_candle.open_time == utils.round_down_m1_to_h2_time(self.current_candle.open_time)
if self.open_position_timeframe == "h4":
is_ontime = self.current_candle.open_time == utils.round_down_m1_to_h4_time(self.current_candle.open_time)
if self.open_position_timeframe == "d1":
is_ontime = self.current_candle.open_time == utils.round_down_m1_to_d1_time(self.current_candle.open_time)
return is_positions_list_empty and is_ontime and not is_too_early and main_condition