Skip to content

Instantly share code, notes, and snippets.

@bmurtagh
Created April 3, 2026 12:46
Show Gist options
  • Select an option

  • Save bmurtagh/e880f362efeebe5bff36170d43dc36dc to your computer and use it in GitHub Desktop.

Select an option

Save bmurtagh/e880f362efeebe5bff36170d43dc36dc to your computer and use it in GitHub Desktop.
def calculate_fidelity_otoco_with_trailing():
print("--- Fidelity OTOCO Trailing Stop Calculator ---")
try:
price = float(input("Enter Purchase Price: "))
shares = int(input("Enter Number of Shares: "))
trail_pct = float(input("Enter Trailing Stop % (e.g., 10 for 10%): "))
# Base Calculations
risk_per_share = price * (trail_pct / 100)
stop_loss_initial = price - risk_per_share
ratios = [1, 2, 3, 4]
print(f"\n{'='*55}")
print(f" FIDELITY OTOCO ORDER DETAILS (Trailing Stop)")
print(f"{'='*55}")
print(f"PRIMARY ORDER: Buy {shares} shares @ ${price:.2f}")
print(f"TRAILING STOP LOSS: {trail_pct:.2f}% (Initial Stop: ${stop_loss_initial:.2f})")
print(f"{'-'*55}")
print(f"{'Ratio':<8} | {'Target Price':<12} | {'Total Profit':<12} | {'Risk/Share'}")
print(f"{'-'*55}")
for r in ratios:
reward_per_share = risk_per_share * r
target_price = price + reward_per_share
total_profit = reward_per_share * shares
print(f"{r}:1{' ':<5} | ${target_price:<11.2f} | ${total_profit:<11.2f} | ${risk_per_share:.2f}")
print(f"{'='*55}")
print("Fidelity Tip: Select 'Trailing Stop Loss %' in the secondary order.")
except ValueError:
print("Invalid input. Please enter numerical values.")
if __name__ == "__main__":
calculate_fidelity_otoco_with_trailing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment