Untitled
unknown
plain_text
3 years ago
1.4 kB
7
Indexable
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
# Load historical market data for GBPUSD into a pandas DataFrame
data = pd.read_csv('GBPUSD_data.csv')
# Clean and preprocess the data
...
# Calculate the BOS indicator
data['BOS'] = np.where((data['High'] > data['High'].shift(1)) & (data['Low'] > data['Low'].shift(1)), 1, 0)
# Calculate the risk-to-reward ratio for each trade
data['RiskReward'] = np.where(data['BOS'] == 1, (data['EntryPrice'] - data['StopLoss']) / (data['TakeProfit'] - data['EntryPrice']), np.nan)
# Filter for trades with a minimum risk-to-reward ratio of 1:5
data = data[data['RiskReward'] >= 5]
# Split the data into training and testing sets
X = data[['BOS', 'RSI', 'MACD', 'Stochastic']]
y = data['Signal']
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)
# Train a logistic regression model on the training data
model = LogisticRegression()
model.fit(X_train, y_train)
# Use the trained model to make predictions on the testing data
y_pred = model.predict(X_test)
# Determine whether to buy or sell based on the predictions
if y_pred[-1] == 1:
# Buy
...
else:
# Sell
...
Editor is loading...