feat: Add 7% stop loss and portfolio-based position sizing
This commit is contained in:
parent
bf71fa5fb2
commit
c1fbac6103
@ -299,7 +299,11 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
|
|||||||
sunny = SunnyBands()
|
sunny = SunnyBands()
|
||||||
calculator = None
|
calculator = None
|
||||||
if portfolio_size and portfolio_size > 0:
|
if portfolio_size and portfolio_size > 0:
|
||||||
calculator = PositionCalculator(account_size=portfolio_size)
|
calculator = PositionCalculator(
|
||||||
|
account_size=portfolio_size,
|
||||||
|
risk_percentage=1.0,
|
||||||
|
stop_loss_percentage=7.0 # Explicit 7% stop loss
|
||||||
|
)
|
||||||
|
|
||||||
bullish_signals = []
|
bullish_signals = []
|
||||||
bearish_signals = []
|
bearish_signals = []
|
||||||
@ -321,25 +325,36 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
|
|||||||
target_price = results['upper_band'].iloc[-1]
|
target_price = results['upper_band'].iloc[-1]
|
||||||
|
|
||||||
if calculator:
|
if calculator:
|
||||||
position = calculator.calculate_position_size(current_price, target_price)
|
try:
|
||||||
if position['shares'] > 0:
|
position = calculator.calculate_position_size(
|
||||||
signal_data = {
|
entry_price=current_price,
|
||||||
'ticker': ticker,
|
target_price=target_price
|
||||||
'entry': current_price,
|
)
|
||||||
'target': target_price,
|
if position['shares'] > 0:
|
||||||
'volume': current_volume,
|
# Update signal data with proper stop loss calculation
|
||||||
'last_update': datetime.fromtimestamp(last_update/1000000000),
|
signal_data = {
|
||||||
'shares': position['shares'],
|
'ticker': ticker,
|
||||||
'position_size': position['position_value'],
|
'entry': current_price,
|
||||||
'stop_loss': position['stop_loss'],
|
'target': target_price,
|
||||||
'risk': position['potential_loss'],
|
'volume': current_volume,
|
||||||
'reward': position['potential_profit'],
|
'last_update': datetime.fromtimestamp(last_update/1000000000),
|
||||||
'r_r': position['risk_reward_ratio']
|
'shares': position['shares'],
|
||||||
}
|
'position_size': position['position_value'],
|
||||||
bullish_signals.append(signal_data)
|
'stop_loss': current_price * 0.93, # 7% stop loss
|
||||||
# Print potential entry, target, and potential P/L
|
'risk': position['potential_loss'],
|
||||||
print(f"\n🟢 {ticker} Entry: ${current_price:.2f} Target: ${target_price:.2f}")
|
'reward': position['potential_profit'],
|
||||||
print(f" Potential Profit: ${signal_data['reward']:.2f} | Potential Loss: ${abs(signal_data['risk']):.2f}")
|
'r_r': position['risk_reward_ratio']
|
||||||
|
}
|
||||||
|
bullish_signals.append(signal_data)
|
||||||
|
# Update print output format
|
||||||
|
dollar_risk = position['potential_loss'] * -1
|
||||||
|
print(f"\n🟢 {ticker} @ ${current_price:.2f}")
|
||||||
|
print(f" Size: {position['shares']} shares (${position['position_value']:.2f})")
|
||||||
|
print(f" Stop: ${signal_data['stop_loss']:.2f} (-7%) | Target: ${target_price:.2f}")
|
||||||
|
print(f" Risk/Reward: 1:{position['risk_reward_ratio']:.1f} | Risk: ${dollar_risk:.2f}")
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"Skipping {ticker} position: {str(e)}")
|
||||||
|
continue
|
||||||
|
|
||||||
elif results['bearish_signal'].iloc[-1]:
|
elif results['bearish_signal'].iloc[-1]:
|
||||||
bearish_signals.append({
|
bearish_signals.append({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user