Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
5
Indexable
Never
import pandas as pd
import talib

# Load historical data for the currency pair
data = pd.read_csv('currency_pair_data.csv')

# Filter the data to only include 15-minute time frame
data = data[data['timeframe'] == '15m']

# Calculate the 25-day and 50-day simple moving averages
data['sma25'] = data['close'].rolling(window=25).mean()
data['sma50'] = data['close'].rolling(window=50).mean()

# Calculate the 14-day RSI
data['rsi'] = talib.RSI(data['close'], timeperiod=14)

# Initialize a variable to keep track of the current position (long or short)
position = None

# Initialize stop loss and take profit levels
stop_loss_level = 0.01
take_profit_level = 0.02

# Initialize account balance
account_balance = 10000.0

# Initialize the trade size as 1% of the account balance
trade_size = account_balance * 0.01

# Iterate through the data and execute trades based on the moving average crossover
for index, row in data.iterrows():
    if position == None:
        # Check if the 25-day SMA has crossed above the 50-day SMA and RSI is below 30
        if row['sma25'] > row['sma50'] and row['rsi'] < 30:
            # Calculate the number of units to trade based on the trade size
            units = trade_size / row['close']
            # Execute a buy order
            print('