INNER CODE UNIT · Python

_check_conditions_to_close_long_position

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

	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]
					recent_candles_high_list = [candle.high for candle in recent_candles_list]
					recent_candles_low_list = [candle.low for candle in recent_candles_list]
					position_result_and_candles = PositionResultAndCandles(open_prices_list=recent_candles_open_list,
																		   close_prices_list=recent_candles_close_list,
																		   high_prices_list=recent_candles_high_list,
																		   low_prices_list=recent_candles_low_list)
					self.open_long_positions_list[i].exit_time = self.current_candle.close_time

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…