INNER CODE UNIT · Python

_update_open_short_positions_statistics

Erfaniaa/crypto-trading-strategy-backtester · backtester.py:422

	def _update_open_short_positions_statistics(self):
		open_short_positions_count = len(self.open_short_positions_list)
		for i in range(open_short_positions_count):
			self.open_short_positions_list[i].max_profit_percent = max(self.open_short_positions_list[i].max_profit_percent, -100 * (self.current_candle.close - self.open_short_positions_list[i].entry_price) / self.open_short_positions_list[i].entry_price)
			self.open_short_positions_list[i].min_profit_percent = min(self.open_short_positions_list[i].min_profit_percent, -100 * (self.current_candle.close - self.open_short_positions_list[i].entry_price) / self.open_short_positions_list[i].entry_price)


	def _check_conditions_to_close_long_position(self):
		main_condition = self.is_price_decreasing and not self.last_is_price_decreasing
		open_long_positions_count = len(self.open_long_positions_list)
		for i in reversed(range(open_long_positions_count)):
			if self.current_candle.high > self.open_long_positions_list[i].take_profit_price or \
				self.current_candle.low < self.open_long_positions_list[i].stop_loss_price or \
				main_condition:
					self.last_position_status += self.CLOSE_LONG_POSITION
					recent_candles_list = self.open_long_positions_list[i].recent_candles_list
					recent_candles_close_list = [candle.close for candle in recent_candles_list]
					recent_candles_open_list = [candle.open for candle in recent_candles_list]

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…