fix the gui below and conform to these requiremnts peorfectly to really backtest potenntially profitable strategies and fix the dorpdowna nd period boxes  2. Core Feature Development  2.1 Flexible Strategy Definition   Details: Build a user interface for defining trading strategies. Integrate core indicators like RSI, MACD, and others, along with data transformations such as scaling and demeaning. Enable users to input custom strategy rules.   2.2 Backtesting and Performance Analysis   Details: Develop the backtesting engine with support for processing complex strategies across historical data. Implement visualization for cumulative PnL and metrics like Sharpe ratio, maximum drawdown, and win rate.import tkinter as tk
from tkinter import ttk
import pandas as pd
import ccxt
from ta.momentum import RSIIndicator, StochasticOscillator
from ta.volatility import BollingerBands
from ta.trend import MACD
from backtesting import Backtest, Strategy
from backtesting.lib import crossover
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import pandas as pd
import ccxt
from ta.momentum import RSIIndicator, StochasticOscillator
from ta.volatility import BollingerBands
from ta.trend import MACD
from backtesting import Backtest, Strategy
from backtesting.lib import crossover
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

class TradingStrategy(Strategy):
    params = {
        'rsi_threshold': 30,
        'macd_fast': 12,
        'macd_slow': 26,
        'bollinger_bands_window': 20,
        'stochastic_oscillator_window': 14,
    }

    def init(self):
        # Convert data columns to pandas.Series
        close_series = pd.Series(self.data['Close'])
        high_series = pd.Series(self.data['High'])
        low_series = pd.Series(self.data['Low'])

        # RSI Indicator
        self.rsi = self.I(lambda x: RSIIndicator(x, window=self.params[0][1]).rsi(), close_series)
        
        # MACD
        self.macd = self.I(lambda x: MACD(x, window_slow=self.params[1][1], window_fast=self.params[2][1]).macd(), close_series)
        print(self.macd)
        # Bollinger Bands
        self.bollinger_bands = self.I(lambda x: BollingerBands(x, window=self.params[3][1]).bollinger_mavg(), close_series)
        
        
        # Stochastic Oscillator
        self.stochastic_oscillator = self.I(
            lambda h, l, c: StochasticOscillator(
                high=h, low=l, close=c, window=self.params[4][1]
            ).stoch(),
            high_series, low_series, close_series
        )

    def next(self):
        if self.rsi < self.params[0][1]:
            self.buy()
        elif self.rsi > self.params[0][1]+20:
            self.sell()

        if self.macd >  self.params[0][1]:
            self.buy()
        elif self.macd < self.params[0][1]+20:
            self.sell()

        if self.data['Close'] < self.bollinger_bands:
            self.buy()
        elif self.data['Close'] > self.bollinger_bands:
            self.sell()

        if self.stochastic_oscillator > self.stochastic_oscillator[-1]:
            self.buy()
        elif self.stochastic_oscillator < self.stochastic_oscillator[-1]:
            self.sell()

class GUI:
    def __init__(self, root):
        self.root = root
        self.root.title("Trading Strategy GUI")
        self.root.geometry("800x600")

        self.ticker_label = tk.Label(root, text="Ticker:")
        self.ticker_label.pack()
        self.ticker_entry = tk.Entry(root)
        self.ticker_entry.insert(0, 'PEPE/USDT')
        self.ticker_entry.pack()

        self.indicator_label = tk.Label(root, text="Indicator:")
        self.indicator_label.pack()
        self.indicator_var = tk.StringVar()
        self.indicator_var.set("RSI")
        self.indicator_option = tk.OptionMenu(root, self.indicator_var, "RSI", "MACD", "Bollinger Bands", "Stochastic Oscillator")
        self.indicator_option.pack()

        self.rsi_threshold_label = tk.Label(root, text="RSI Threshold:")
        self.rsi_threshold_label.pack()
        self.rsi_threshold_entry = tk.Entry(root)
        self.rsi_threshold_entry.insert(0, '30')
        self.rsi_threshold_entry.pack()

        self.macd_fast_label = tk.Label(root, text="MACD Fast:")
        self.macd_fast_label.pack()
        self.macd_fast_entry = tk.Entry(root)
        self.macd_fast_entry.insert(0, '12')
        self.macd_fast_entry.pack()

        self.macd_slow_label = tk.Label(root, text="MACD Slow:")
        self.macd_slow_label.pack()
        self.macd_slow_entry = tk.Entry(root)
        self.macd_slow_entry.insert(0, '26')
        self.macd_slow_entry.pack()

        self.bollinger_bands_window_label = tk.Label(root, text="Bollinger Bands Window:")
        self.bollinger_bands_window_label.pack()
        self.bollinger_bands_window_entry = tk.Entry(root)
        self.bollinger_bands_window_entry.insert(0, '20')
        self.bollinger_bands_window_entry.pack()

        self.stochastic_oscillator_window_label = tk.Label(root, text="Stochastic Oscillator Window:")
        self.stochastic_oscillator_window_label.pack()
        self.stochastic_oscillator_window_entry = tk.Entry(root)
        self.stochastic_oscillator_window_entry.insert(0, '14')
        self.stochastic_oscillator_window_entry.pack()

        self.backtest_button = tk.Button(root, text="Backtest", command=self.backtest)
        self.backtest_button.pack()

        self.plot_button = tk.Button(root, text="Plot", command=self.plot)
        self.plot_button.pack()

    def backtest(self):
        ticker = self.ticker_entry.get()
        exchange = ccxt.binance()
        data = exchange.fetch_ohlcv(ticker, timeframe='1m', since=1609459200000, limit=10000)
        df = pd.DataFrame(data, columns=['timestamp', 'Open', 'High', 'Low', 'Close', 'Volume'])
        #df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
        df.set_index('timestamp', inplace=True)
        strategy = TradingStrategy
        strategy.params = (
            ('rsi_threshold', int(self.rsi_threshold_entry.get())),
            ('macd_fast', int(self.macd_fast_entry.get())),
            ('macd_slow', int(self.macd_slow_entry.get())),
            ('bollinger_bands_window', int(self.bollinger_bands_window_entry.get())),
            ('stochastic_oscillator_window', int(self.stochastic_oscillator_window_entry.get())),
        )
        self.backtest = Backtest(df, strategy, cash=1000000, commission=.02)

        self.stats = self.backtest.run()
        fig, ax = plt.subplots(figsize=(16, 8))
        ax.plot(self.backtest._data.index, self.backtest._data['Close'], label='Close Price')
        ax.plot(self.backtest._results['_equity_curve']['Equity'])
        ax.set_ylabel('Price')
        ax.set_title('Backtest Results')
        ax.legend()
        plt.show()
        #ax.set_ylim(bottom=0, top=500000)  # Adjust the top limit as needed
        print( self.stats)

        #fig, ax = plt.subplots(figsize=(8, 6))
    def plot(self):
        fig, ax = plt.subplots(figsize=(8, 6))
        equity_curve = self.backtest._results['_equity_curve']
        equity_curve = equity_curve[equity_curve.notnull()] # remove NaT values
        ax.plot(equity_curve)
        ax.set_xlabel('Time')
        ax.set_ylabel('Equity')
        ax.set_title('Equity Curve')
        canvas = FigureCanvasTkAgg(fig, self.root)
        canvas.get_tk_widget().pack()
        canvas.draw()

        # Embed the plot into the Tkinter window
#        canvas = FigureCanvasTkAgg(fig, self.root)
 #       canvas.get_tk_widget().pack()
  #      canvas.draw()
   #     plt.show()

if __name__ == "__main__":
    root = tk.Tk()
    gui = GUI(root)
    root.mainloop()