Untitled
import csv import os from datetime import datetime # Define the file name for the journal FILE_NAME = "forex_trade_journal.csv" # Check if the file exists, if not create it with headers if not os.path.exists(FILE_NAME): with open(FILE_NAME, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(["Date", "Currency Pair", "Trade Type", "Entry Price", "Exit Price", "Stop Loss", "Take Profit", "Lot Size", "Profit/Loss", "Notes"]) def log_trade(currency_pair, trade_type, entry_price, exit_price, stop_loss, take_profit, lot_size, profit_loss, notes=""): """Logs a forex trade to the CSV journal.""" with open(FILE_NAME, mode='a', newline='') as file: writer = csv.writer(file) writer.writerow([ datetime.now().strftime("%Y-%m-%d %H:%M:%S"), currency_pair, trade_type, entry_price, exit_price, stop_loss, take_profit, lot_size, profit_loss, notes ]) print("Trade logged successfully!") # Example usage if __name__ == "__main__": log_trade( currency_pair="EUR/USD", trade_type="Buy", entry_price=1.1200, exit_price=1.1250, stop_loss=1.1150, take_profit=1.1300, lot_size=1.0, profit_loss=50.0, notes="Test trade log." )
Leave a Comment